-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.ts
63 lines (58 loc) · 1.83 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import * as Parse from 'parse/node';
import { ParseQueryGen, IParams } from './index';
test('should proccess ok the params', () => {
ParseQueryGen.setParse(Parse);
const params: IParams = {
className: 'MyClass',
equalTo: {
key: 'value',
key2: 'value2',
},
greaterThan: {
key3: 'value',
key4: 'value2',
},
lessThan: {
key5: 'value',
key6: 'value2',
},
notEqualTo: {
key7: 'abc',
},
ascending: ['createdAt'],
descending: ['updatedAt'],
containedIn: {
w: ['abc', '123'],
},
matches: {
string: 'value',
},
select: ['abc', 'abc2'],
containsAll: {
w2: ['abc', '123'],
},
include: ['brand'],
exists: ['test1', 'test2'],
matchesQuery: {
testKey: new Parse.Query('Test').equalTo('active', true),
},
};
const q = ParseQueryGen.gen(params);
const json = q.toJSON();
expect(q instanceof Parse.Query);
expect(q.className).toEqual(params.className);
expect(json.where.key).toEqual(params.equalTo.key);
expect(json.where.key2).toEqual(params.equalTo.key2);
expect(json.where.key3).toEqual({ $gt: params.greaterThan.key3 });
expect(json.where.key4).toEqual({ $gt: params.greaterThan.key4 });
expect(json.where.key5).toEqual({ $lt: params.lessThan.key5 });
expect(json.where.key6).toEqual({ $lt: params.lessThan.key6 });
expect(json.where.key7).toEqual({ $ne: params.notEqualTo.key7 });
expect(json.where.w).toEqual({ $in: params.containedIn.w });
expect(json.where.w2).toEqual({ $all: params.containsAll.w2 });
expect(json.where.string).toEqual({ $regex: params.matches.string });
expect(json.include).toEqual('brand');
expect(json.keys).toEqual(params.select.join(','));
expect(json.order.indexOf('createdAt') !== -1).toBe(true);
expect(json.order.indexOf('updatedAt') !== -1).toBe(true);
});