Skip afterFind for Aggregate and Distinct Queries (#4596)

This commit is contained in:
Diamond Lewis
2018-02-28 19:32:01 -06:00
committed by GitHub
parent 213801c4b1
commit d8f3fb16bd
2 changed files with 46 additions and 0 deletions

View File

@@ -1819,4 +1819,46 @@ describe('afterFind hooks', () => {
Parse.Cloud.afterSave('_PushStatus', () => {});
}).not.toThrow();
});
it('should skip afterFind hooks for aggregate', (done) => {
const hook = {
method: function() {
return Promise.reject();
}
};
spyOn(hook, 'method').and.callThrough();
Parse.Cloud.afterFind('MyObject', hook.method);
const obj = new Parse.Object('MyObject')
const pipeline = [{
group: { objectId: {} }
}];
obj.save().then(() => {
const query = new Parse.Query('MyObject');
return query.aggregate(pipeline);
}).then((results) => {
expect(results[0].objectId).toEqual(null);
expect(hook.method).not.toHaveBeenCalled();
done();
});
});
it('should skip afterFind hooks for distinct', (done) => {
const hook = {
method: function() {
return Promise.reject();
}
};
spyOn(hook, 'method').and.callThrough();
Parse.Cloud.afterFind('MyObject', hook.method);
const obj = new Parse.Object('MyObject')
obj.set('score', 10);
obj.save().then(() => {
const query = new Parse.Query('MyObject');
return query.distinct('score');
}).then((results) => {
expect(results[0]).toEqual(10);
expect(hook.method).not.toHaveBeenCalled();
done();
});
});
});