Files
HexaHost-GameCloud/apps/api/test/health.test.js
smueller e37ea87b35
Some checks failed
CI / Go — node-agent tests (push) Has been cancelled
CI / Go — edge-gateway build (push) Has been cancelled
CI / Node — lint, typecheck, test, build (push) Has been cancelled
initial commit
2026-06-26 10:45:08 +02:00

32 lines
1012 B
JavaScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import http from "node:http";
describe("api health", () => {
it("returns ok for healthz", async () => {
const server = http.createServer((req, res) => {
if (req.url === "/healthz") {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ status: "ok", service: "api" }));
return;
}
res.writeHead(404);
res.end();
});
await new Promise<void>((resolve) => server.listen(0, resolve));
const addr = server.address();
assert.ok(addr && typeof addr === "object");
const port = addr.port;
const response = await fetch(`http://127.0.0.1:${port}/healthz`);
assert.equal(response.status, 200);
const body = (await response.json()) as { status: string };
assert.equal(body.status, "ok");
await new Promise<void>((resolve, reject) =>
server.close((err) => (err ? reject(err) : resolve())),
);
});
});