From c9f46e8ebc491e251bc129fd37e1a72c707b56b9 Mon Sep 17 00:00:00 2001 From: Yogendra Singh Date: Fri, 21 Jan 2022 16:17:44 +0530 Subject: [PATCH 1/3] fix: Pass context to afterFind hook while making object.fetch call. --- spec/CloudCode.spec.js | 9 +++++++++ src/Routers/ClassesRouter.js | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index c185eac53e..cc207c35f1 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -3224,6 +3224,15 @@ describe('afterLogin hook', () => { const query = new Parse.Query(TestObject); await query.find({ context: { a: 'a' } }); }); + + it('afterFind should have access to context while making fetch call', async () => { + Parse.Cloud.afterFind('TestObject', req => { + expect(req.context.a).toEqual('a'); + }); + const obj = new TestObject(); + await obj.save(); + await obj.fetch({ context: { a: 'a' } }); + }); }); describe('saveFile hooks', () => { diff --git a/src/Routers/ClassesRouter.js b/src/Routers/ClassesRouter.js index 6788d93e5f..7f3e0a84f3 100644 --- a/src/Routers/ClassesRouter.js +++ b/src/Routers/ClassesRouter.js @@ -83,7 +83,8 @@ export class ClassesRouter extends PromiseRouter { this.className(req), req.params.objectId, options, - req.info.clientSDK + req.info.clientSDK, + req.info.context ) .then(response => { if (!response.results || response.results.length == 0) { From 969e43bf6e2f5488ca3c4d3c4ee3dc5b45102dbb Mon Sep 17 00:00:00 2001 From: Yogendra Singh Date: Mon, 24 Jan 2022 12:04:22 +0530 Subject: [PATCH 2/3] review changes --- spec/CloudCode.spec.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index cc207c35f1..c98974d9d1 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -3225,9 +3225,15 @@ describe('afterLogin hook', () => { await query.find({ context: { a: 'a' } }); }); - it('afterFind should have access to context while making fetch call', async () => { + it('beforeFine and afterFind should have access to context while making fetch call', async () => { + Parse.Cloud.beforeFind('TestObject', req => { + expect(req.context.a).toEqual('a'); + expect(req.context.b).to.not.exist; + req.context.b = 'b'; + }); Parse.Cloud.afterFind('TestObject', req => { expect(req.context.a).toEqual('a'); + expect(req.context.b).toEqual('b'); }); const obj = new TestObject(); await obj.save(); From 2006ddffe332b4cfa715063184cd24ca34a12366 Mon Sep 17 00:00:00 2001 From: Yogendra Singh Date: Tue, 25 Jan 2022 08:54:45 +0530 Subject: [PATCH 3/3] build fix --- spec/CloudCode.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index c98974d9d1..4b8df9f9c9 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -3225,10 +3225,10 @@ describe('afterLogin hook', () => { await query.find({ context: { a: 'a' } }); }); - it('beforeFine and afterFind should have access to context while making fetch call', async () => { + it('beforeFind and afterFind should have access to context while making fetch call', async () => { Parse.Cloud.beforeFind('TestObject', req => { expect(req.context.a).toEqual('a'); - expect(req.context.b).to.not.exist; + expect(req.context.b).toBeUndefined(); req.context.b = 'b'; }); Parse.Cloud.afterFind('TestObject', req => {