39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
import { buildApp } from "../src/app";
|
|
import { createRecordingQueue } from "../src/jobs/queue";
|
|
import { loadConfig } from "../src/config";
|
|
import { testConfig } from "./helpers";
|
|
|
|
describe("server skeleton", () => {
|
|
const app = buildApp(testConfig(), { jobs: createRecordingQueue() });
|
|
let baseUrl = "";
|
|
|
|
beforeAll(async () => {
|
|
baseUrl = await app.listen({ host: "127.0.0.1", port: 0 });
|
|
});
|
|
afterAll(() => app.close());
|
|
|
|
it("answers the health endpoint over HTTP", async () => {
|
|
const response = await fetch(`${baseUrl}/api/health`);
|
|
expect(response.status).toBe(200);
|
|
expect(await response.json()).toEqual({ status: "ok" });
|
|
});
|
|
});
|
|
|
|
describe("config loading", () => {
|
|
it("rejects a missing database URL and a short auth secret, listing both", () => {
|
|
expect(() =>
|
|
loadConfig({ BETTER_AUTH_SECRET: "short", BETTER_AUTH_URL: "http://localhost:3000" }),
|
|
).toThrow(/DATABASE_URL[\s\S]*BETTER_AUTH_SECRET|BETTER_AUTH_SECRET[\s\S]*DATABASE_URL/);
|
|
});
|
|
|
|
it("applies defaults", () => {
|
|
const config = loadConfig({
|
|
DATABASE_URL: "postgres://u:p@localhost:5432/db",
|
|
BETTER_AUTH_SECRET: "x".repeat(32),
|
|
BETTER_AUTH_URL: "http://localhost:3000",
|
|
});
|
|
expect(config).toMatchObject({ env: "development", port: 3000, logLevel: "info" });
|
|
});
|
|
});
|