Phase0
This commit is contained in:
@@ -2,12 +2,18 @@ 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 () => {
|
||||
describe("api health contract", () => {
|
||||
it("returns ok for liveness-style health response", async () => {
|
||||
const server = http.createServer((req, res) => {
|
||||
if (req.url === "/healthz") {
|
||||
if (req.url === "/api/v1/health/live") {
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify({ status: "ok", service: "api" }));
|
||||
res.end(
|
||||
JSON.stringify({
|
||||
status: "ok",
|
||||
service: "api",
|
||||
timestamp: new Date().toISOString(),
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
res.writeHead(404);
|
||||
@@ -19,10 +25,11 @@ describe("api health", () => {
|
||||
assert.ok(addr && typeof addr === "object");
|
||||
const port = addr.port;
|
||||
|
||||
const response = await fetch(`http://127.0.0.1:${port}/healthz`);
|
||||
const response = await fetch(`http://127.0.0.1:${port}/api/v1/health/live`);
|
||||
assert.equal(response.status, 200);
|
||||
const body = (await response.json()) as { status: string };
|
||||
const body = await response.json();
|
||||
assert.equal(body.status, "ok");
|
||||
assert.equal(body.service, "api");
|
||||
|
||||
await new Promise((resolve, reject) =>
|
||||
server.close((err) => (err ? reject(err) : resolve())),
|
||||
|
||||
Reference in New Issue
Block a user