Skip to content

Commit 0a923bd

Browse files
committed
test: Make aggregation date conversion tests deterministic and faster
1 parent f1008d9 commit 0a923bd

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

spec/ParseQuery.Aggregate.spec.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,31 +476,29 @@ describe('Parse.Query Aggregate testing', () => {
476476
it_id('e09a170a-38fc-4439-9383-8d5270caad9e')(it_exclude_dbs(['postgres']))('converts JS Date values to BSON when using _created_at in $match', async () => {
477477
const obj = new TestObject();
478478
await obj.save();
479-
await new Promise(r => setTimeout(r, 2000));
480-
const date = new Date();
479+
const date = new Date(obj.createdAt.getTime() + 1);
481480
const pipeline = [
482-
{ $match: { _created_at: { $lte: date } } },
481+
{ $match: { objectId: obj.id, _created_at: { $lte: date } } },
483482
{ $count: 'total' },
484483
];
485484
const query = new Parse.Query('TestObject');
486485
const results = await query.aggregate(pipeline, { useMasterKey: true });
487486
expect(results.length).toBe(1);
488-
expect(results[0].total).toBeGreaterThanOrEqual(1);
487+
expect(results[0].total).toBe(1);
489488
});
490489

491490
it_id('8234438d-44b7-4029-a202-433c55d673e3')(it_exclude_dbs(['postgres']))('converts JS Date values to BSON when using _updated_at in $match', async () => {
492491
const obj = new TestObject();
493492
await obj.save();
494-
await new Promise(r => setTimeout(r, 2000));
495-
const date = new Date();
493+
const date = new Date(obj.updatedAt.getTime() + 1);
496494
const pipeline = [
497-
{ $match: { _updated_at: { $lte: date } } },
495+
{ $match: { objectId: obj.id, _updated_at: { $lte: date } } },
498496
{ $count: 'total' },
499497
];
500498
const query = new Parse.Query('TestObject');
501499
const results = await query.aggregate(pipeline, { useMasterKey: true });
502500
expect(results.length).toBe(1);
503-
expect(results[0].total).toBeGreaterThanOrEqual(1);
501+
expect(results[0].total).toBe(1);
504502
});
505503

506504
it_only_db('postgres')(

0 commit comments

Comments
 (0)