mirror of
https://github.com/Since-3/Kuma.git
synced 2026-10-12 20:51:18 +00:00
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
|
|
vi.mock("@/src/lib/prisma", () => ({
|
|
prisma: { customerPass: { findFirst: vi.fn(), updateMany: vi.fn() } },
|
|
}));
|
|
|
|
import { reconcilePassRefund } from "@/src/modules/products/lib/pass-refund";
|
|
import { prisma } from "@/src/lib/prisma";
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
vi.mocked(prisma.customerPass.updateMany).mockResolvedValue({ count: 1 } as never);
|
|
});
|
|
|
|
describe("reconcilePassRefund", () => {
|
|
it("schließt eine offene Kartenerstattung ab, sobald Stripe sie meldet", async () => {
|
|
vi.mocked(prisma.customerPass.findFirst).mockResolvedValue({ id: "pass-1" } as never);
|
|
|
|
await reconcilePassRefund({
|
|
refunded: true,
|
|
payment_intent: "pi_1",
|
|
amount_refunded: 12500,
|
|
} as never);
|
|
|
|
expect(prisma.customerPass.findFirst).toHaveBeenCalledWith({
|
|
where: { stripePaymentIntentId: "pi_1", status: "refunding" },
|
|
select: { id: true },
|
|
});
|
|
expect(prisma.customerPass.updateMany).toHaveBeenCalledWith({
|
|
where: { id: "pass-1", status: "refunding" },
|
|
data: expect.objectContaining({ status: "refunded", refundedAmount: 12500 }),
|
|
});
|
|
});
|
|
|
|
it("ignoriert Teilerstattungen - eine Karte wird nur komplett erstattet", async () => {
|
|
await reconcilePassRefund({ refunded: false, payment_intent: "pi_1" } as never);
|
|
expect(prisma.customerPass.findFirst).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("tut nichts, wenn keine Kartenerstattung auf diese Zahlung wartet", async () => {
|
|
vi.mocked(prisma.customerPass.findFirst).mockResolvedValue(null);
|
|
await reconcilePassRefund({
|
|
refunded: true,
|
|
payment_intent: "pi_x",
|
|
amount_refunded: 1,
|
|
} as never);
|
|
expect(prisma.customerPass.updateMany).not.toHaveBeenCalled();
|
|
});
|
|
});
|