This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeys_test.js
80 lines (74 loc) · 1.76 KB
/
keys_test.js
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
// deno-lint-ignore-file no-unused-vars
import { adapter } from "./adapter.js";
import { R } from "./deps.js";
import { assertEquals } from "./dev_deps.js";
const { head, last, prop, take, takeLast } = R;
function Datastore(config) {
const docs = [
{
_id: "1",
type: "movie",
title: "Ghostbusters",
dateAdded: "2021-08-01",
},
{
_id: "2",
type: "movie",
title: "Groundhog Day",
dateAdded: "2021-08-02",
},
{
_id: "3",
type: "movie",
title: "Avengers",
dateAdded: "2021-08-03",
},
{
_id: "4",
type: "movie",
title: "Batman",
dateAdded: "2021-08-04",
},
{
_id: "5",
type: "movie",
title: "Superman",
dateAdded: "2021-08-05",
},
{
_id: "6",
type: "movie",
title: "Hulk",
dateAdded: "2021-08-06",
},
{
_id: "7",
type: "movie",
title: "Captain America",
dateAdded: "2021-08-07",
},
{
_id: "8",
type: "movie",
title: "Black Widow",
dateAdded: "2021-08-08",
},
];
return Object.freeze({
insert: (doc) => Promise.resolve(doc),
findOne: (o) => Promise.resolve({ _id: "1", hello: "world" }),
updateOne: (criteria, action) =>
Promise.resolve({ _id: "1", hello: "moon" }),
removeOne: (o) => Promise.resolve(o),
find: () => Promise.resolve(docs),
update: (criteria, action) => Promise.resolve(action.$set),
});
}
const test = Deno.test;
const a = adapter({ filename: "./test.db" }, Datastore);
test("keys with adapter", async () => {
const res = await a.listDocuments({ db: "foo", keys: "1,3,5" });
assertEquals(res.docs.length, 3);
assertEquals(res.docs[0]._id, "1");
assertEquals(res.docs[2]._id, "5");
});