import { describe, expect, it } from "vitest"; import { cartPaymentMethodsTransformRun as run } from "../src/cart_payment_methods_transform_run.js"; const methods = [ { id: "card", name: "Credit card" }, { id: "cod", name: "Cash on Delivery (COD)" }, { id: "store", name: "Pay in store" }, { id: "paypal", name: "PayPal" }, ]; const input = (m) => ({ cart: { selection: m ? { value: JSON.stringify({ m, d: "2026-11-07", s: "10:00-13:00" }) } : null }, paymentMethods: methods }); const hidden = (r) => r.operations.map((o) => o.paymentMethodHide.paymentMethodId); describe("payment rules", () => { it("hides pay-in-person methods for shipping", () => expect(hidden(run(input("shipping")))).toEqual(["cod", "store"])); it("keeps every method for pickup and local delivery", () => { expect(hidden(run(input("pickup")))).toEqual([]); expect(hidden(run(input("delivery")))).toEqual([]); }); it("changes nothing without a selection or with bad JSON", () => { expect(hidden(run(input(null)))).toEqual([]); expect(hidden(run({ cart: { selection: { value: "{x" } }, paymentMethods: methods }))).toEqual([]); }); it("doesn't hide names that merely contain the letters cod", () => { expect(hidden(run({ ...input("shipping"), paymentMethods: [{ id: "x", name: "Codiac Pay" }] }))).toEqual([]); }); });