Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/apps/web/app/routes/auth.registration-plan-advice.test.ts
T

39 lines
1.7 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const loadRegistrationPlanSelection = vi.fn();
vi.mock("~/services/billing/registration-plan-selection.server", () => ({
loadRegistrationPlanSelection: (...args: unknown[]) => loadRegistrationPlanSelection(...args),
}));
import { loader } from "./auth.registration-plan-advice";
describe("registration plan advice resource", () => {
beforeEach(() => loadRegistrationPlanSelection.mockReset());
it("returns a no-store server-built recommendation for valid team sizes", async () => {
const selection = { recommendedPriceId: "price_pro", plans: [] };
loadRegistrationPlanSelection.mockResolvedValue(selection);
const response = await loader({ request: new Request("https://app.test/auth/registration-plan-advice?office=5&field=15") } as never);
expect(loadRegistrationPlanSelection).toHaveBeenCalledWith(null, { officeSeatQuantity: 5, fieldSeatQuantity: 15 });
expect(response.headers.get("Cache-Control")).toBe("private, no-store");
await expect(response.json()).resolves.toEqual(selection);
});
it.each(["office=&field=1", "office=0&field=1", "office=1.5&field=1", "office=1&field=-1", "office=10001&field=1"])(
"rejects invalid quantities without loading the catalog: %s",
async (query) => {
const failure = await loader({ request: new Request(`https://app.test/auth/registration-plan-advice?${query}`) } as never).catch(
(error: Response) => error
);
expect(failure).toMatchObject({
status: 400,
});
await expect(failure.json()).resolves.toEqual({ errorKey: "account.register.recommendationErrorBody" });
expect(loadRegistrationPlanSelection).not.toHaveBeenCalled();
}
);
});