2022-04-03 16:42:12 +00:00
|
|
|
import {createSandbox} from "../environments/node_sandbox";
|
|
|
|
import {expect, test} from "@jest/globals";
|
|
|
|
import {System} from "../system";
|
|
|
|
import {ensureTable, storeSyscalls} from "./store.knex_node";
|
2022-03-25 11:03:06 +00:00
|
|
|
import knex from "knex";
|
|
|
|
import fs from "fs/promises";
|
|
|
|
|
|
|
|
test("Test store", async () => {
|
|
|
|
const db = knex({
|
|
|
|
client: "better-sqlite3",
|
|
|
|
connection: {
|
|
|
|
filename: "test.db",
|
|
|
|
},
|
|
|
|
useNullAsDefault: true,
|
|
|
|
});
|
|
|
|
await ensureTable(db, "test_table");
|
|
|
|
let system = new System("server");
|
2022-04-03 16:42:12 +00:00
|
|
|
system.registerSyscalls([], storeSyscalls(db, "test_table"));
|
2022-03-25 11:03:06 +00:00
|
|
|
let plug = await system.load(
|
|
|
|
"test",
|
|
|
|
{
|
|
|
|
functions: {
|
|
|
|
test1: {
|
|
|
|
code: `(() => {
|
|
|
|
return {
|
|
|
|
default: async () => {
|
|
|
|
await self.syscall("store.set", "name", "Pete");
|
|
|
|
return await self.syscall("store.get", "name");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})()`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
createSandbox
|
|
|
|
);
|
|
|
|
expect(await plug.invoke("test1", [])).toBe("Pete");
|
|
|
|
await system.unloadAll();
|
|
|
|
await fs.unlink("test.db");
|
|
|
|
});
|