Fix beforeQuery trigger when getting objects through GET API (#3862)
This commit is contained in:
committed by
Florent Vilmart
parent
a0d1a3517f
commit
422723fa31
@@ -1211,6 +1211,7 @@ describe('beforeFind hooks', () => {
|
||||
expect(jsonQuery.include).toEqual('otherKey,otherValue');
|
||||
expect(jsonQuery.limit).toEqual(100);
|
||||
expect(jsonQuery.skip).toBe(undefined);
|
||||
expect(req.isGet).toEqual(false);
|
||||
});
|
||||
|
||||
const query = new Parse.Query('MyObject');
|
||||
@@ -1305,6 +1306,34 @@ describe('beforeFind hooks', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should add beforeFind trigger using get API',(done) => {
|
||||
const hook = {
|
||||
method: function(req) {
|
||||
expect(req.isGet).toEqual(true);
|
||||
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', () => {
|
||||
|
||||
Reference in New Issue
Block a user