import test from "node:test"; import assert from "node:assert/strict"; import { callPost, holdPublishQueue, setupOpsCorpus } from "../_testCorpus"; // Run with: // pnpm -C editor exec tsx --test "app/api/ops/deploy-homepage/route.test.ts" // // The homepage's deploy path refuses BEFORE a job exists, like deploy-hub's. // Moved from e2e/ops-api.spec.ts (release 19, A2b). Nothing here can reach // wrangler: "built" is the homepage's stamp in the corpus's .export-builds // (there is none), the missing-build call asks for a PREVIEW, and the publish // queue is held, so a stage a regressed refusal failed to stop only queues. const corpus = await setupOpsCorpus("empty"); const deployHomepage = (await import("./route")).POST; const buildHomepage = (await import("../build-homepage/route")).POST; await holdPublishQueue(); test.after(() => corpus.cleanup()); test("deploy-homepage refuses a bad preview name and a missing build; build-homepage refuses a preview without a deploy", async () => { // A bad preview name is judged before any build is looked at. const production = await callPost(deployHomepage, { preview: "main" }); assert.equal(production.status, 400); assert.equal(production.body.error, '"main" is the production branch; a preview needs another name.'); const shape = await callPost(deployHomepage, { preview: "Not_Valid" }); assert.equal(shape.status, 400); assert.match(String(shape.body.error), /not a valid preview branch name/); // And on the build-then-deploy, before anything is built. const buildDeploy = await callPost(buildHomepage, { deploy: true, preview: "main" }); assert.equal(buildDeploy.status, 400); assert.match(String(buildDeploy.body.error), /is the production branch/); // build-homepage: a preview without a deploy is a mistake, not a build. const previewOnly = await callPost(buildHomepage, { preview: "home-check" }); assert.equal(previewOnly.status, 400); assert.match(String(previewOnly.body.error), /"preview" needs "deploy": true/); // No build: the homepage's stamp is the corpus's. const unbuilt = await callPost(deployHomepage, { preview: "home-check" }); assert.equal(unbuilt.status, 400); assert.match( String(unbuilt.body.error), /^no build of _homepage in .*\.export-builds\/_homepage — archilyzer publish homepage$/, ); assert.deepEqual(await corpus.listJobIds(), []); });