This repository was archived by the owner on Oct 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
64 lines (53 loc) · 2.52 KB
/
index.test.js
File metadata and controls
64 lines (53 loc) · 2.52 KB
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
64
const Queries = require('./index');
describe("implicit AND queries", () => {
test('single field', () => {
const query = Queries.SimpleQuery.create({id: 123}).toMongoQuery();
expect(query).toMatchObject({id: 123});
});
test('multi-field', () => {
const query = Queries.SimpleQuery.create({id: 123, version: 2, country:"Canada"}).toMongoQuery();
expect(query).toEqual({id: 123, version: 2, country:"Canada"});
});
})
describe("explicit AND queries", () => {
test('single condition', () => {
const query = Queries.Query.create().and({id: 123}).toMongoQuery();
expect(query).toMatchObject({$and:[{id: 123}]});
});
test('multi-condition', () => {
const query = Queries.Query.create().and({id: 123}, {version:2}).toMongoQuery();
expect(query).toMatchObject({$and:[{id: 123},{version:2}]});
});
test('multi-condition chain', () => {
const query = Queries.Query.create().and({id: 123}, {version:2}, {country:"canada"}).toMongoQuery();
expect(query).toMatchObject({$and:[{id: 123},{version:2},{country:"canada"}]});
});
})
describe("explicit OR queries", () => {
test('single condition', () => {
const query = Queries.Query.create().or({id: 123}).toMongoQuery();
expect(query).toMatchObject({$or:[{id: 123}]});
});
test('multi-condition', () => {
const query = Queries.Query.create().or({id: 123}, {version:2}).toMongoQuery();
expect(query).toMatchObject({$or:[{id: 123},{version:2}]});
});
test('multi-condition chain', () => {
const query = Queries.Query.create().or({id: 123}, {version:2}, {country:"canada"}).toMongoQuery();
expect(query).toMatchObject({$or:[{id: 123},{version:2},{country:"canada"}]});
});
})
describe("mixed conditional queries", () => {
test('or & and condition', () => {
const query = Queries.Query.create().or({id: 123}).and({version:2}).toMongoQuery();
expect(query).toMatchObject({$or:[{id: 123}], $and:[{version:2}]});
});
test('and & or condition', () => {
const query = Queries.Query.create().and({id: 123}).or({version:2}).toMongoQuery();
expect(query).toMatchObject({$and:[{id: 123}], $or:[{version:2}]});
});
test('multiple and & or conditions', () => {
const query = spec.AndQuery.create({id: 123}).or({version:2}).or({country:"canada"}).and({lang:"US"}).toMongoQuery();
expect(query).toMatchObject({$and:[{id: 123}, {lang:"US"}], $or:[{version:2}, {country:"canada"}]});
});
})