Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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