UNPKG

@x5e/gink

Version:

an eventually consistent database

74 lines 4.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const implementation_1 = require("../implementation"); it("test resetProperties", async function () { for (const store of [ new implementation_1.IndexedDbStore("Database.propertyReset.test", true), new implementation_1.MemoryStore(true), ]) { await store.ready; const db = new implementation_1.Database(store); await db.ready; const root = db.getGlobalDirectory(); const prop1 = await db.createProperty(); const prop2 = await db.createProperty(); await prop1.set(root, "foo"); await prop2.set(root, "bar"); await root.setName("root"); const resetTo = (0, implementation_1.generateTimestamp)(); await prop1.set(root, "foo2"); await prop2.set(root, "bar2"); const prop3 = await db.createProperty(); await prop3.set(root, "baz2"); await root.setName("root2"); (0, implementation_1.ensure)((await prop1.get(root)) === "foo2"); (0, implementation_1.ensure)((await prop2.get(root)) === "bar2"); (0, implementation_1.ensure)((await prop3.get(root)) === "baz2"); (0, implementation_1.ensure)((await root.getName()) === "root2"); await root.resetProperties(resetTo); (0, implementation_1.ensure)((await prop1.get(root)) === "foo"); (0, implementation_1.ensure)((await prop2.get(root)) === "bar"); (0, implementation_1.ensure)((await prop3.get(root)) === undefined); (0, implementation_1.ensure)((await root.getName()) === "root"); // clear all properties await root.resetProperties(); (0, implementation_1.ensure)((await prop1.get(root)) === undefined); (0, implementation_1.ensure)((await prop2.get(root)) === undefined); (0, implementation_1.ensure)((await prop3.get(root)) === undefined); (0, implementation_1.ensure)((await root.getName()) === undefined); // Same test with non-global container const seq = await db.createSequence(); const prop1Seq = await db.createProperty(); const prop2Seq = await db.createProperty(); await prop1Seq.set(seq, "foo"); await prop2Seq.set(seq, "bar"); await seq.setName("seq"); const resetToSeq = (0, implementation_1.generateTimestamp)(); await prop1Seq.set(seq, "foo2"); await prop2Seq.set(seq, "bar2"); const prop3Seq = await db.createProperty(); await prop3Seq.set(seq, "baz2"); await seq.setName("seq2"); (0, implementation_1.ensure)((await prop1Seq.get(seq)) === "foo2"); (0, implementation_1.ensure)((await prop2Seq.get(seq)) === "bar2"); (0, implementation_1.ensure)((await prop3Seq.get(seq)) === "baz2"); (0, implementation_1.ensure)((await seq.getName()) === "seq2"); await seq.resetProperties(resetToSeq); (0, implementation_1.ensure)((await prop1Seq.get(seq)) === "foo"); (0, implementation_1.ensure)((await prop2Seq.get(seq)) === "bar"); (0, implementation_1.ensure)((await prop3Seq.get(seq)) === undefined); (0, implementation_1.ensure)((await seq.getName()) === "seq"); const propValues = Array.from((await db.store.getContainerProperties(seq)).values()); (0, implementation_1.ensure)(propValues.length === 3); (0, implementation_1.ensure)(propValues.find((v) => v === "foo") !== undefined); (0, implementation_1.ensure)(propValues.find((v) => v === "bar") !== undefined); (0, implementation_1.ensure)(propValues.find((v) => v === "seq") !== undefined); (0, implementation_1.ensure)(propValues.find((v) => v === "baz2") === undefined); // clear all properties await seq.resetProperties(); (0, implementation_1.ensure)((await prop1Seq.get(seq)) === undefined); (0, implementation_1.ensure)((await seq.getName()) === undefined); (0, implementation_1.ensure)((await prop2Seq.get(seq)) === undefined); } }); //# sourceMappingURL=Container.test.js.map