-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange.test.ts
57 lines (49 loc) · 1.98 KB
/
change.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
import { expect, testSuite } from "manten";
import { nrml, testCollection } from "../../../common";
export default testSuite(async ({ describe }) => {
describe("$change", ({ test }) => {
test("works", () => {
const collection = testCollection();
collection.insert({ a: 1 });
collection.insert({ a: 2 });
collection.update({ a: 2 }, { $change: { a: 3 } });
const found = nrml(collection.find({ a: 3 }));
expect(found).toEqual([{ a: 3 }]);
});
test("works deeply", () => {
const collection = testCollection();
collection.insert({ a: 1, b: { c: 5 } });
collection.update({ c: 5 }, { $change: { b: { c: 6 } } });
const found = nrml(collection.find({ a: 1 }));
expect(found).toEqual([{ a: 1, b: { c: 6 } }]);
});
test("works deeply with dot notation", () => {
const collection = testCollection();
collection.insert({ a: 1, b: { c: 5 } });
collection.update({ c: 5 }, { $change: { "b.c": 6 } });
const found = nrml(collection.find({ a: 1 }));
expect(found).toEqual([{ a: 1, b: { c: 6 } }]);
});
test("doesn't create new properties", () => {
const collection = testCollection();
collection.insert({ a: 1 });
collection.update({ a: 1 }, { $change: { b: 1 } });
const found = nrml(collection.find({ a: 1 }));
expect(found).toEqual([{ a: 1 }]);
});
test("doesn't create new properties, deep", () => {
const collection = testCollection();
collection.insert({ a: 1 });
collection.update({ a: 1 }, { $change: { b: { c: 1 } } });
const found = nrml(collection.find({ a: 1 }));
expect(found).toEqual([{ a: 1 }]);
});
test("doesn't create new properties, deep, dot notation", () => {
const collection = testCollection();
collection.insert({ a: 1 });
collection.update({ a: 1 }, { $change: { "b.c": 1 } });
const found = nrml(collection.find({ a: 1 }));
expect(found).toEqual([{ a: 1 }]);
});
});
});