@x5e/gink
Version:
an eventually consistent database
103 lines • 4.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const implementation_1 = require("../implementation");
const utils_1 = require("../implementation/utils");
const test_utils_1 = require("./test_utils");
it("include, exclude, and contains work as intended", async function () {
for (const store of [
new implementation_1.IndexedDbStore("PS.test1", true),
new implementation_1.MemoryStore(true),
]) {
const instance = new implementation_1.Database(store);
await instance.ready;
const ps1 = await instance.createPairSet();
const box1 = await instance.createBox();
const box2 = await instance.createBox();
const box3 = await instance.createBox();
await ps1.include([box1, box2]);
(0, utils_1.ensure)((await ps1.size()) === 1, `${await ps1.size()}`);
(0, utils_1.ensure)(await ps1.contains([box1, box2]));
await ps1.include([box2, box3]);
(0, utils_1.ensure)((await ps1.size()) === 2);
(0, utils_1.ensure)(await ps1.contains([box2, box3]));
await ps1.exclude([box1, box2]);
(0, utils_1.ensure)((await ps1.size()) === 1);
(0, utils_1.ensure)(!(await ps1.contains([box1, box2])));
await ps1.include([box1, box2]);
(0, utils_1.ensure)((await ps1.size()) === 2);
(0, utils_1.ensure)(await ps1.contains([box1.address, box2]));
(0, utils_1.ensure)(await ps1.contains([box1, box2.address]));
}
});
it("asOf and getPairs work properly", async function () {
for (const store of [
new implementation_1.IndexedDbStore("PS.test2", true),
new implementation_1.MemoryStore(true),
]) {
const instance = new implementation_1.Database(store);
await instance.ready;
const ps1 = await instance.createPairSet();
const box1 = await instance.createBox();
const box2 = await instance.createBox();
const box3 = await instance.createBox();
await ps1.include([box1, box2]);
await (0, test_utils_1.sleep)(10);
const time0 = Date.now() * 1000;
await (0, test_utils_1.sleep)(10);
await ps1.include([box2, box3]);
await (0, test_utils_1.sleep)(10);
const time1 = Date.now() * 1000;
await (0, test_utils_1.sleep)(10);
await ps1.include([box1, box3]);
await (0, test_utils_1.sleep)(10);
(0, utils_1.ensure)(await ps1.contains([box1, box2], time1));
(0, utils_1.ensure)(!(await ps1.contains([box1, box3], time1)));
const toSet = await ps1.getPairs();
(0, utils_1.ensure)(toSet.size === 3);
const asOfSet = await ps1.getPairs(time0);
(0, utils_1.ensure)(asOfSet.size === 1);
(0, utils_1.ensure)((await ps1.size(time0)) === 1);
(0, utils_1.ensure)(!(await ps1.contains([box1, box3], time0)));
}
});
it("PairSet.reset", async function () {
for (const store of [
new implementation_1.IndexedDbStore("ps-test3", true),
new implementation_1.MemoryStore(true),
]) {
const instance = new implementation_1.Database(store);
await instance.ready;
const box1 = await instance.createBox();
const box2 = await instance.createBox();
const ps = await instance.createPairSet();
await ps.include([box1, box2]);
const prop1 = await instance.createProperty();
const prop2 = await instance.createProperty();
await prop1.set(ps, "foo");
await prop2.set(ps, "bar");
const afterOne = (0, utils_1.generateTimestamp)();
await ps.include([box2, box1]);
await prop1.set(ps, "foo2");
await prop2.set(ps, "bar2");
(0, utils_1.ensure)(await ps.contains([box2, box1]));
await ps.reset({ toTime: afterOne });
(0, utils_1.ensure)(!(await ps.contains([box2, box1])));
(0, utils_1.ensure)(await ps.contains([box1, box2]));
(0, utils_1.ensure)((await prop1.get(ps)) === "foo");
(0, utils_1.ensure)((await prop2.get(ps)) === "bar");
await ps.reset();
(0, utils_1.ensure)((await ps.size()) === 0);
await ps.include([box1, box2]);
await ps.include([box2, box1]);
(0, utils_1.ensure)((await prop1.get(ps)) === undefined);
(0, utils_1.ensure)((await prop2.get(ps)) === undefined);
const beforeExclude = (0, utils_1.generateTimestamp)();
await ps.exclude([box1, box2]);
await ps.reset({ toTime: beforeExclude, skipProperties: true });
(0, utils_1.ensure)(await ps.contains([box1, box2]));
(0, utils_1.ensure)(await ps.contains([box2, box1]));
(0, utils_1.ensure)((await prop1.get(ps)) === undefined);
(0, utils_1.ensure)((await prop2.get(ps)) === undefined);
}
});
//# sourceMappingURL=PairSet.test.js.map