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", + }, + }); + }); +});