fix: afterSave trigger removes pointer in Parse object (#7913)
This commit is contained in:
@@ -1598,6 +1598,32 @@ describe('Cloud Code', () => {
|
||||
expect(obj.get('count')).toBe(0);
|
||||
});
|
||||
|
||||
it('pointer should not be cleared by triggers', async () => {
|
||||
Parse.Cloud.afterSave('MyObject', () => {});
|
||||
const foo = await new Parse.Object('Test', { foo: 'bar' }).save();
|
||||
const obj = await new Parse.Object('MyObject', { foo }).save();
|
||||
const foo2 = obj.get('foo');
|
||||
expect(foo2.get('foo')).toBe('bar');
|
||||
});
|
||||
|
||||
it('can set a pointer in triggers', async () => {
|
||||
Parse.Cloud.beforeSave('MyObject', () => {});
|
||||
Parse.Cloud.afterSave(
|
||||
'MyObject',
|
||||
async ({ object }) => {
|
||||
const foo = await new Parse.Object('Test', { foo: 'bar' }).save();
|
||||
object.set({ foo });
|
||||
await object.save(null, { useMasterKey: true });
|
||||
},
|
||||
{
|
||||
skipWithMasterKey: true,
|
||||
}
|
||||
);
|
||||
const obj = await new Parse.Object('MyObject').save();
|
||||
const foo2 = obj.get('foo');
|
||||
expect(foo2.get('foo')).toBe('bar');
|
||||
});
|
||||
|
||||
it('beforeSave should not sanitize database', async done => {
|
||||
const { adapter } = Config.get(Parse.applicationId).database;
|
||||
const spy = spyOn(adapter, 'findOneAndUpdate').and.callThrough();
|
||||
|
||||
@@ -429,4 +429,26 @@ describe('RestQuery.each', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('test afterSave should not affect save response', async () => {
|
||||
Parse.Cloud.beforeSave('TestObject2', ({ object }) => {
|
||||
object.set('addedBeforeSave', true);
|
||||
});
|
||||
Parse.Cloud.afterSave('TestObject2', ({ object }) => {
|
||||
object.set('addedAfterSave', true);
|
||||
object.unset('initialToRemove');
|
||||
});
|
||||
const { response } = await rest.create(config, nobody, 'TestObject2', {
|
||||
initialSave: true,
|
||||
initialToRemove: true,
|
||||
});
|
||||
expect(Object.keys(response).sort()).toEqual([
|
||||
'addedAfterSave',
|
||||
'addedBeforeSave',
|
||||
'createdAt',
|
||||
'initialToRemove',
|
||||
'objectId',
|
||||
'updatedAt',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user