Files
co-lite/solvway-admin-portal/app/api/auth/session/route.company.test.ts
T

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 });
});
});