import { describe, it, expect } from "vitest"; import Fastify from "fastify"; import { registerVersionHeader, readAppVersion } from "../middleware/version"; /** * The server stamps every response with X-App-Version so the SPA can detect a * deploy (the client compares it to the version baked into its bundle). */ describe("registerVersionHeader", () => { it("adds X-App-Version to responses", async () => { const app = Fastify({ logger: false }); registerVersionHeader(app, "9.9.9"); app.get("/ping", async () => ({ ok: true })); const res = await app.inject({ method: "GET", url: "/ping" }); expect(res.headers["x-app-version"]).toBe("9.9.9"); await app.close(); }); it("defaults to the package.json version (semver string)", () => { expect(readAppVersion()).toMatch(/^\d+\.\d+\.\d+/); }); });