test: dedupe diffs http local get setup

This commit is contained in:
Peter Steinberger
2026-03-13 22:06:49 +00:00
parent 07900303f4
commit f7b9cfebe1

View File

@@ -9,6 +9,19 @@ describe("createDiffsHttpHandler", () => {
let store: DiffArtifactStore; let store: DiffArtifactStore;
let cleanupRootDir: () => Promise<void>; let cleanupRootDir: () => Promise<void>;
async function handleLocalGet(url: string) {
const handler = createDiffsHttpHandler({ store });
const res = createMockServerResponse();
const handled = await handler(
localReq({
method: "GET",
url,
}),
res,
);
return { handled, res };
}
beforeEach(async () => { beforeEach(async () => {
({ store, cleanup: cleanupRootDir } = await createDiffStoreHarness("openclaw-diffs-http-")); ({ store, cleanup: cleanupRootDir } = await createDiffStoreHarness("openclaw-diffs-http-"));
}); });
@@ -19,16 +32,7 @@ describe("createDiffsHttpHandler", () => {
it("serves a stored diff document", async () => { it("serves a stored diff document", async () => {
const artifact = await createViewerArtifact(store); const artifact = await createViewerArtifact(store);
const { handled, res } = await handleLocalGet(artifact.viewerPath);
const handler = createDiffsHttpHandler({ store });
const res = createMockServerResponse();
const handled = await handler(
localReq({
method: "GET",
url: artifact.viewerPath,
}),
res,
);
expect(handled).toBe(true); expect(handled).toBe(true);
expect(res.statusCode).toBe(200); expect(res.statusCode).toBe(200);
@@ -38,15 +42,8 @@ describe("createDiffsHttpHandler", () => {
it("rejects invalid tokens", async () => { it("rejects invalid tokens", async () => {
const artifact = await createViewerArtifact(store); const artifact = await createViewerArtifact(store);
const { handled, res } = await handleLocalGet(
const handler = createDiffsHttpHandler({ store }); artifact.viewerPath.replace(artifact.token, "bad-token"),
const res = createMockServerResponse();
const handled = await handler(
localReq({
method: "GET",
url: artifact.viewerPath.replace(artifact.token, "bad-token"),
}),
res,
); );
expect(handled).toBe(true); expect(handled).toBe(true);