Test case to ensure dashboard.parse.com won't break (#1636)
* Test case to ensure dashboard.parse.com won't break * Adds volatile classes concept for _PushStatus * Fixes test
This commit is contained in:
@@ -9,6 +9,7 @@ var facebook = require('../src/authDataManager/facebook');
|
||||
var ParseServer = require('../src/index').ParseServer;
|
||||
var path = require('path');
|
||||
var TestUtils = require('../src/index').TestUtils;
|
||||
var MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
|
||||
|
||||
var databaseURI = process.env.DATABASE_URI;
|
||||
var cloudMain = process.env.CLOUD_CODE_MAIN || './spec/cloud/main.js';
|
||||
@@ -87,8 +88,29 @@ beforeEach(function(done) {
|
||||
return TestUtils.destroyAllDataPermanently().then(done, fail);
|
||||
});
|
||||
|
||||
var mongoAdapter = new MongoStorageAdapter({
|
||||
collectionPrefix: defaultConfiguration.collectionPrefix,
|
||||
uri: databaseURI,
|
||||
})
|
||||
|
||||
afterEach(function(done) {
|
||||
Parse.User.logOut().then(() => {
|
||||
mongoAdapter.getAllSchemas()
|
||||
.then(allSchemas => {
|
||||
allSchemas.forEach((schema) => {
|
||||
var className = schema.className;
|
||||
expect(className).toEqual({ asymmetricMatch: className => {
|
||||
if (!className.startsWith('_')) {
|
||||
return true;
|
||||
} else {
|
||||
// Other system classes will break Parse.com, so make sure that we don't save anything to _SCHEMA that will
|
||||
// break it.
|
||||
return ['_User', '_Installation', '_Role', '_Session', '_Product'].includes(className);
|
||||
}
|
||||
}});
|
||||
});
|
||||
})
|
||||
.then(() => Parse.User.logOut())
|
||||
.then(() => {
|
||||
return TestUtils.destroyAllDataPermanently();
|
||||
}).then(() => {
|
||||
done();
|
||||
|
||||
@@ -345,7 +345,7 @@ DatabaseController.prototype.create = function(className, object, { acl } = {})
|
||||
return (isMaster ? Promise.resolve() : schemaController.validatePermission(className, aclGroup, 'create'))
|
||||
.then(() => this.handleRelationUpdates(className, null, object))
|
||||
.then(() => schemaController.enforceClassExists(className))
|
||||
.then(() => schemaController.getOneSchema(className))
|
||||
.then(() => schemaController.getOneSchema(className, true))
|
||||
.then(schema => this.adapter.createObject(className, object, schemaController, schema))
|
||||
.then(result => sanitizeDatabaseResult(originalObject, result.ops[0]));
|
||||
})
|
||||
|
||||
@@ -93,6 +93,8 @@ const requiredColumns = Object.freeze({
|
||||
|
||||
const systemClasses = Object.freeze(['_User', '_Installation', '_Role', '_Session', '_Product', '_PushStatus']);
|
||||
|
||||
const volatileClasses = Object.freeze(['_PushStatus']);
|
||||
|
||||
// 10 alpha numberic chars + uppercase
|
||||
const userIdRegex = /^[a-zA-Z0-9]{10}$/;
|
||||
// Anything that start with role
|
||||
@@ -251,6 +253,15 @@ class SchemaController {
|
||||
this.data[schema.className] = schema.fields;
|
||||
this.perms[schema.className] = schema.classLevelPermissions;
|
||||
});
|
||||
|
||||
// Inject the in-memory classes
|
||||
volatileClasses.forEach(className => {
|
||||
this.data[className] = injectDefaultSchema({
|
||||
className,
|
||||
fields: {},
|
||||
classLevelPermissions: {}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -259,7 +270,10 @@ class SchemaController {
|
||||
.then(allSchemas => allSchemas.map(injectDefaultSchema));
|
||||
}
|
||||
|
||||
getOneSchema(className) {
|
||||
getOneSchema(className, allowVolatileClasses = false) {
|
||||
if (allowVolatileClasses && volatileClasses.indexOf(className) > -1) {
|
||||
return Promise.resolve(this.data[className]);
|
||||
}
|
||||
return this._dbAdapter.getOneSchema(className)
|
||||
.then(injectDefaultSchema);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user