Fixes issue affecting sorting in beforeFind (#4519)

* Fixes issue affecting sorting in beforeFind

* Update CloudCode.spec.js
This commit is contained in:
Florent Vilmart
2018-01-24 15:15:05 -05:00
committed by GitHub
parent 40407fea80
commit 401cc357e5
2 changed files with 30 additions and 0 deletions

View File

@@ -1472,6 +1472,32 @@ describe('beforeFind hooks', () => {
});
});
it('should handle sorting where', (done) => {
Parse.Cloud.beforeFind('MyObject', (req) => {
const query = req.query;
query.ascending('score');
return query;
});
const count = 20;
const objects = [];
while (objects.length != count) {
const object = new Parse.Object('MyObject');
object.set('score', Math.floor(Math.random() * 100));
objects.push(object);
}
Parse.Object.saveAll(objects).then(() => {
const query = new Parse.Query('MyObject');
return query.find();
}).then((objects) => {
let lastScore = -1;
objects.forEach((element) => {
expect(element.get('score') >= lastScore).toBe(true);
lastScore = element.get('score');
});
}).then(done).catch(done.fail);
});
it('should add beforeFind trigger using get API',(done) => {
const hook = {
method: function(req) {

View File

@@ -356,6 +356,10 @@ export function maybeRunQueryTrigger(triggerType, className, restWhere, restOpti
restOptions = restOptions || {};
restOptions.keys = jsonQuery.keys;
}
if (jsonQuery.order) {
restOptions = restOptions || {};
restOptions.order = jsonQuery.order;
}
if (requestObject.readPreference) {
restOptions = restOptions || {};
restOptions.readPreference = requestObject.readPreference;