Merge pull request #828 from Marco129/fix-update-system-schema

Fix add field to system schema
This commit is contained in:
Drew
2016-03-04 08:53:23 -08:00
2 changed files with 58 additions and 1 deletions

View File

@@ -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 => { it('lets you delete multiple fields and add fields', done => {
var obj1 = hasAllPODobject(); var obj1 = hasAllPODobject();
obj1.save() obj1.save()

View File

@@ -85,7 +85,7 @@ function modifySchema(req) {
throw new Parse.Error(Parse.Error.INVALID_CLASS_NAME, `Class ${req.params.className} does not exist.`); 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 => { 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') {