Skip to content
Open

tests #449

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions .github/workflows/assign-reviewers.yml

This file was deleted.

49 changes: 0 additions & 49 deletions apps/web/src/app/_components/reviews/unused/collapsable-info.tsx

This file was deleted.

20 changes: 0 additions & 20 deletions apps/web/src/app/_components/reviews/unused/info-card.tsx

This file was deleted.

38 changes: 0 additions & 38 deletions apps/web/src/app/_components/reviews/unused/new-role-card.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions apps/web/src/app/_components/reviews/unused/review-search-bar.tsx

This file was deleted.

144 changes: 0 additions & 144 deletions apps/web/src/app/_components/search/review-search-bar.tsx

This file was deleted.

55 changes: 55 additions & 0 deletions apps/web/test/api-routes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { beforeEach, describe, expect, test, vi } from "vitest";

const h = vi.hoisted(() => ({
fetchRequestHandler: vi.fn(),
toNextJsHandler: vi.fn(() => ({ GET: vi.fn(), POST: vi.fn() })),
getSession: vi.fn(),
auth: {},
}));

vi.mock("@trpc/server/adapters/fetch", () => ({
fetchRequestHandler: h.fetchRequestHandler,
}));
vi.mock("better-auth/next-js", () => ({ toNextJsHandler: h.toNextJsHandler }));
vi.mock("@cooper/api", () => ({
appRouter: {},
createTRPCContext: vi.fn(),
}));
vi.mock("@cooper/auth", () => ({
auth: { api: { getSession: h.getSession } },
}));

describe("api/auth/[...all] route", () => {
test("exposes GET and POST handlers from better-auth", async () => {
const route = await import("~/app/api/auth/[...all]/route");
expect(route.GET).toBeTypeOf("function");
expect(route.POST).toBeTypeOf("function");
expect(h.toNextJsHandler).toHaveBeenCalled();
});
});

describe("api/trpc/[trpc] route", () => {
beforeEach(() => {
vi.clearAllMocks();
});

test("OPTIONS responds 204 with permissive CORS headers", async () => {
const route = await import("~/app/api/trpc/[trpc]/route");
const res = route.OPTIONS();
expect(res.status).toBe(204);
expect(res.headers.get("Access-Control-Allow-Origin")).toBe("*");
expect(res.headers.get("Access-Control-Allow-Methods")).toBe(
"OPTIONS, GET, POST",
);
});

test("GET delegates to fetchRequestHandler and sets CORS headers", async () => {
h.fetchRequestHandler.mockResolvedValue(new Response("ok"));
const route = await import("~/app/api/trpc/[trpc]/route");

const res = await route.GET(new Request("http://localhost/api/trpc"));

expect(h.fetchRequestHandler).toHaveBeenCalledOnce();
expect(res.headers.get("Access-Control-Allow-Origin")).toBe("*");
});
});
Loading
Loading