Initial Commit
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { beforeEach, describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import { dispose } from "./dispose.js";
|
||||
import { handleRequest } from "./handle-request.js";
|
||||
import { start } from "./start.js";
|
||||
import { resetState } from "./wasm-state.js";
|
||||
|
||||
beforeEach(() => {
|
||||
resetState();
|
||||
});
|
||||
|
||||
function emptyReq(url: string): Parameters<typeof handleRequest>[0] {
|
||||
return {
|
||||
url,
|
||||
method: "GET",
|
||||
headers: [],
|
||||
bodyBase64: "",
|
||||
principalId: null,
|
||||
tenantId: null,
|
||||
capabilities: ["example:read", "example:write"],
|
||||
requestId: "r",
|
||||
timestamp: 0,
|
||||
};
|
||||
}
|
||||
|
||||
function decode(b64url: string): string {
|
||||
const padLen = (4 - (b64url.length % 4)) % 4;
|
||||
const padded =
|
||||
b64url.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat(padLen);
|
||||
return atob(padded);
|
||||
}
|
||||
|
||||
describe("wasm/start", () => {
|
||||
it("start is idempotent", { timeout: 5000 }, () => {
|
||||
start();
|
||||
start();
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
|
||||
it("start re-primes after dispose", { timeout: 5000 }, async () => {
|
||||
start();
|
||||
const res = await handleRequest(emptyReq("http://t/example/invoices"));
|
||||
expect(res.status).toBe(200);
|
||||
const body = JSON.parse(decode(res.bodyBase64)) as {
|
||||
invoices: readonly unknown[];
|
||||
};
|
||||
expect(body.invoices).toEqual([]);
|
||||
dispose();
|
||||
start();
|
||||
const after = await handleRequest(
|
||||
emptyReq("http://t/example/invoices")
|
||||
);
|
||||
const body2 = JSON.parse(decode(after.bodyBase64)) as {
|
||||
invoices: readonly unknown[];
|
||||
};
|
||||
expect(body2.invoices).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user