35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
/**
|
|
* Route-level test for GET /api/ready (BACKLOG P0-3: "no /ready route
|
|
* existed at all"). Unlike /api/health, readiness fails closed: 503 when the
|
|
* load-bearing dependency (db) is not both configured and reachable.
|
|
*/
|
|
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
import { GET as readyGET } from "@/app/api/ready/route";
|
|
|
|
describe("GET /api/ready", () => {
|
|
const savedEnv = {
|
|
DATABASE_URL: process.env.DATABASE_URL,
|
|
POSTGRES_URL: process.env.POSTGRES_URL,
|
|
};
|
|
|
|
beforeEach(() => {
|
|
delete process.env.DATABASE_URL;
|
|
delete process.env.POSTGRES_URL;
|
|
});
|
|
|
|
afterEach(() => {
|
|
for (const [k, v] of Object.entries(savedEnv)) {
|
|
if (v === undefined) delete process.env[k];
|
|
else process.env[k] = v;
|
|
}
|
|
});
|
|
|
|
it("fails closed with 503 when the database is not configured", async () => {
|
|
const res = await readyGET();
|
|
expect(res.status).toBe(503);
|
|
const body = await res.json();
|
|
expect(body.ready).toBe(false);
|
|
expect(body.db).toBe("not_configured");
|
|
});
|
|
});
|