-
Notifications
You must be signed in to change notification settings - Fork 209
/
Copy pathdeleteRecord.test.ts
98 lines (86 loc) · 2.26 KB
/
deleteRecord.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { attest } from "@ark/attest";
import { defineStore } from "@latticexyz/store";
import { describe, it } from "vitest";
import { createStash } from "../createStash";
import { setRecord } from "./setRecord";
import { deleteRecord } from "./deleteRecord";
describe("deleteRecord", () => {
it("should delete a record from the stash", () => {
const config = defineStore({
namespace: "namespace1",
tables: {
table1: {
schema: {
field1: "string",
field2: "uint32",
field3: "int32",
},
key: ["field2", "field3"],
},
},
});
const table = config.namespaces.namespace1.tables.table1;
const stash = createStash(config);
setRecord({
stash,
table,
key: { field2: 1, field3: 2 },
record: { field1: "hello" },
});
setRecord({
stash,
table,
key: { field2: 3, field3: 1 },
record: { field1: "world" },
});
deleteRecord({
stash,
table,
key: { field2: 1, field3: 2 },
});
attest(stash.get().records).snap({
namespace1: {
table1: {
"3|1": {
field1: "world",
field2: 3,
field3: 1,
},
},
},
});
});
it("should throw a type error if an invalid key is provided", () => {
const config = defineStore({
namespace: "namespace1",
tables: {
table1: {
schema: {
field1: "string",
field2: "uint32",
field3: "int32",
},
key: ["field2", "field3"],
},
},
});
const table = config.namespaces.namespace1.tables.table1;
const stash = createStash(config);
attest(() =>
deleteRecord({
stash,
table,
// @ts-expect-error Property 'field3' is missing in type '{ field2: number; }'
key: { field2: 1 },
}),
).type.errors(`Property 'field3' is missing in type '{ field2: number; }'`);
attest(() =>
deleteRecord({
stash,
table,
// @ts-expect-error Type 'string' is not assignable to type 'number'
key: { field2: 1, field3: "invalid" },
}),
).type.errors(`Type 'string' is not assignable to type 'number'`);
});
});