diff --git a/app/docs/route.test.ts b/app/docs/route.test.ts new file mode 100644 index 0000000..e849edc --- /dev/null +++ b/app/docs/route.test.ts @@ -0,0 +1,32 @@ +import { beforeEach, describe, expect, it, vi } from "vitest"; + +const mocks = vi.hoisted(() => ({ + getSession: vi.fn(), + listDocs: vi.fn(), + listSharedDocs: vi.fn(), +})); + +vi.mock("@/lib/auth/session", () => ({ getSession: mocks.getSession })); +vi.mock("@/lib/docs/store", () => ({ + listDocs: mocks.listDocs, + listSharedDocs: mocks.listSharedDocs, +})); +vi.mock("@/lib/db", () => ({ query: vi.fn() })); + +import { GET } from "@/app/docs/route"; + +describe("GET /docs", () => { + beforeEach(() => { + mocks.getSession.mockResolvedValue({ id: 1, email: "user@example.com", user_id: 1 }); + mocks.listDocs.mockResolvedValue([]); + mocks.listSharedDocs.mockResolvedValue([]); + }); + + it("shows a logout button for the current session", async () => { + const res = await GET(new Request("https://justhtml.sh/docs")); + const html = await res.text(); + + expect(html).toContain('