From 8814e1f3b59e0b5bca41b0b014b47838860d6bba Mon Sep 17 00:00:00 2001 From: Marco129 Date: Fri, 4 Mar 2016 20:44:21 +0800 Subject: [PATCH] Fix add field to system schema --- spec/schemas.spec.js | 57 ++++++++++++++++++++++++++++++++++++ src/Routers/SchemasRouter.js | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/spec/schemas.spec.js b/spec/schemas.spec.js index 63843e57df..9a410eed4b 100644 --- a/spec/schemas.spec.js +++ b/spec/schemas.spec.js @@ -561,6 +561,63 @@ describe('schemas', () => { }) }); + it('lets you add fields to system schema', done => { + request.post({ + url: 'http://localhost:8378/1/schemas/_User', + headers: masterKeyHeaders, + json: true + }, (error, response, body) => { + request.put({ + url: 'http://localhost:8378/1/schemas/_User', + headers: masterKeyHeaders, + json: true, + body: { + fields: { + newField: {type: 'String'} + } + } + }, (error, response, body) => { + expect(body).toEqual({ + className: '_User', + fields: { + objectId: {type: 'String'}, + updatedAt: {type: 'Date'}, + createdAt: {type: 'Date'}, + username: {type: 'String'}, + password: {type: 'String'}, + authData: {type: 'Object'}, + email: {type: 'String'}, + emailVerified: {type: 'Boolean'}, + newField: {type: 'String'}, + ACL: {type: 'ACL'} + } + }); + request.get({ + url: 'http://localhost:8378/1/schemas/_User', + headers: masterKeyHeaders, + json: true + }, (error, response, body) => { + expect(body).toEqual({ + className: '_User', + fields: { + objectId: {type: 'String'}, + updatedAt: {type: 'Date'}, + createdAt: {type: 'Date'}, + username: {type: 'String'}, + password: {type: 'String'}, + authData: {type: 'Object'}, + email: {type: 'String'}, + emailVerified: {type: 'Boolean'}, + newField: {type: 'String'}, + ACL: {type: 'ACL'} + } + }); + done(); + }); + }); + }) + }); + it('lets you delete multiple fields and add fields', done => { var obj1 = hasAllPODobject(); obj1.save() diff --git a/src/Routers/SchemasRouter.js b/src/Routers/SchemasRouter.js index e352bd5e90..59fef02da3 100644 --- a/src/Routers/SchemasRouter.js +++ b/src/Routers/SchemasRouter.js @@ -85,7 +85,7 @@ function modifySchema(req) { throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${req.params.className} does not exist.`); } - let existingFields = schema.data[className]; + let existingFields = Object.assign(schema.data[className], {_id: className}); Object.keys(submittedFields).forEach(name => { let field = submittedFields[name]; if (existingFields[name] && field.__op !== 'Delete') {