Pass context in beforeDelete, afterDelete, beforeFind and Parse.Cloud.run. (#6666)
* add context for following hooks. 1. beforeDelete 2. afterDelete 3. beforeFind 4. Cloud Function * revert un-necessary code change. * fix: failing test cases. * fix: failing test cases. * fix: failing test cases. * fix: failing test cases. * fix: failing test cases. * fix: failing test cases. * fix: failing test cases. * review changes * revert changes * revert changes * review changes * lint changes * review changes
This commit is contained in:
@@ -2968,4 +2968,58 @@ describe('afterLogin hook', () => {
|
||||
obj.set("obj2", obj2);
|
||||
await obj.save(null, { context: { a: 'a' } });
|
||||
});
|
||||
|
||||
it('should have access to context as saveAll argument', async () => {
|
||||
Parse.Cloud.beforeSave('TestObject', (req) => {
|
||||
expect(req.context.a).toEqual('a');
|
||||
});
|
||||
Parse.Cloud.afterSave('TestObject', (req) => {
|
||||
expect(req.context.a).toEqual('a');
|
||||
});
|
||||
const obj1 = new TestObject();
|
||||
const obj2 = new TestObject();
|
||||
await Parse.Object.saveAll([obj1, obj2], { context: { a: 'a' }});
|
||||
});
|
||||
|
||||
it('should have access to context as destroyAll argument', async () => {
|
||||
Parse.Cloud.beforeDelete('TestObject', (req) => {
|
||||
expect(req.context.a).toEqual('a');
|
||||
});
|
||||
Parse.Cloud.afterDelete('TestObject', (req) => {
|
||||
expect(req.context.a).toEqual('a');
|
||||
});
|
||||
const obj1 = new TestObject();
|
||||
const obj2 = new TestObject();
|
||||
await Parse.Object.saveAll([obj1, obj2]);
|
||||
await Parse.Object.destroyAll([obj1, obj2], { context: { a: 'a' } });
|
||||
});
|
||||
|
||||
it('should have access to context as destroy a object', async () => {
|
||||
Parse.Cloud.beforeDelete('TestObject', (req) => {
|
||||
expect(req.context.a).toEqual('a');
|
||||
});
|
||||
Parse.Cloud.afterDelete('TestObject', (req) => {
|
||||
expect(req.context.a).toEqual('a');
|
||||
});
|
||||
const obj = new TestObject();
|
||||
await obj.save();
|
||||
await obj.destroy({ context: { a: 'a' } });
|
||||
});
|
||||
|
||||
it('should have access to context in beforeFind hook', async () => {
|
||||
Parse.Cloud.beforeFind('TestObject', (req) => {
|
||||
expect(req.context.a).toEqual('a');
|
||||
});
|
||||
const query = new Parse.Query('TestObject');
|
||||
return query.find({ context: { a: 'a' } });
|
||||
});
|
||||
|
||||
it('should have access to context when cloud function is called.', async () => {
|
||||
Parse.Cloud.define('contextTest', async (req) => {
|
||||
expect(req.context.a).toEqual('a');
|
||||
return {};
|
||||
});
|
||||
|
||||
await Parse.Cloud.run('contextTest', {}, { context: { a: 'a' } });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user