Skip to content

Commit 44c2c8d

Browse files
committed
update relativeTests to async/await
1 parent b69d190 commit 44c2c8d

File tree

1 file changed

+53
-72
lines changed

1 file changed

+53
-72
lines changed

spec/ParseQuery.spec.js

+53-72
Original file line numberDiff line numberDiff line change
@@ -4766,7 +4766,7 @@ describe('Parse.Query testing', () => {
47664766
.catch(done.fail);
47674767
});
47684768

4769-
it('should handle relative times correctly', function (done) {
4769+
it('should handle relative times correctly', async () => {
47704770
const now = Date.now();
47714771
const obj1 = new Parse.Object('MyCustomObject', {
47724772
name: 'obj1',
@@ -4777,94 +4777,75 @@ describe('Parse.Query testing', () => {
47774777
ttl: new Date(now - 2 * 24 * 60 * 60 * 1000), // 2 days ago
47784778
});
47794779

4780-
Parse.Object.saveAll([obj1, obj2])
4781-
.then(() => {
4782-
const q = new Parse.Query('MyCustomObject');
4783-
q.greaterThan('ttl', { $relativeTime: 'in 1 day' });
4784-
return q.find({ useMasterKey: true });
4785-
})
4786-
.then(results => {
4787-
expect(results.length).toBe(1);
4788-
})
4789-
.then(() => {
4790-
const q = new Parse.Query('MyCustomObject');
4791-
q.greaterThan('ttl', { $relativeTime: '1 day ago' });
4792-
return q.find({ useMasterKey: true });
4793-
})
4794-
.then(results => {
4795-
expect(results.length).toBe(1);
4796-
})
4797-
.then(() => {
4798-
const q = new Parse.Query('MyCustomObject');
4799-
q.lessThan('ttl', { $relativeTime: '5 days ago' });
4800-
return q.find({ useMasterKey: true });
4801-
})
4802-
.then(results => {
4803-
expect(results.length).toBe(0);
4804-
})
4805-
.then(() => {
4806-
const q = new Parse.Query('MyCustomObject');
4807-
q.greaterThan('ttl', { $relativeTime: '3 days ago' });
4808-
return q.find({ useMasterKey: true });
4809-
})
4810-
.then(results => {
4811-
expect(results.length).toBe(2);
4812-
})
4813-
.then(() => {
4814-
const q = new Parse.Query('MyCustomObject');
4815-
q.greaterThan('ttl', { $relativeTime: 'now' });
4816-
return q.find({ useMasterKey: true });
4817-
})
4818-
.then(results => {
4819-
expect(results.length).toBe(1);
4820-
})
4821-
.then(() => {
4822-
const q = new Parse.Query('MyCustomObject');
4823-
q.greaterThan('ttl', { $relativeTime: 'now' });
4824-
q.lessThan('ttl', { $relativeTime: 'in 1 day' });
4825-
return q.find({ useMasterKey: true });
4826-
})
4827-
.then(results => {
4828-
expect(results.length).toBe(0);
4829-
})
4830-
.then(() => {
4831-
const q = new Parse.Query('MyCustomObject');
4832-
q.greaterThan('ttl', { $relativeTime: '1 year 3 weeks ago' });
4833-
return q.find({ useMasterKey: true });
4834-
})
4835-
.then(results => {
4836-
expect(results.length).toBe(2);
4837-
})
4838-
.then(done, done.fail);
4780+
await Parse.Object.saveAll([obj1, obj2])
4781+
const q1 = new Parse.Query('MyCustomObject');
4782+
q1.greaterThan('ttl', { $relativeTime: 'in 1 day' });
4783+
const results1 = await q1.find({ useMasterKey: true });
4784+
expect(results1.length).toBe(1);
4785+
4786+
const q2 = new Parse.Query('MyCustomObject');
4787+
q2.greaterThan('ttl', { $relativeTime: '1 day ago' });
4788+
const results2 = await q2.find({ useMasterKey: true });
4789+
expect(results2.length).toBe(1);
4790+
4791+
const q3 = new Parse.Query('MyCustomObject');
4792+
q3.lessThan('ttl', { $relativeTime: '5 days ago' });
4793+
const results3 = await q3.find({ useMasterKey: true });
4794+
expect(results3.length).toBe(0);
4795+
4796+
const q4 = new Parse.Query('MyCustomObject');
4797+
q4.greaterThan('ttl', { $relativeTime: '3 days ago' });
4798+
const results4 = await q4.find({ useMasterKey: true });
4799+
expect(results4.length).toBe(2);
4800+
4801+
const q5 = new Parse.Query('MyCustomObject');
4802+
q5.greaterThan('ttl', { $relativeTime: 'now' });
4803+
const results5 = await q5.find({ useMasterKey: true });
4804+
expect(results5.length).toBe(1);
4805+
4806+
const q6 = new Parse.Query('MyCustomObject');
4807+
q6.greaterThan('ttl', { $relativeTime: 'now' });
4808+
q6.lessThan('ttl', { $relativeTime: 'in 1 day' });
4809+
const results6 = await q6.find({ useMasterKey: true });
4810+
expect(results6.length).toBe(0);
4811+
4812+
const q7 = new Parse.Query('MyCustomObject');
4813+
q7.greaterThan('ttl', { $relativeTime: '1 year 3 weeks ago' });
4814+
const results7 = await q7.find({ useMasterKey: true });
4815+
expect(results7.length).toBe(2);
48394816
});
48404817

4841-
it('should error on invalid relative time', function (done) {
4818+
it('should error on invalid relative time', async () => {
48424819
const obj1 = new Parse.Object('MyCustomObject', {
48434820
name: 'obj1',
48444821
ttl: new Date(Date.now() + 2 * 24 * 60 * 60 * 1000), // 2 days from now
48454822
});
4846-
4823+
await obj1.save({ useMasterKey: true });
48474824
const q = new Parse.Query('MyCustomObject');
48484825
q.greaterThan('ttl', { $relativeTime: '-12 bananas ago' });
4849-
obj1
4850-
.save({ useMasterKey: true })
4851-
.then(() => q.find({ useMasterKey: true }))
4852-
.then(done.fail, () => done());
4826+
try {
4827+
await q.find({ useMasterKey: true });
4828+
fail("Should have thrown error");
4829+
} catch(error) {
4830+
expect(error.code).toBe(Parse.Error.INVALID_JSON);
4831+
}
48534832
});
48544833

4855-
it('should error when using $relativeTime on non-Date field', function (done) {
4834+
it('should error when using $relativeTime on non-Date field', async () => {
48564835
const obj1 = new Parse.Object('MyCustomObject', {
48574836
name: 'obj1',
48584837
nonDateField: 'abcd',
48594838
ttl: new Date(Date.now() + 2 * 24 * 60 * 60 * 1000), // 2 days from now
48604839
});
4861-
4840+
await obj1.save({ useMasterKey: true });
48624841
const q = new Parse.Query('MyCustomObject');
48634842
q.greaterThan('nonDateField', { $relativeTime: '1 day ago' });
4864-
obj1
4865-
.save({ useMasterKey: true })
4866-
.then(() => q.find({ useMasterKey: true }))
4867-
.then(done.fail, () => done());
4843+
try {
4844+
await q.find({ useMasterKey: true });
4845+
fail("Should have thrown error");
4846+
} catch(error) {
4847+
expect(error.code).toBe(Parse.Error.INVALID_JSON);
4848+
}
48684849
});
48694850

48704851
it('should match complex structure with dot notation when using matchesKeyInQuery', function (done) {

0 commit comments

Comments
 (0)