Skip to content

Commit

Permalink
Fix beforeQuery trigger when getting objects through GET API
Browse files Browse the repository at this point in the history
  • Loading branch information
davimacedo committed May 30, 2017
1 parent 9ad8697 commit 639784b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
27 changes: 27 additions & 0 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,33 @@ describe('beforeFind hooks', () => {
done();
});
});

it('should add beforeFind trigger using get API',(done) => {
const hook = {
method: function() {
return Promise.resolve();
}
};
spyOn(hook, 'method').and.callThrough();
Parse.Cloud.beforeFind('MyObject', hook.method);
const obj = new Parse.Object('MyObject');
obj.set('secretField', 'SSID');
obj.save().then(function() {
rp({
method: 'GET',
uri: 'http://localhost:8378/1/classes/MyObject/' + obj.id,
headers: {
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest'
},
json: true,
}).then(body => {
expect(body.secretField).toEqual('SSID');
expect(hook.method).toHaveBeenCalled();
done();
});
});
});
});

describe('afterFind hooks', () => {
Expand Down
9 changes: 7 additions & 2 deletions src/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ function find(config, auth, className, restWhere, restOptions, clientSDK) {

// get is just like find but only queries an objectId.
const get = (config, auth, className, objectId, restOptions, clientSDK) => {
var restWhere = { objectId };
enforceRoleSecurity('get', className, auth);
const query = new RestQuery(config, auth, className, { objectId }, restOptions, clientSDK);
return query.execute();
return triggers.maybeRunQueryTrigger(triggers.Types.beforeFind, className, restWhere, restOptions, config, auth).then((result) => {
restWhere = result.restWhere || restWhere;
restOptions = result.restOptions || restOptions;
const query = new RestQuery(config, auth, className, restWhere, restOptions, clientSDK);
return query.execute();
});
}

// Returns a promise that doesn't resolve to any useful value.
Expand Down

0 comments on commit 639784b

Please sign in to comment.