Skip to content

Commit

Permalink
Merge 2c26e45 into 4187a97
Browse files Browse the repository at this point in the history
  • Loading branch information
dplewis authored May 10, 2023
2 parents 4187a97 + 2c26e45 commit df3dbef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
22 changes: 22 additions & 0 deletions spec/ParseLiveQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const Auth = require('../lib/Auth');
const UserController = require('../lib/Controllers/UserController').UserController;
const Config = require('../lib/Config');
const triggers = require('../lib/triggers');
const validatorFail = () => {
throw 'you are not authorized';
};
Expand Down Expand Up @@ -1212,4 +1213,25 @@ describe('ParseLiveQuery', function () {
object.set({ location: secondPoint });
await object.save();
});

it('prevent afterSave trigger if not exists', async () => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
spyOn(triggers, 'maybeRunTrigger').and.callThrough();
const object1 = new TestObject();
const object2 = new TestObject();
const object3 = new TestObject();
await Parse.Object.saveAll([object1, object2, object3]);

expect(triggers.maybeRunTrigger).toHaveBeenCalledTimes(0);
expect(object1.id).toBeDefined();
expect(object2.id).toBeDefined();
expect(object3.id).toBeDefined();
});
});
26 changes: 15 additions & 11 deletions src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -1577,17 +1577,21 @@ RestWrite.prototype.runAfterSaveTrigger = function () {
const { originalObject, updatedObject } = this.buildParseObjects();
updatedObject._handleSaveResponse(this.response.response, this.response.status || 200);

this.config.database.loadSchema().then(schemaController => {
// Notifiy LiveQueryServer if possible
const perms = schemaController.getClassLevelPermissions(updatedObject.className);
this.config.liveQueryController.onAfterSave(
updatedObject.className,
updatedObject,
originalObject,
perms
);
});

if (hasLiveQuery) {
this.config.database.loadSchema().then(schemaController => {
// Notify LiveQueryServer if possible
const perms = schemaController.getClassLevelPermissions(updatedObject.className);
this.config.liveQueryController.onAfterSave(
updatedObject.className,
updatedObject,
originalObject,
perms
);
});
}
if (!hasAfterSaveHook) {
return Promise.resolve();
}
// Run afterSave trigger
return triggers
.maybeRunTrigger(
Expand Down

0 comments on commit df3dbef

Please sign in to comment.