Files
kami-parse-server/spec/support/dev.js
Diamond Lewis a02014f557 Improve single schema cache (#7214)
* Initial Commit

* fix flaky test

* temporary set ci timeout

* turn off ci check

* fix postgres tests

* fix tests

* node flaky test

* remove improvements

* Update SchemaPerformance.spec.js

* fix tests

* revert ci

* Create Singleton Object

* properly clear cache testing

* Cleanup

* remove fit

* try PushController.spec

* try push test rewrite

* try push enqueue time

* Increase test timeout

* remove pg server creation test

* xit push tests

* more xit

* remove skipped tests

* Fix conflicts

* reduce ci timeout

* fix push tests

* Revert "fix push tests"

This reverts commit 05aba62f1cbbca7d5d3e80b9444529f59407cb56.

* improve initialization

* fix flaky tests

* xit flaky test

* Update CHANGELOG.md

* enable debug logs

* Update LogsRouter.spec.js

* create initial indexes in series

* lint

* horizontal scaling documentation

* Update Changelog

* change horizontalScaling db option

* Add enableSchemaHooks option

* move enableSchemaHooks to databaseOptions
2021-03-16 16:05:36 -05:00

93 lines
2.9 KiB
JavaScript

const Config = require('../../lib/Config');
const Parse = require('parse/node');
const className = 'AnObject';
const defaultRoleName = 'tester';
module.exports = {
/* AnObject */
className,
/**
* Creates and returns new user.
*
* This method helps to avoid 'User already exists' when re-running/debugging a single test.
* @param {string} username - username base, will be postfixed with current time in millis;
* @param {string} [password='password'] - optional, defaults to "password" if not set;
*/
createUser: async (username, password = 'password') => {
const user = new Parse.User({
username: username + Date.now(),
password,
});
await user.save();
return user;
},
/**
* Logs the user in.
*
* If password not provided, default 'password' is used.
* @param {string} username - username base, will be postfixed with current time in millis;
* @param {string} [password='password'] - optional, defaults to "password" if not set;
*/
logIn: async (userObject, password) => {
return await Parse.User.logIn(userObject.getUsername(), password || 'password');
},
/**
* Sets up Class-Level Permissions for 'AnObject' class.
* @param clp {ClassLevelPermissions}
*/
updateCLP: async (clp, targetClass = className) => {
const config = Config.get(Parse.applicationId);
const schemaController = await config.database.loadSchema();
await schemaController.updateClass(targetClass, {}, clp);
},
/**
* Creates and returns role. Adds user(s) if provided.
*
* This method helps to avoid errors when re-running/debugging a single test.
*
* @param {Parse.User|Parse.User[]} [users] - user or array of users to be related with this role;
* @param {string?} [roleName] - uses this name for role if provided. Generates from datetime if not set;
* @param {string?} [exactName] - sets exact name (no generated part added);
* @param {Parse.Role[]} [roles] - uses this name for role if provided. Generates from datetime if not set;
* @param {boolean} [read] - value for role's acl public read. Defaults to true;
* @param {boolean} [write] - value for role's acl public write. Defaults to true;
*/
createRole: async ({
users = null,
exactName = defaultRoleName + Date.now(),
roleName = null,
roles = null,
read = true,
write = true,
}) => {
const acl = new Parse.ACL();
acl.setPublicReadAccess(read);
acl.setPublicWriteAccess(write);
const role = new Parse.Object('_Role');
role.setACL(acl);
// generate name based on roleName or use exactName (if botth not provided name is generated)
const name = roleName ? roleName + Date.now() : exactName;
role.set('name', name);
if (roles) {
role.relation('roles').add(roles);
}
if (users) {
role.relation('users').add(users);
}
await role.save({ useMasterKey: true });
return role;
},
};