UNPKG

@x5e/gink

Version:

an eventually consistent database

106 lines 5.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const implementation_1 = require("../implementation"); const utils_1 = require("../implementation/utils"); it("include and exclude work as intended", async function () { for (const store of [ new implementation_1.IndexedDbStore("Group.test1", true), new implementation_1.MemoryStore(true), ]) { const instance = new implementation_1.Database({ store }); await instance.ready; const group1 = await implementation_1.Group.create(instance); const box1 = await implementation_1.Box.create(instance); const box2 = await implementation_1.Box.create(instance); await group1.include(box1); (0, utils_1.ensure)(await group1.isIncluded(box1), `Doesn't contain box1`); (0, utils_1.ensure)(await group1.isIncluded(box1.address)); await group1.exclude(box1); (0, utils_1.ensure)(!(await group1.isIncluded(box1)), `Still contains box1 after exclude`); // Testing a container can be excluded before it was included. await group1.exclude(box2); let found = false; const box2MuidStr = (0, utils_1.muidToString)(box2.address); for (const entry of await store.getAllEntries()) { if (Array.isArray(entry.storageKey) && entry.storageKey.length === 3) { if (box2MuidStr === (0, utils_1.muidToString)((0, utils_1.muidTupleToMuid)(entry.storageKey))) { found = true; } } } (0, utils_1.ensure)(found); } }); it("contains, toArray, and getMembers work properly", async function () { for (const store of [ new implementation_1.IndexedDbStore("Group.test2", true), new implementation_1.MemoryStore(true), ]) { const instance = new implementation_1.Database({ store }); await instance.ready; const group1 = await implementation_1.Group.create(instance); const box1 = await implementation_1.Box.create(instance); const box2 = await implementation_1.Box.create(instance); const box3 = await implementation_1.Box.create(instance); await group1.include(box1); await group1.include(box2); (0, utils_1.ensure)(await group1.isIncluded(box1)); (0, utils_1.ensure)(!(await group1.isIncluded(box3))); (0, utils_1.ensure)((await group1.size()) === 2); (0, utils_1.ensure)((await group1.includedAsArray()).length === 2); (0, utils_1.ensure)((await group1.includedAsArray())[0].behavior); for await (const member of group1.getMembers()) { (0, utils_1.ensure)(member.address && member.behavior && member.database); } } }); it("Group.reset", async function () { for (const store of [ new implementation_1.IndexedDbStore("Group.test3", true), new implementation_1.MemoryStore(true), ]) { const instance = new implementation_1.Database({ store }); await instance.ready; const box1 = await implementation_1.Box.create(instance); const box2 = await implementation_1.Box.create(instance); const group = await implementation_1.Group.create(instance); const prop1 = await implementation_1.Property.create(instance); const prop2 = await implementation_1.Property.create(instance); await prop1.set(group, "foo"); await prop2.set(group, "bar"); await group.include(box1); const afterOne = (0, utils_1.generateTimestamp)(); await group.include(box2); await prop1.set(group, "foo2"); await prop2.set(group, "bar2"); (0, utils_1.ensure)(await group.isIncluded(box2)); await group.reset(afterOne); await group.resetProperties(afterOne); (0, utils_1.ensure)((await prop1.get(group)) === "foo"); (0, utils_1.ensure)((await prop2.get(group)) === "bar"); (0, utils_1.ensure)(!(await group.isIncluded(box2))); (0, utils_1.ensure)(await group.isIncluded(box1)); await group.reset(); await group.resetProperties(); (0, utils_1.ensure)((await group.size()) === 0); let val = await prop1.get(group); if (val !== undefined) { store.dumpEntries(); } (0, utils_1.ensure)(val === undefined, val ? val.toString() : "no val"); (0, utils_1.ensure)((await prop2.get(group)) === undefined); await group.include(box1); await group.include(box2); const beforeExclude = (0, utils_1.generateTimestamp)(); await group.exclude(box1); await group.reset(beforeExclude); await group.resetProperties(beforeExclude); (0, utils_1.ensure)(await group.isIncluded(box1)); (0, utils_1.ensure)(await group.isIncluded(box2)); (0, utils_1.ensure)((await prop1.get(group)) === undefined); (0, utils_1.ensure)((await prop2.get(group)) === undefined); } }); //# sourceMappingURL=Group.test.js.map