UNPKG

@x5e/gink

Version:

an eventually consistent database

91 lines 4.35 kB
"use strict"; 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 implementation_1.PairSet.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 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 implementation_1.PairSet.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 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 implementation_1.Box.create(instance); const box2 = await implementation_1.Box.create(instance); const ps = await implementation_1.PairSet.create(instance); await ps.include([box1, box2]); const afterOne = (0, utils_1.generateTimestamp)(); await ps.include([box2, box1]); (0, utils_1.ensure)(await ps.contains([box2, box1])); await ps.reset(afterOne); (0, utils_1.ensure)(!(await ps.contains([box2, box1]))); (0, utils_1.ensure)(await ps.contains([box1, box2])); await ps.reset(); (0, utils_1.ensure)((await ps.size()) === 0); await ps.include([box1, box2]); await ps.include([box2, box1]); const beforeExclude = (0, utils_1.generateTimestamp)(); await ps.exclude([box1, box2]); await ps.reset(beforeExclude); (0, utils_1.ensure)(await ps.contains([box1, box2])); (0, utils_1.ensure)(await ps.contains([box2, box1])); } }); //# sourceMappingURL=PairSet.test.js.map