Skip to content

Commit 2160c34

Browse files
committed
enforce keys
1 parent 3052060 commit 2160c34

File tree

2 files changed

+62
-55
lines changed

2 files changed

+62
-55
lines changed

spec/ParseAPI.spec.js

+60-49
Original file line numberDiff line numberDiff line change
@@ -951,57 +951,68 @@ describe('miscellaneous', function () {
951951
);
952952
});
953953

954-
it('should return the updated fields on PUT', done => {
954+
it('should return the updated fields on PUT', async () => {
955955
const obj = new Parse.Object('GameScore');
956-
obj
957-
.save({ a: 'hello', c: 1, d: ['1'], e: ['1'], f: ['1', '2'] })
958-
.then(() => {
959-
const headers = {
960-
'Content-Type': 'application/json',
961-
'X-Parse-Application-Id': 'test',
962-
'X-Parse-REST-API-Key': 'rest',
963-
'X-Parse-Installation-Id': 'yolo',
964-
};
965-
request({
966-
method: 'PUT',
967-
headers: headers,
968-
url: 'http://localhost:8378/1/classes/GameScore/' + obj.id,
969-
body: JSON.stringify({
970-
a: 'b',
971-
c: { __op: 'Increment', amount: 2 },
972-
d: { __op: 'Add', objects: ['2'] },
973-
e: { __op: 'AddUnique', objects: ['1', '2'] },
974-
f: { __op: 'Remove', objects: ['2'] },
975-
selfThing: {
976-
__type: 'Pointer',
977-
className: 'GameScore',
978-
objectId: obj.id,
979-
},
980-
}),
981-
}).then(response => {
982-
try {
983-
const body = response.data;
984-
expect(body.a).toBeUndefined();
985-
expect(body.c).toEqual(3); // 2+1
986-
expect(body.d.length).toBe(2);
987-
expect(body.d.indexOf('1') > -1).toBe(true);
988-
expect(body.d.indexOf('2') > -1).toBe(true);
989-
expect(body.e.length).toBe(2);
990-
expect(body.e.indexOf('1') > -1).toBe(true);
991-
expect(body.e.indexOf('2') > -1).toBe(true);
992-
expect(body.f.length).toBe(1);
993-
expect(body.f.indexOf('1') > -1).toBe(true);
994-
// return nothing on other self
995-
expect(body.selfThing).toBeUndefined();
996-
// updatedAt is always set
997-
expect(body.updatedAt).not.toBeUndefined();
998-
} catch (e) {
999-
fail(e);
1000-
}
1001-
done();
1002-
});
956+
const pointer = new Parse.Object('Child');
957+
Parse.Cloud.beforeSave('GameScore', request => {
958+
return request.object;
959+
});
960+
Parse.Cloud.afterSave('GameScore', request => {
961+
return request.object;
962+
});
963+
await pointer.save();
964+
obj.set(
965+
'point',
966+
new Parse.GeoPoint({
967+
latitude: 37.4848,
968+
longitude: -122.1483,
1003969
})
1004-
.catch(done.fail);
970+
);
971+
obj.set('array', ['obj1', 'obj2']);
972+
obj.set('objects', { a: 'b' });
973+
obj.set('string', 'abc');
974+
obj.set('bool', true);
975+
obj.set('number', 1);
976+
obj.set('date', new Date());
977+
obj.set('pointer', pointer);
978+
await obj.save({ a: 'hello', c: 1, d: ['1'], e: ['1'], f: ['1', '2'] });
979+
const headers = {
980+
'Content-Type': 'application/json',
981+
'X-Parse-Application-Id': 'test',
982+
'X-Parse-REST-API-Key': 'rest',
983+
'X-Parse-Installation-Id': 'yolo',
984+
};
985+
const response = await request({
986+
method: 'PUT',
987+
headers: headers,
988+
url: 'http://localhost:8378/1/classes/GameScore/' + obj.id,
989+
body: JSON.stringify({
990+
a: 'b',
991+
c: { __op: 'Increment', amount: 2 },
992+
d: { __op: 'Add', objects: ['2'] },
993+
e: { __op: 'AddUnique', objects: ['1', '2'] },
994+
f: { __op: 'Remove', objects: ['2'] },
995+
selfThing: {
996+
__type: 'Pointer',
997+
className: 'GameScore',
998+
objectId: obj.id,
999+
},
1000+
}),
1001+
});
1002+
const body = response.data;
1003+
expect(Object.keys(body).sort()).toEqual(['c', 'd', 'e', 'f', 'objectId', 'updatedAt']);
1004+
expect(body.a).toBeUndefined();
1005+
expect(body.c).toEqual(3); // 2+1
1006+
expect(body.d.length).toBe(2);
1007+
expect(body.d.indexOf('1') > -1).toBe(true);
1008+
expect(body.d.indexOf('2') > -1).toBe(true);
1009+
expect(body.e.length).toBe(2);
1010+
expect(body.e.indexOf('1') > -1).toBe(true);
1011+
expect(body.e.indexOf('2') > -1).toBe(true);
1012+
expect(body.f.length).toBe(1);
1013+
expect(body.f.indexOf('1') > -1).toBe(true);
1014+
expect(body.selfThing).toBeUndefined();
1015+
expect(body.updatedAt).not.toBeUndefined();
10051016
});
10061017

10071018
it('test cloud function error handling', done => {

src/RestWrite.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1678,19 +1678,15 @@ RestWrite.prototype._updateResponseWithData = function (response, data) {
16781678
this.storage.fieldsChangedByTrigger.push(key);
16791679
}
16801680
}
1681-
const skipKeys = [
1682-
'objectId',
1683-
'createdAt',
1684-
'updatedAt',
1685-
...(requiredColumns.read[this.className] || []),
1686-
];
1681+
const skipKeys = ['objectId', 'updatedAt', ...(requiredColumns.read[this.className] || [])];
16871682
for (const key in response) {
16881683
if (skipKeys.includes(key)) {
16891684
continue;
16901685
}
16911686
const value = response[key];
16921687
if (
16931688
value == null ||
1689+
data[key] == null ||
16941690
(value.__type && value.__type === 'Pointer') ||
16951691
util.isDeepStrictEqual(data[key], value)
16961692
) {

0 commit comments

Comments
 (0)