60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
|
|
function requiredEnvironment(name) {
|
|
const value = process.env[name];
|
|
if (!value) throw new Error(`${name} is required`);
|
|
return value;
|
|
}
|
|
|
|
async function requestJson(url, options = {}) {
|
|
const response = await fetch(url, options);
|
|
const body = await response.json().catch(() => null);
|
|
assert.ok(
|
|
response.ok && body,
|
|
`${options.method ?? "GET"} ${url} failed with status ${response.status}`,
|
|
);
|
|
return body;
|
|
}
|
|
|
|
const apiBaseUrl = requiredEnvironment("API_BASE_URL").replace(/\/$/, "");
|
|
const brandSlug = requiredEnvironment("BRAND_SLUG");
|
|
const username = requiredEnvironment("ADMIN_USERNAME");
|
|
const password = requiredEnvironment("ADMIN_PASSWORD");
|
|
|
|
const health = await requestJson(`${apiBaseUrl}/health`);
|
|
assert.equal(health.status, "ok");
|
|
console.log(`health: ok (${health.service})`);
|
|
|
|
const session = await requestJson(`${apiBaseUrl}/admin/session/login`, {
|
|
method: "POST",
|
|
headers: { "content-type": "application/json" },
|
|
body: JSON.stringify({ username, password }),
|
|
});
|
|
assert.equal(session.mustChangePassword, false, "admin must change the initial password");
|
|
const token = session.token ?? session.accessToken;
|
|
assert.equal(typeof token, "string", "login response does not contain a token");
|
|
console.log("admin login: ok");
|
|
|
|
const readiness = await requestJson(`${apiBaseUrl}/admin/releases/readiness`, {
|
|
headers: { authorization: `Bearer ${token}` },
|
|
});
|
|
const missingChecks = readiness.checks.filter((check) => !check.passed);
|
|
assert.deepEqual(
|
|
missingChecks.map((check) => check.label),
|
|
[],
|
|
`release readiness failed: ${missingChecks.map((check) => check.label).join(", ")}`,
|
|
);
|
|
console.log(`release readiness: ok (${readiness.checks.length} checks)`);
|
|
|
|
const workspace = await requestJson(
|
|
`${apiBaseUrl}/public/workspace?brandSlug=${encodeURIComponent(brandSlug)}`,
|
|
);
|
|
assert.equal(workspace.publication?.status, "published", "brand is not published");
|
|
assert.ok(
|
|
Array.isArray(workspace.offerings) && workspace.offerings.length > 0,
|
|
"published workspace has no offerings",
|
|
);
|
|
console.log(
|
|
`published workspace: ok (${brandSlug}, v${workspace.publication.version}, ${workspace.offerings.length} offerings)`,
|
|
);
|