mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 09:48:39 +00:00
test: dedupe diffs http local get setup
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user