fix: set objects in afterFind triggers (#7311)
This commit is contained in:
@@ -2391,6 +2391,53 @@ describe('afterFind hooks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('can set a pointer object in afterFind', async () => {
|
||||
const obj = new Parse.Object('MyObject');
|
||||
await obj.save();
|
||||
Parse.Cloud.afterFind('MyObject', async ({ objects }) => {
|
||||
const otherObject = new Parse.Object('Test');
|
||||
otherObject.set('foo', 'bar');
|
||||
await otherObject.save();
|
||||
objects[0].set('Pointer', otherObject);
|
||||
objects[0].set('xyz', 'yolo');
|
||||
expect(objects[0].get('Pointer').get('foo')).toBe('bar');
|
||||
});
|
||||
const query = new Parse.Query('MyObject');
|
||||
query.equalTo('objectId', obj.id);
|
||||
const obj2 = await query.first();
|
||||
expect(obj2.get('xyz')).toBe('yolo');
|
||||
const pointer = obj2.get('Pointer');
|
||||
expect(pointer.get('foo')).toBe('bar');
|
||||
});
|
||||
|
||||
it('can set invalid object in afterFind', async () => {
|
||||
const obj = new Parse.Object('MyObject');
|
||||
await obj.save();
|
||||
Parse.Cloud.afterFind('MyObject', () => [{}]);
|
||||
const query = new Parse.Query('MyObject');
|
||||
query.equalTo('objectId', obj.id);
|
||||
const obj2 = await query.first();
|
||||
expect(obj2).toBeDefined();
|
||||
expect(obj2.toJSON()).toEqual({});
|
||||
expect(obj2.id).toBeUndefined();
|
||||
});
|
||||
|
||||
it('can return a unsaved object in afterFind', async () => {
|
||||
const obj = new Parse.Object('MyObject');
|
||||
await obj.save();
|
||||
Parse.Cloud.afterFind('MyObject', async () => {
|
||||
const otherObject = new Parse.Object('Test');
|
||||
otherObject.set('foo', 'bar');
|
||||
return [otherObject];
|
||||
});
|
||||
const query = new Parse.Query('MyObject');
|
||||
const obj2 = await query.first();
|
||||
expect(obj2.get('foo')).toEqual('bar');
|
||||
expect(obj2.id).toBeUndefined();
|
||||
await obj2.save();
|
||||
expect(obj2.id).toBeDefined();
|
||||
});
|
||||
|
||||
it('should have request headers', done => {
|
||||
Parse.Cloud.afterFind('MyObject', req => {
|
||||
expect(req.headers).toBeDefined();
|
||||
|
||||
Reference in New Issue
Block a user