feat : also update
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const set = vi.fn().mockResolvedValue(null);
|
||||
const getRedisClient = vi.fn().mockResolvedValue({ set });
|
||||
const inspectImage = vi.fn();
|
||||
const verifyCommissionSlip = vi.fn();
|
||||
|
||||
vi.mock("server-only", () => ({}));
|
||||
vi.mock("@/lib/redis/client", () => ({ getRedisClient }));
|
||||
vi.mock("@/lib/media/inspect", () => ({ inspectImage }));
|
||||
vi.mock("@/lib/commission/payment", () => ({ verifyCommissionSlip }));
|
||||
|
||||
const { verifyAndCreateTicket } = await import("./slip-upload");
|
||||
|
||||
describe("commission slip submission lock", () => {
|
||||
it("rejects a second verification for the same checkout before calling Slip2Go", async () => {
|
||||
const checkout = { id: "checkout-1", userId: "customer-1", amountBaht: 150 };
|
||||
const file = new File(["image"], "slip.png", { type: "image/png" });
|
||||
await expect(verifyAndCreateTicket(checkout as Parameters<typeof verifyAndCreateTicket>[0], file))
|
||||
.rejects.toMatchObject({ status: 409, message: "slip-verification-in-progress" });
|
||||
expect(set).toHaveBeenCalledWith(expect.stringContaining(":commission-slip-lock:checkout-1"),
|
||||
expect.any(String), "EX", 60, "NX");
|
||||
expect(inspectImage).not.toHaveBeenCalled();
|
||||
expect(verifyCommissionSlip).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user