Fix flaky test (#2078)

* Debug flaky test

* create new object instead of modifying and assigning existing object

* use getOneSchema instead of this.data when updating fields

* Remove debug stuff

* Don't try to validate existing fields

* run just one test

* Verbose test all

* Use schema instead of this.data

* Switch to all tests
This commit is contained in:
Drew
2016-06-16 15:34:33 -07:00
committed by Peter J. Shin
parent 627b4164bb
commit 1a75101146

View File

@@ -341,12 +341,9 @@ class SchemaController {
} }
updateClass(className, submittedFields, classLevelPermissions, database) { updateClass(className, submittedFields, classLevelPermissions, database) {
return this.hasClass(className) return this.getOneSchema(className)
.then(hasClass => { .then(schema => {
if (!hasClass) { let existingFields = schema.fields;
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} does not exist.`);
}
let existingFields = Object.assign(this.data[className], {_id: className});
Object.keys(submittedFields).forEach(name => { Object.keys(submittedFields).forEach(name => {
let field = submittedFields[name]; let field = submittedFields[name];
if (existingFields[name] && field.__op !== 'Delete') { if (existingFields[name] && field.__op !== 'Delete') {
@@ -360,7 +357,7 @@ class SchemaController {
delete existingFields._rperm; delete existingFields._rperm;
delete existingFields._wperm; delete existingFields._wperm;
let newSchema = buildMergedSchemaObject(existingFields, submittedFields); let newSchema = buildMergedSchemaObject(existingFields, submittedFields);
let validationError = this.validateSchemaData(className, newSchema, classLevelPermissions); let validationError = this.validateSchemaData(className, newSchema, classLevelPermissions, Object.keys(existingFields));
if (validationError) { if (validationError) {
throw new Parse.Error(validationError.code, validationError.error); throw new Parse.Error(validationError.code, validationError.error);
} }
@@ -395,6 +392,13 @@ class SchemaController {
classLevelPermissions: this.perms[className] classLevelPermissions: this.perms[className]
})); }));
}) })
.catch(error => {
if (error === undefined) {
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} does not exist.`);
} else {
throw error;
}
})
} }
// Returns a promise that resolves successfully to the new schema // Returns a promise that resolves successfully to the new schema
@@ -436,11 +440,12 @@ class SchemaController {
error: invalidClassNameMessage(className), error: invalidClassNameMessage(className),
}; };
} }
return this.validateSchemaData(className, fields, classLevelPermissions); return this.validateSchemaData(className, fields, classLevelPermissions, []);
} }
validateSchemaData(className, fields, classLevelPermissions) { validateSchemaData(className, fields, classLevelPermissions, existingFieldNames) {
for (let fieldName in fields) { for (let fieldName in fields) {
if (!existingFieldNames.includes(fieldName)) {
if (!fieldNameIsValid(fieldName)) { if (!fieldNameIsValid(fieldName)) {
return { return {
code: Parse.Error.INVALID_KEY_NAME, code: Parse.Error.INVALID_KEY_NAME,
@@ -456,6 +461,7 @@ class SchemaController {
const error = fieldTypeIsInvalid(fields[fieldName]); const error = fieldTypeIsInvalid(fields[fieldName]);
if (error) return { code: error.code, error: error.message }; if (error) return { code: error.code, error: error.message };
} }
}
for (let fieldName in defaultColumns[className]) { for (let fieldName in defaultColumns[className]) {
fields[fieldName] = defaultColumns[className][fieldName]; fields[fieldName] = defaultColumns[className][fieldName];
@@ -552,19 +558,19 @@ class SchemaController {
throw new Parse.Error(136, `field ${fieldName} cannot be changed`); throw new Parse.Error(136, `field ${fieldName} cannot be changed`);
} }
return this.reloadData() return this.getOneSchema(className)
.then(() => this.hasClass(className)) .catch(error => {
.then(hasClass => { if (error === undefined) {
if (!hasClass) {
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} does not exist.`); throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} does not exist.`);
} } else {
if (!this.data[className][fieldName]) { throw error;
throw new Parse.Error(255, `Field ${fieldName} does not exist, cannot delete.`);
} }
}) })
.then(() => this.getOneSchema(className))
.then(schema => { .then(schema => {
if (this.data[className][fieldName].type == 'Relation') { if (!schema.fields[fieldName]) {
throw new Parse.Error(255, `Field ${fieldName} does not exist, cannot delete.`);
}
if (schema.fields[fieldName].type == 'Relation') {
//For relations, drop the _Join table //For relations, drop the _Join table
return database.adapter.deleteFields(className, schema, [fieldName]) return database.adapter.deleteFields(className, schema, [fieldName])
.then(() => database.adapter.deleteClass(`_Join:${fieldName}:${className}`)); .then(() => database.adapter.deleteClass(`_Join:${fieldName}:${className}`));