Fix issue #5274 on RestQuery.each and relations (#5276)

* Add test on RestQuery.each with relation

* Fix the failing test for RestQuery.each and relations

* Add test for getRolesForUser

* Fix format for comment

* Remove extra fit
This commit is contained in:
Perceval Archimbaud
2019-01-04 20:22:46 +01:00
committed by Florent Vilmart
parent eb877545de
commit 9f2fc88f0f
3 changed files with 110 additions and 8 deletions

View File

@@ -363,4 +363,65 @@ describe('RestQuery.each', () => {
expect(classSpy.calls.count()).toBe(4);
expect(results.length).toBe(7);
});
it('should work with query on relations', async () => {
const objectA = new Parse.Object('Letter', { value: 'A' });
const objectB = new Parse.Object('Letter', { value: 'B' });
const object1 = new Parse.Object('Number', { value: '1' });
const object2 = new Parse.Object('Number', { value: '2' });
const object3 = new Parse.Object('Number', { value: '3' });
const object4 = new Parse.Object('Number', { value: '4' });
await Parse.Object.saveAll([object1, object2, object3, object4]);
objectA.relation('numbers').add(object1);
objectB.relation('numbers').add(object2);
await Parse.Object.saveAll([objectA, objectB]);
const config = Config.get('test');
/**
* Two queries needed since objectId are sorted and we can't know which one
* going to be the first and then skip by the $gt added by each
*/
const queryOne = new RestQuery(
config,
auth.master(config),
'Letter',
{
numbers: {
__type: 'Pointer',
className: 'Number',
objectId: object1.id,
},
},
{ limit: 1 }
);
const queryTwo = new RestQuery(
config,
auth.master(config),
'Letter',
{
numbers: {
__type: 'Pointer',
className: 'Number',
objectId: object2.id,
},
},
{ limit: 1 }
);
const classSpy = spyOn(RestQuery.prototype, 'execute').and.callThrough();
const resultsOne = [];
const resultsTwo = [];
await queryOne.each(result => {
resultsOne.push(result);
});
await queryTwo.each(result => {
resultsTwo.push(result);
});
expect(classSpy.calls.count()).toBe(4);
expect(resultsOne.length).toBe(1);
expect(resultsTwo.length).toBe(1);
});
});