blob: 2c0588b39ac3afc932c85692df9644eab1b0a8fe (
plain)
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
|
import { Database } from "./database";
describe("Database module", () => {
let db: Database;
beforeAll(async () => {
db = new Database();
await db.init();
});
// Next 2 tests simply look
// for expections on operations that
// should be harmless
test("it should write data", () => {
return db.write("/hello/world", {
formula: "hello world"
});
});
test("it should fetch data", () => {
return db.fetch("/hello/world");
});
test("it should have a string representation", () => {
expect(db.toString()).not.toHaveLength(0);
});
test("it should write and then fetch data", async () => {
const path = "/hello/world";
const toWrite = {
secret: "stuff"
};
await db.write(path, toWrite);
const s = await db.fetch(path);
expect(s).toBe(toWrite);
});
test("it should be empty after a flush", async () => {
await db.write("/hello/world", {
my: "object"
});
await db.flush();
expect(db.toString()).toHaveLength(2); // empty object
});
test("it should fetch null on an empty node", async () => {
await db.flush();
const s = await db.fetch("/any/path/should/work");
expect(s).toBeNull();
});
test("it should not change on fetch", async () => {
await db.flush();
await db.write("/my/data/lives/here", {
whiteHouseDinner: `America's Finest McDouble's`
});
const before = db.toString();
const s = await db.fetch("/no/data/here/silly");
expect(s).toBeNull();
expect(before).toEqual(db.toString());
});
});
|