From ca38e1a30ff0dcf6e65c359cc8139c10df3e18ee Mon Sep 17 00:00:00 2001 From: Brandon Wolfgang Date: Wed, 21 Oct 2026 19:16:37 -0500 Subject: [PATCH] test: add API endpoint tests with Node.js test runner - 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 --- package.json | 2 +- src/server.test.ts | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/server.test.ts diff --git a/package.json b/package.json index 230576d..5c55e4b 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", + "test": "tsx --test src/**/*.test.ts", "dev": "tsx watch src/server.ts", "build": "tsc -p tsconfig.json", "start": "node dist/server.js" diff --git a/src/server.test.ts b/src/server.test.ts new file mode 100644 index 0000000..f430346 --- /dev/null +++ b/src/server.test.ts @@ -0,0 +1,39 @@ +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", + }, + }); + }); +});