Skip to content

Fix #5654 #5664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions spec/ParseObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2068,4 +2068,19 @@ describe('Parse.Object testing', () => {

done();
});

it('isNew in cloud code', async () => {
Parse.Cloud.beforeSave('CloudCodeIsNew', req => {
expect(req.object.isNew()).toBeTruthy();
expect(req.object.id).toBeUndefined();
});

Parse.Cloud.afterSave('CloudCodeIsNew', req => {
expect(req.object.isNew()).toBeFalsy();
expect(req.object.id).toBeDefined();
});

const object = new Parse.Object('CloudCodeIsNew');
await object.save();
});
});
22 changes: 22 additions & 0 deletions spec/rest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,28 @@ describe('rest create', () => {
});
});

it('cannot set id', done => {
const headers = {
'Content-Type': 'application/json',
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
};
request({
headers: headers,
method: 'POST',
url: 'http://localhost:8378/1/classes/TestObject',
body: JSON.stringify({
foo: 'bar',
id: 'hello',
}),
}).then(fail, response => {
const b = response.data;
expect(b.code).toEqual(105);
expect(b.error).toEqual('id is an invalid field name.');
done();
});
});

it('test default session length', done => {
const user = {
username: 'asdf',
Expand Down
6 changes: 6 additions & 0 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ function RestWrite(
'objectId is an invalid field name.'
);
}
if (!query && data.id) {
throw new Parse.Error(
Parse.Error.INVALID_KEY_NAME,
'id is an invalid field name.'
);
}

// When the operation is complete, this.response may have several
// fields.
Expand Down