From 288e74688848f067cb1a98a3875296189b66b44c Mon Sep 17 00:00:00 2001 From: Manuel Date: Tue, 28 Apr 2020 20:36:46 +0200 Subject: [PATCH] add context to Parse.Object.save (#6626) * added failing test * added parsing of context in REST save request * undo lint changes --- spec/CloudCode.spec.js | 13 +++++++++++++ src/RestWrite.js | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index bbd51d2a99..48ac7c2db5 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -2911,4 +2911,17 @@ describe('afterLogin hook', () => { await Parse.User.logIn('testuser', 'p@ssword'); done(); }); + + it('should have access to context as save argument', async () => { + // Declare triggers + Parse.Cloud.beforeSave('TestObject', (req) => { + expect(req.context.a).toEqual('a'); + }); + Parse.Cloud.afterSave('TestObject', (req) => { + expect(req.context.a).toEqual('a'); + }); + // Save object + const obj = new TestObject(); + await obj.save(null, { context: { a: 'a' } }); + }); }); diff --git a/src/RestWrite.js b/src/RestWrite.js index 38a795bb4d..84a67ec6c2 100644 --- a/src/RestWrite.js +++ b/src/RestWrite.js @@ -53,6 +53,11 @@ function RestWrite( } if (!query) { + // Parse context + if (data._context && data._context instanceof Object) { + this.context = data._context; + delete data._context; + } if (this.config.allowCustomObjectId) { if ( Object.prototype.hasOwnProperty.call(data, 'objectId') &&