68 lines
3.2 KiB
TypeScript
68 lines
3.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
defaultMollieFirstPaymentMethod,
|
|
MOLLIE_SEPA_DIRECT_DEBIT_MAX_EUR_CENTS,
|
|
requiresMollieCardForAmount,
|
|
resolveMollieCheckoutPaymentMethodRequirement,
|
|
resolveMollieRecurringPaymentMethod,
|
|
selectMollieRecurringMandate,
|
|
} from "./mollie-payment-policy.js";
|
|
|
|
describe("Mollie payment policy", () => {
|
|
it("switches from SEPA to card only above the exact EUR 1,000 boundary", () => {
|
|
expect(requiresMollieCardForAmount({ amountCents: MOLLIE_SEPA_DIRECT_DEBIT_MAX_EUR_CENTS, currency: "eur" })).toBe(false);
|
|
expect(requiresMollieCardForAmount({ amountCents: MOLLIE_SEPA_DIRECT_DEBIT_MAX_EUR_CENTS + 1, currency: "EUR" })).toBe(true);
|
|
expect(
|
|
resolveMollieCheckoutPaymentMethodRequirement({
|
|
amountCents: MOLLIE_SEPA_DIRECT_DEBIT_MAX_EUR_CENTS + 1,
|
|
currency: "EUR",
|
|
configuredRequirement: "sepa",
|
|
})
|
|
).toBe("card");
|
|
});
|
|
|
|
it("keeps the configured method contract at or below the boundary", () => {
|
|
expect(
|
|
resolveMollieCheckoutPaymentMethodRequirement({
|
|
amountCents: MOLLIE_SEPA_DIRECT_DEBIT_MAX_EUR_CENTS,
|
|
currency: "EUR",
|
|
configuredRequirement: "sepa",
|
|
})
|
|
).toBe("sepa");
|
|
expect(resolveMollieCheckoutPaymentMethodRequirement({ amountCents: 29_900, currency: "EUR", configuredRequirement: "any" })).toBe("any");
|
|
});
|
|
|
|
it("pins high-value first and recurring payments to credit card", () => {
|
|
expect(defaultMollieFirstPaymentMethod("card", ["ideal"])).toBe("creditcard");
|
|
expect(resolveMollieRecurringPaymentMethod({ amountCents: 100_001, currency: "EUR", billingCadence: "monthly" })).toBe("creditcard");
|
|
expect(resolveMollieRecurringPaymentMethod({ amountCents: 100_000, currency: "EUR", billingCadence: "annual_sepa" })).toBeNull();
|
|
});
|
|
|
|
it("uses the latest valid customer-selected mandate below the boundary", () => {
|
|
expect(
|
|
selectMollieRecurringMandate({
|
|
amountCents: 100_000,
|
|
currency: "EUR",
|
|
mandates: [
|
|
{ provider: "mollie", providerMandateId: "mdt_sepa", status: "valid", method: "directdebit", createdAt: "2026-08-01T10:00:00.000Z" },
|
|
{ provider: "mollie", providerMandateId: "mdt_card", status: "valid", method: "creditcard", createdAt: "2026-08-02T10:00:00.000Z" },
|
|
],
|
|
})
|
|
).toMatchObject({ providerMandateId: "mdt_card", method: "creditcard" });
|
|
});
|
|
|
|
it("requires a valid card mandate above the boundary without SEPA fallback", () => {
|
|
const mandates = [
|
|
{ provider: "mollie" as const, providerMandateId: "mdt_sepa", status: "valid" as const, method: "directdebit" as const, createdAt: null },
|
|
{ provider: "mollie" as const, providerMandateId: "mdt_pending", status: "pending" as const, method: "creditcard" as const, createdAt: null },
|
|
];
|
|
expect(selectMollieRecurringMandate({ amountCents: 100_001, currency: "EUR", mandates })).toBeNull();
|
|
});
|
|
|
|
it("rejects malformed amounts and currencies before choosing a method", () => {
|
|
expect(() => requiresMollieCardForAmount({ amountCents: -1, currency: "EUR" })).toThrow("non-negative integer");
|
|
expect(() => requiresMollieCardForAmount({ amountCents: 100_001, currency: "EURO" })).toThrow("ISO 4217");
|
|
});
|
|
});
|