-
Notifications
You must be signed in to change notification settings - Fork 0
/
or.test.ts
53 lines (50 loc) · 1.58 KB
/
or.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
import { testSuite, expect } from "manten";
import { nrml, testCollection } from "../../../common";
export default testSuite(async ({ describe }) => {
describe("$or", ({ test }) => {
test("works", () => {
const collection = testCollection();
collection.insert([
{ a: 1, b: 1, c: 1 },
{ a: 1, b: 1, c: 2 },
{ a: 1, b: 2, c: 3 },
{ a: 2, b: 2, c: 3 },
]);
const found = nrml(collection.find({ $or: [{ a: 1 }, { c: 2 }] }));
expect(found).toEqual([
{ a: 1, b: 1, c: 1 },
{ a: 1, b: 1, c: 2 },
{ a: 1, b: 2, c: 3 },
]);
});
test("nested operators", () => {
const collection = testCollection();
collection.insert([
{ foo: "bar", num: 5 },
{ foo: "bee", num: 8 },
{ foo: "baz", num: 10 },
{ foo: "boo", num: 20 },
]);
const found = nrml(collection.find({ $or: [{ foo: { $includes: "ba" } }, { num: { $lt: 9 } }] }));
expect(found).toEqual([
{ foo: "bar", num: 5 },
{ foo: "bee", num: 8 },
{ foo: "baz", num: 10 },
]);
});
test("works with dot notation", () => {
const collection = testCollection();
collection.insert([
{ a: { b: { c: 1, d: 1 } } },
{ a: { b: { c: 1, d: 2 } } },
{ a: { b: { c: 1, d: 3 } } },
]);
const found = nrml(collection.find({ $or: [{ "a.b.c": 1 }, { "a.b.d": 3 }] }));
expect(found).toEqual([
{ a: { b: { c: 1, d: 1 } } },
{ a: { b: { c: 1, d: 2 } } },
{ a: { b: { c: 1, d: 3 } } },
]);
})
});
});