2022-04-05 15:02:17 +00:00
|
|
|
import { createSandbox } from "../environments/node_sandbox";
|
|
|
|
import { expect, test } from "@jest/globals";
|
|
|
|
import { System } from "../system";
|
|
|
|
import { storeSyscalls } from "./store.dexie_browser";
|
2022-03-25 11:03:06 +00:00
|
|
|
|
|
|
|
// For testing in node.js
|
|
|
|
require("fake-indexeddb/auto");
|
|
|
|
|
|
|
|
test("Test store", async () => {
|
|
|
|
let system = new System("server");
|
2022-04-03 16:42:12 +00:00
|
|
|
system.registerSyscalls([], storeSyscalls("test", "test"));
|
2022-03-25 11:03:06 +00:00
|
|
|
let plug = await system.load(
|
|
|
|
{
|
2022-04-26 17:04:36 +00:00
|
|
|
name: "test",
|
2022-03-25 11:03:06 +00:00
|
|
|
functions: {
|
|
|
|
test1: {
|
|
|
|
code: `(() => {
|
|
|
|
return {
|
|
|
|
default: async () => {
|
|
|
|
await self.syscall("store.set", "name", "Pete");
|
|
|
|
return await self.syscall("store.get", "name");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})()`,
|
|
|
|
},
|
|
|
|
test2: {
|
|
|
|
code: `(() => {
|
|
|
|
return {
|
|
|
|
default: async () => {
|
|
|
|
await self.syscall("store.set", "page1:bl:page2:10", {title: "Something", meta: 20});
|
|
|
|
await self.syscall("store.batchSet", [
|
|
|
|
{key: "page2:bl:page3", value: {title: "Something2", meta: 10}},
|
|
|
|
{key: "page2:bl:page4", value: {title: "Something3", meta: 10}},
|
|
|
|
]);
|
|
|
|
return await self.syscall("store.queryPrefix", "page2:");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})()`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
createSandbox
|
|
|
|
);
|
|
|
|
expect(await plug.invoke("test1", [])).toBe("Pete");
|
|
|
|
let queryResults = await plug.invoke("test2", []);
|
|
|
|
expect(queryResults.length).toBe(2);
|
|
|
|
expect(queryResults[0].value.meta).toBe(10);
|
|
|
|
await system.unloadAll();
|
|
|
|
});
|