import { ForbiddenException } from "@nestjs/common"; import { PlanLimitsService } from "../src/stripe/plan-limits.service"; import { createPrismaMock } from "./utils/mock-prisma"; describe("PlanLimitsService", () => { it("blocks free users from exceeding the account limit", async () => { const prisma = createPrismaMock(); prisma.subscription.findUnique.mockResolvedValue({ userId: "user_1", plan: "free" }); prisma.account.count.mockResolvedValue(2); const service = new PlanLimitsService(prisma as any); await expect(service.assertCanAddAccounts("user_1", 1)).rejects.toBeInstanceOf(ForbiddenException); }); it("allows unlimited elite accounts", async () => { const prisma = createPrismaMock(); prisma.subscription.findUnique.mockResolvedValue({ userId: "user_1", plan: "elite" }); const service = new PlanLimitsService(prisma as any); await expect(service.assertCanAddAccounts("user_1", 100)).resolves.toBeUndefined(); expect(prisma.account.count).not.toHaveBeenCalled(); }); });