Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
22 lines
991 B
TypeScript
22 lines
991 B
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({ callMobileApi: vi.fn() }));
|
|
vi.mock("@/app/lib/server/mobileApi", () => ({ callMobileApi: mocks.callMobileApi }));
|
|
vi.mock("@/app/lib/server/session", () => ({ getToken: vi.fn().mockResolvedValue("jwt") }));
|
|
vi.mock("@/app/lib/server/sessionRefresh", () => ({ maybeRefreshSession: vi.fn() }));
|
|
|
|
import { GET } from "./route";
|
|
|
|
beforeEach(() => mocks.callMobileApi.mockReset());
|
|
|
|
describe("GET /api/auth/session company", () => {
|
|
it("passes companyId, companyCode and isSuper through", async () => {
|
|
mocks.callMobileApi.mockResolvedValue({
|
|
ok: true,
|
|
data: { id: 1, username: "john@ins", name: "J", roles: [], aclMenu: {}, companyId: 7, companyCode: "ins", isSuper: false },
|
|
});
|
|
const res = await GET(new Request("http://localhost/api/auth/session") as never);
|
|
expect(await res.json()).toMatchObject({ companyId: 7, companyCode: "ins", isSuper: false });
|
|
});
|
|
});
|