32 lines
1.6 KiB
TypeScript
32 lines
1.6 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const { limit } = vi.hoisted(() => ({ limit: vi.fn() }));
|
|
vi.mock("server-only", () => ({}));
|
|
vi.mock("@/db", () => ({ getDb: () => ({ select: () => ({ from: () => ({ where: () => ({ limit }) }) }) }) }));
|
|
import { getCommissionSlipProvider, slipProviderConfigured } from "./slip-provider";
|
|
afterEach(() => { vi.unstubAllEnvs(); vi.clearAllMocks(); });
|
|
|
|
describe("commission provider configuration", () => {
|
|
it("reads fresh settings after switching", async () => {
|
|
limit.mockResolvedValueOnce([{ slipProvider: "slip2go" }]).mockResolvedValueOnce([{ slipProvider: "slipok" }]);
|
|
expect(await getCommissionSlipProvider()).toBe("slip2go");
|
|
expect(await getCommissionSlipProvider()).toBe("slipok");
|
|
expect(limit).toHaveBeenCalledTimes(2);
|
|
});
|
|
it.each([{ rows: [] }, { rows: [{ slipProvider: "invalid" }] }])("rejects missing or invalid settings", async ({ rows }) => {
|
|
limit.mockResolvedValueOnce(rows);
|
|
await expect(getCommissionSlipProvider()).rejects.toMatchObject({ status: 503 });
|
|
});
|
|
it("requires an HTTPS Slip2Go endpoint and key", () => {
|
|
vi.stubEnv("SLIP2GO_API_SECRET", "secret");
|
|
vi.stubEnv("SLIP2GO_VERIFY_URL", "http://slip.test");
|
|
expect(slipProviderConfigured("slip2go")).toBe(false);
|
|
vi.stubEnv("SLIP2GO_VERIFY_URL", "invalid");
|
|
expect(slipProviderConfigured("slip2go")).toBe(false);
|
|
vi.stubEnv("SLIP2GO_VERIFY_URL", "https://slip.test");
|
|
expect(slipProviderConfigured("slip2go")).toBe(true);
|
|
vi.stubEnv("SLIP2GO_API_SECRET", "");
|
|
expect(slipProviderConfigured("slip2go")).toBe(false);
|
|
});
|
|
});
|