- Replace the placeholder test script with tsx --test - Add tests for GET /health response status and payload - Add tests for GET /ready response status and dependency status - Use Fastify injection to test endpoints without opening a network listener - Close the app after the test suite completes
39 lines
857 B
TypeScript
39 lines
857 B
TypeScript
import assert from "node:assert";
|
|
import { after, describe, it } from "node:test";
|
|
|
|
import { buildApp } from "./server.js";
|
|
|
|
describe("API endpoints", () => {
|
|
const app = buildApp();
|
|
|
|
after(async () => {
|
|
await app.close();
|
|
});
|
|
|
|
it("GET /health returns 200 and status ok", async () => {
|
|
const response = await app.inject({
|
|
method: "GET",
|
|
url: "/health",
|
|
});
|
|
|
|
assert.equal(response.statusCode, 200);
|
|
assert.deepEqual(response.json(), {
|
|
status: "ok",
|
|
});
|
|
});
|
|
|
|
it("GET /ready returns 200 and dependency status", async () => {
|
|
const response = await app.inject({
|
|
method: "GET",
|
|
url: "/ready",
|
|
});
|
|
|
|
assert.equal(response.statusCode, 200);
|
|
assert.deepEqual(response.json(), {
|
|
status: "ready",
|
|
dependencies: {
|
|
ollama: "not-integrated",
|
|
},
|
|
});
|
|
});
|
|
});
|