53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
import test from "node:test";
|
|
import { spawn } from "node:child_process";
|
|
import { once } from "node:events";
|
|
import { createServer } from "node:http";
|
|
|
|
function runScript(environment) {
|
|
const child = spawn(process.execPath, ["scripts/deploy/verify-release.mjs"], {
|
|
env: { ...process.env, ...environment },
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
});
|
|
return once(child, "close").then(([code]) => code);
|
|
}
|
|
|
|
test("release verifier requires deployment variables", async () => {
|
|
assertEqualExit(await runScript({}), 1);
|
|
});
|
|
|
|
test("release verifier rejects an unpublished brand", async () => {
|
|
const server = createServer((request, response) => {
|
|
if (request.url === "/health") {
|
|
response.writeHead(200, { "content-type": "application/json" });
|
|
response.end(JSON.stringify({ status: "ok", service: "fixture" }));
|
|
return;
|
|
}
|
|
if (request.url === "/admin/session/login") {
|
|
response.writeHead(200, { "content-type": "application/json" });
|
|
response.end(JSON.stringify({ token: "fixture-token", mustChangePassword: false }));
|
|
return;
|
|
}
|
|
if (request.url === "/admin/releases/readiness") {
|
|
response.writeHead(200, { "content-type": "application/json" });
|
|
response.end(JSON.stringify({ checks: [{ key: "brand", passed: true }] }));
|
|
return;
|
|
}
|
|
response.writeHead(200, { "content-type": "application/json" });
|
|
response.end(JSON.stringify({ publication: { status: "unpublished" } }));
|
|
});
|
|
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
const { port } = server.address();
|
|
const exitCode = await runScript({
|
|
API_BASE_URL: `http://127.0.0.1:${port}`,
|
|
BRAND_SLUG: "fixture",
|
|
ADMIN_USERNAME: "admin",
|
|
ADMIN_PASSWORD: "fixture-password",
|
|
});
|
|
server.close();
|
|
assertEqualExit(exitCode, 1);
|
|
});
|
|
|
|
function assertEqualExit(actual, expected) {
|
|
if (actual !== expected) throw new Error(`expected exit ${expected}, received ${actual}`);
|
|
}
|