| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import { describe, it, expect, vi, beforeEach } from "vitest";
- // 1) Mock for destroySession
- vi.mock("@/lib/auth/session", () => ({
- destroySession: vi.fn(),
- }));
- // 2) Import after mock
- import { destroySession } from "@/lib/auth/session";
- import { GET } from "./route";
- describe("GET /api/auth/logout", () => {
- beforeEach(() => {
- vi.clearAllMocks();
- });
- it("calls destroySession and returns ok: true", async () => {
- const response = await GET();
- const json = await response.json();
- expect(destroySession).toHaveBeenCalledTimes(1);
- expect(response.status).toBe(200);
- expect(json).toEqual({ ok: true });
- });
- it("returns 500 when destroySession throws an error", async () => {
- destroySession.mockImplementation(() => {
- throw new Error("boom");
- });
- const response = await GET();
- const json = await response.json();
- expect(destroySession).toHaveBeenCalledTimes(1);
- expect(response.status).toBe(500);
- expect(json).toEqual({ error: "Internal server error" });
- });
- });
|