Full cleanup pass

This commit is contained in:
adilallo
2026-05-21 23:25:56 -06:00
parent 28de8ef3bc
commit 99f535f821
149 changed files with 2623 additions and 1242 deletions
+2 -2
View File
@@ -102,14 +102,14 @@ describe("ContentContainer", () => {
});
it("applies correct width when specified", () => {
render(<ContentContainer post={mockPost} width="300px" size="xs" />);
render(<ContentContainer post={mockPost} width="300px" size="responsive" />);
const container = document.querySelector("div[class*='relative z-20']");
expect(container).toHaveStyle("width: 300px");
});
it("applies default width when not specified", () => {
render(<ContentContainer post={mockPost} size="xs" />);
render(<ContentContainer post={mockPost} size="responsive" />);
const container = document.querySelector("div[class*='relative z-20']");
expect(container).toHaveStyle("width: 200px");
+2 -3
View File
@@ -1,12 +1,11 @@
import { render, screen, cleanup } from "@testing-library/react";
import { screen, cleanup } from "@testing-library/react";
import { describe, test, expect, afterEach } from "vitest";
import { renderWithProviders as render } from "../utils/test-utils";
import LogoWall from "../../app/components/sections/LogoWall";
afterEach(() => {
cleanup();
});
// Pure presentational; no provider context needed.
describe("LogoWall Component", () => {
test("renders with default logos", () => {
render(<LogoWall />);
+81
View File
@@ -0,0 +1,81 @@
import { NextRequest } from "next/server";
import { beforeEach, describe, expect, it, vi } from "vitest";
const isDatabaseConfiguredMock = vi.fn();
const queryRawMock = vi.fn();
vi.mock("../../../lib/server/env", () => ({
isDatabaseConfigured: () => isDatabaseConfiguredMock(),
}));
vi.mock("../../../lib/server/db", () => ({
prisma: {
$queryRaw: (...args: unknown[]) => queryRawMock(...args),
},
}));
import { GET } from "../../../app/api/health/route";
beforeEach(() => {
isDatabaseConfiguredMock.mockReset();
queryRawMock.mockReset();
});
describe("GET /api/health", () => {
it("returns not_configured when DATABASE_URL is unset", async () => {
isDatabaseConfiguredMock.mockReturnValue(false);
const res = await GET(
new NextRequest("https://x.test/api/health"),
undefined,
);
expect(res.status).toBe(200);
expect(await res.json()).toEqual({
ok: true,
database: "not_configured",
});
expect(res.headers.get("x-request-id")).toBeTruthy();
expect(queryRawMock).not.toHaveBeenCalled();
});
it("returns connected when the database probe succeeds", async () => {
isDatabaseConfiguredMock.mockReturnValue(true);
queryRawMock.mockResolvedValueOnce([{ "?column?": 1 }]);
const res = await GET(
new NextRequest("https://x.test/api/health"),
undefined,
);
expect(res.status).toBe(200);
expect(await res.json()).toEqual({
ok: true,
database: "connected",
});
expect(queryRawMock).toHaveBeenCalled();
expect(res.headers.get("x-request-id")).toBeTruthy();
});
it("returns 503 with database error when the probe fails", async () => {
isDatabaseConfiguredMock.mockReturnValue(true);
queryRawMock.mockRejectedValueOnce(new Error("connection refused"));
const res = await GET(
new NextRequest("https://x.test/api/health"),
undefined,
);
expect(res.status).toBe(503);
expect(await res.json()).toEqual({
ok: false,
database: "error",
});
expect(res.headers.get("x-request-id")).toBeTruthy();
});
it("forwards an incoming x-request-id on the response", async () => {
isDatabaseConfiguredMock.mockReturnValue(false);
const res = await GET(
new NextRequest("https://x.test/api/health", {
headers: { "x-request-id": "req_health-1" },
}),
undefined,
);
expect(res.headers.get("x-request-id")).toBe("req_health-1");
});
});
+21 -3
View File
@@ -1,3 +1,4 @@
import { NextRequest } from "next/server";
import { beforeEach, describe, expect, it, vi } from "vitest";
const findManyMock = vi.fn();
@@ -17,7 +18,7 @@ vi.mock("../../lib/server/db", () => ({
import { GET } from "../../app/api/create-flow/methods/route";
function makeReq(url: string) {
return { nextUrl: new URL(url) } as unknown as Parameters<typeof GET>[0];
return new NextRequest(url);
}
beforeEach(() => {
@@ -25,13 +26,28 @@ beforeEach(() => {
});
describe("GET /api/create-flow/methods", () => {
it("400s on missing or unknown section", async () => {
const r1 = await GET(makeReq("https://x.test/api/create-flow/methods"));
it("400s on missing or unknown section with the canonical error shape", async () => {
const r1 = await GET(
makeReq("https://x.test/api/create-flow/methods"),
undefined,
);
expect(r1.status).toBe(400);
const body1 = (await r1.json()) as {
error: { code: string; message: string };
};
expect(body1.error.code).toBe("validation_error");
expect(body1.error.message).toMatch(/Unknown section/);
expect(r1.headers.get("x-request-id")).toBeTruthy();
const r2 = await GET(
makeReq("https://x.test/api/create-flow/methods?section=foo"),
undefined,
);
expect(r2.status).toBe(400);
const body2 = (await r2.json()) as {
error: { code: string; message: string };
};
expect(body2.error.code).toBe("validation_error");
});
it("returns ranked methods from the facet query", async () => {
@@ -44,6 +60,7 @@ describe("GET /api/create-flow/methods", () => {
makeReq(
"https://x.test/api/create-flow/methods?section=communication&facet.size=twoToFive&facet.orgType=workersCoop",
),
undefined,
);
expect(res.status).toBe(200);
const json = (await res.json()) as {
@@ -61,6 +78,7 @@ describe("GET /api/create-flow/methods", () => {
makeReq(
"https://x.test/api/create-flow/methods?section=communication&facet.size=oneMember",
),
undefined,
);
expect(res.status).toBe(200);
const json = (await res.json()) as { methods: unknown[] };