From 0e189bae0867d488c4bb51b83b69bd1a683ab036 Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Thu, 16 Jun 2016 08:52:13 -0700 Subject: [PATCH 1/9] Debug flaky test --- package.json | 2 +- spec/schemas.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2f5e403823..11d3f395be 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "dev": "npm run build && node bin/dev", "build": "./node_modules/.bin/babel src/ -d lib/", "pretest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.2.6} MONGODB_STORAGE_ENGINE=mmapv1 ./node_modules/.bin/mongodb-runner start", - "test": "cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js", + "test": "cross-env NODE_ENV=test VERBOSE=1 TESTING=1 ./node_modules/.bin/babel-node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js", "test:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node ./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/** ./node_modules/jasmine/bin/jasmine.js && npm run posttest", "posttest": "./node_modules/.bin/mongodb-runner stop", "coverage": "cross-env COVERAGE_OPTION='./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/**' npm test", diff --git a/spec/schemas.spec.js b/spec/schemas.spec.js index ffecf3c265..75682d1d29 100644 --- a/spec/schemas.spec.js +++ b/spec/schemas.spec.js @@ -677,7 +677,7 @@ describe('schemas', () => { }) }); - it('lets you delete multiple fields and add fields', done => { + fit('lets you delete multiple fields and add fields', done => { var obj1 = hasAllPODobject(); obj1.save() .then(() => { From 22d2c1d957ecf678d7ec90a9d560647756f153fd Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Thu, 16 Jun 2016 09:17:05 -0700 Subject: [PATCH 2/9] create new object instead of modifying and assigning existing object --- src/Controllers/SchemaController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controllers/SchemaController.js b/src/Controllers/SchemaController.js index 0c5502157a..aa7ac701b7 100644 --- a/src/Controllers/SchemaController.js +++ b/src/Controllers/SchemaController.js @@ -309,7 +309,7 @@ class SchemaController { if (!hasClass) { throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} does not exist.`); } - let existingFields = Object.assign(this.data[className], {_id: className}); + let existingFields = { ...this.data[className], _id: className }; Object.keys(submittedFields).forEach(name => { let field = submittedFields[name]; if (existingFields[name] && field.__op !== 'Delete') { From fb1f276df3104cbb64d68c56490599c42325dbbc Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Thu, 16 Jun 2016 10:07:21 -0700 Subject: [PATCH 3/9] use getOneSchema instead of this.data when updating fields --- src/Controllers/SchemaController.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Controllers/SchemaController.js b/src/Controllers/SchemaController.js index aa7ac701b7..3850ac9965 100644 --- a/src/Controllers/SchemaController.js +++ b/src/Controllers/SchemaController.js @@ -304,12 +304,9 @@ class SchemaController { } updateClass(className, submittedFields, classLevelPermissions, database) { - return this.hasClass(className) - .then(hasClass => { - if (!hasClass) { - throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} does not exist.`); - } - let existingFields = { ...this.data[className], _id: className }; + return this.getOneSchema(className) + .then(schema => { + let existingFields = schema.fields; Object.keys(submittedFields).forEach(name => { let field = submittedFields[name]; if (existingFields[name] && field.__op !== 'Delete') { @@ -356,6 +353,13 @@ class SchemaController { 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 From 2a46345aab60ee4c6f9504c4139cb7dfb4cd9e80 Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Thu, 16 Jun 2016 10:42:47 -0700 Subject: [PATCH 4/9] Remove debug stuff --- package.json | 2 +- spec/schemas.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 11d3f395be..2f5e403823 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "dev": "npm run build && node bin/dev", "build": "./node_modules/.bin/babel src/ -d lib/", "pretest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.2.6} MONGODB_STORAGE_ENGINE=mmapv1 ./node_modules/.bin/mongodb-runner start", - "test": "cross-env NODE_ENV=test VERBOSE=1 TESTING=1 ./node_modules/.bin/babel-node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js", + "test": "cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js", "test:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node ./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/** ./node_modules/jasmine/bin/jasmine.js && npm run posttest", "posttest": "./node_modules/.bin/mongodb-runner stop", "coverage": "cross-env COVERAGE_OPTION='./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/**' npm test", diff --git a/spec/schemas.spec.js b/spec/schemas.spec.js index 75682d1d29..ffecf3c265 100644 --- a/spec/schemas.spec.js +++ b/spec/schemas.spec.js @@ -677,7 +677,7 @@ describe('schemas', () => { }) }); - fit('lets you delete multiple fields and add fields', done => { + it('lets you delete multiple fields and add fields', done => { var obj1 = hasAllPODobject(); obj1.save() .then(() => { From bdf1363c500d128c76e7871f417c815f8218de6b Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Thu, 16 Jun 2016 13:16:31 -0700 Subject: [PATCH 5/9] Don't try to validate existing fields --- src/Controllers/SchemaController.js | 34 +++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Controllers/SchemaController.js b/src/Controllers/SchemaController.js index 3850ac9965..1144dcea4a 100644 --- a/src/Controllers/SchemaController.js +++ b/src/Controllers/SchemaController.js @@ -318,7 +318,7 @@ class SchemaController { }); let newSchema = buildMergedSchemaObject(existingFields, submittedFields); - let validationError = this.validateSchemaData(className, newSchema, classLevelPermissions); + let validationError = this.validateSchemaData(className, newSchema, classLevelPermissions, Object.keys(existingFields)); if (validationError) { throw new Parse.Error(validationError.code, validationError.error); } @@ -402,25 +402,27 @@ class SchemaController { 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) { - if (!fieldNameIsValid(fieldName)) { - return { - code: Parse.Error.INVALID_KEY_NAME, - error: 'invalid field name: ' + fieldName, - }; - } - if (!fieldNameIsValidForClass(fieldName, className)) { - return { - code: 136, - error: 'field ' + fieldName + ' cannot be added', - }; + if (!existingFieldNames.includes(fieldName)) { + if (!fieldNameIsValid(fieldName)) { + return { + code: Parse.Error.INVALID_KEY_NAME, + error: 'invalid field name: ' + fieldName, + }; + } + if (!fieldNameIsValidForClass(fieldName, className)) { + return { + code: 136, + error: 'field ' + fieldName + ' cannot be added', + }; + } + const error = fieldTypeIsInvalid(fields[fieldName]); + if (error) return { code: error.code, error: error.message }; } - const error = fieldTypeIsInvalid(fields[fieldName]); - if (error) return { code: error.code, error: error.message }; } for (let fieldName in defaultColumns[className]) { From 34480c2e9e98b13a1970960a48e9d9fad7b2c046 Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Thu, 16 Jun 2016 13:34:10 -0700 Subject: [PATCH 6/9] run just one test --- package.json | 2 +- spec/schemas.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2f5e403823..1697b8de49 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "build": "./node_modules/.bin/babel src/ -d lib/", "pretest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.2.6} MONGODB_STORAGE_ENGINE=mmapv1 ./node_modules/.bin/mongodb-runner start", "test": "cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js", - "test:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node ./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/** ./node_modules/jasmine/bin/jasmine.js && npm run posttest", + "test:win": "npm run pretest && cross-env NODE_ENV=test VERBOSE=1 TESTING=1 ./node_modules/.bin/babel-node ./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/** ./node_modules/jasmine/bin/jasmine.js && npm run posttest", "posttest": "./node_modules/.bin/mongodb-runner stop", "coverage": "cross-env COVERAGE_OPTION='./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/**' npm test", "start": "node ./bin/parse-server", diff --git a/spec/schemas.spec.js b/spec/schemas.spec.js index ffecf3c265..75682d1d29 100644 --- a/spec/schemas.spec.js +++ b/spec/schemas.spec.js @@ -677,7 +677,7 @@ describe('schemas', () => { }) }); - it('lets you delete multiple fields and add fields', done => { + fit('lets you delete multiple fields and add fields', done => { var obj1 = hasAllPODobject(); obj1.save() .then(() => { From 70b42e4c5c22790cb204b8d7f838c15759c06ba4 Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Thu, 16 Jun 2016 13:51:53 -0700 Subject: [PATCH 7/9] Verbose test all --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1697b8de49..11d3f395be 100644 --- a/package.json +++ b/package.json @@ -68,8 +68,8 @@ "dev": "npm run build && node bin/dev", "build": "./node_modules/.bin/babel src/ -d lib/", "pretest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.2.6} MONGODB_STORAGE_ENGINE=mmapv1 ./node_modules/.bin/mongodb-runner start", - "test": "cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js", - "test:win": "npm run pretest && cross-env NODE_ENV=test VERBOSE=1 TESTING=1 ./node_modules/.bin/babel-node ./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/** ./node_modules/jasmine/bin/jasmine.js && npm run posttest", + "test": "cross-env NODE_ENV=test VERBOSE=1 TESTING=1 ./node_modules/.bin/babel-node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js", + "test:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node ./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/** ./node_modules/jasmine/bin/jasmine.js && npm run posttest", "posttest": "./node_modules/.bin/mongodb-runner stop", "coverage": "cross-env COVERAGE_OPTION='./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/**' npm test", "start": "node ./bin/parse-server", From 436b120491871e854f82cd613dba058c6d7ef615 Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Thu, 16 Jun 2016 14:03:24 -0700 Subject: [PATCH 8/9] Use schema instead of this.data --- src/Controllers/SchemaController.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Controllers/SchemaController.js b/src/Controllers/SchemaController.js index 1144dcea4a..f8d9ae56fb 100644 --- a/src/Controllers/SchemaController.js +++ b/src/Controllers/SchemaController.js @@ -534,19 +534,19 @@ class SchemaController { throw new Parse.Error(136, `field ${fieldName} cannot be changed`); } - return this.reloadData() - .then(() => this.hasClass(className)) - .then(hasClass => { - if (!hasClass) { + return this.getOneSchema(className) + .catch(error => { + if (error === undefined) { throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${className} does not exist.`); - } - if (!this.data[className][fieldName]) { - throw new Parse.Error(255, `Field ${fieldName} does not exist, cannot delete.`); + } else { + throw error; } }) - .then(() => this.getOneSchema(className)) .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 return database.adapter.deleteFields(className, schema, [fieldName]) .then(() => database.adapter.deleteClass(`_Join:${fieldName}:${className}`)); From cb6407d56b13c307dee1c8ed49135a630bdbeabd Mon Sep 17 00:00:00 2001 From: Drew Gross Date: Thu, 16 Jun 2016 14:20:02 -0700 Subject: [PATCH 9/9] Switch to all tests --- package.json | 2 +- spec/schemas.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 11d3f395be..2f5e403823 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "dev": "npm run build && node bin/dev", "build": "./node_modules/.bin/babel src/ -d lib/", "pretest": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.2.6} MONGODB_STORAGE_ENGINE=mmapv1 ./node_modules/.bin/mongodb-runner start", - "test": "cross-env NODE_ENV=test VERBOSE=1 TESTING=1 ./node_modules/.bin/babel-node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js", + "test": "cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node $COVERAGE_OPTION ./node_modules/jasmine/bin/jasmine.js", "test:win": "npm run pretest && cross-env NODE_ENV=test TESTING=1 ./node_modules/.bin/babel-node ./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/** ./node_modules/jasmine/bin/jasmine.js && npm run posttest", "posttest": "./node_modules/.bin/mongodb-runner stop", "coverage": "cross-env COVERAGE_OPTION='./node_modules/babel-istanbul/lib/cli.js cover -x **/spec/**' npm test", diff --git a/spec/schemas.spec.js b/spec/schemas.spec.js index 75682d1d29..ffecf3c265 100644 --- a/spec/schemas.spec.js +++ b/spec/schemas.spec.js @@ -677,7 +677,7 @@ describe('schemas', () => { }) }); - fit('lets you delete multiple fields and add fields', done => { + it('lets you delete multiple fields and add fields', done => { var obj1 = hasAllPODobject(); obj1.save() .then(() => {