fix context for cascade-saving and saving existing object (#6735)

* added test cases

* fixed unparsed context when updating object

* fixed context inheritance for cascade-saved objects

* upgraded parse dependecy to 2.14.0

* rebuild

* removed superfluous comments

* undo lint changes
This commit is contained in:
Manuel
2020-07-02 21:37:41 +02:00
committed by GitHub
parent 41fc7c1f21
commit f095dffcc3
5 changed files with 1332 additions and 2385 deletions

View File

@@ -2912,16 +2912,60 @@ describe('afterLogin hook', () => {
done();
});
it('should have access to context as save argument', async () => {
// Declare triggers
it('should have access to context when saving a new object', async () => {
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' } });
});
it('should have access to context when saving an existing object', async () => {
const obj = new TestObject();
await obj.save(null);
Parse.Cloud.beforeSave('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
Parse.Cloud.afterSave('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
await obj.save(null, { context: { a: 'a' } });
});
it('should have access to context when saving a new object in a trigger', async () => {
Parse.Cloud.beforeSave('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
Parse.Cloud.afterSave('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
Parse.Cloud.afterSave('TriggerObject', async () => {
const obj = new TestObject();
await obj.save(null, { context: { a: 'a' } });
});
const obj = new Parse.Object('TriggerObject');
await obj.save(null);
});
it('should have access to context when cascade-saving objects', async () => {
Parse.Cloud.beforeSave('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
Parse.Cloud.afterSave('TestObject', (req) => {
expect(req.context.a).toEqual('a');
});
Parse.Cloud.beforeSave('TestObject2', (req) => {
expect(req.context.a).toEqual('a');
});
Parse.Cloud.afterSave('TestObject2', (req) => {
expect(req.context.a).toEqual('a');
});
const obj = new Parse.Object("TestObject");
const obj2 = new Parse.Object("TestObject2");
obj.set("obj2", obj2);
await obj.save(null, { context: { a: 'a' } });
});
});