Files
piik/tests/native-domain-restore.test.ts
T
AAA 48127849d3 test(backup): distinguish rejected and unconfirmed site restore replies
Exercise the actual NativeDomainHosting adapter with definite pre-handoff rejection, committed response failure, lost reply and malformed success. This is the focused test accompanying the site-restore outcome correction, without restoring a real database.
2026-11-27 10:17:10 -05:00

20 lines
1.4 KiB
TypeScript

import { afterEach, expect, test, vi } from "vitest";
import { NativeDomainHosting } from "../src/client/channel/hosting-api";
const hosting = new NativeDomainHosting({});
afterEach(() => vi.unstubAllGlobals());
test.each([
["explicit rejection", Response.json({ error: "forbidden" }, { status: 403 }), "forbidden"],
["service rejected before handoff", Response.json({ error: "domain_restore_unavailable" }, { status: 409 }), "domain_restore_unavailable"],
["scratch storage unavailable", Response.json({ error: "restore_scratch_limit" }, { status: 507 }), "restore_scratch_limit"],
["committed with hosting failure", Response.json({ error: "domain_restored_connection_failed" }, { status: 409 }), "domain_restored_connection_failed"],
["service lost the result", Response.json({ error: "domain_restore_unavailable" }, { status: 503 }), "domain_restore_unconfirmed"],
["upstream failure", new Response("bad gateway", { status: 502 }), "domain_restore_unconfirmed"],
["truncated success", new Response('{"domainId":'), "domain_restore_unconfirmed"],
["success without the site ID", Response.json({}), "domain_restore_unconfirmed"],
] as const)("classifies a site restore reply indicating %s", async (_outcome, reply, expected) => {
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(reply));
await expect(hosting.restore(new Blob())).rejects.toThrow(expected);
});