63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
normalizeStripeInvoice,
|
|
parseStripeInvoicePaidFlag,
|
|
} from "@/components/displays/department/pos/displays/stripeEmailInvoice.js";
|
|
|
|
describe("stripeEmailInvoice", () => {
|
|
it("parses invoice paid flags without treating non-empty unpaid strings as paid", () => {
|
|
expect(parseStripeInvoicePaidFlag(true)).toBe(true);
|
|
expect(parseStripeInvoicePaidFlag(1)).toBe(true);
|
|
expect(parseStripeInvoicePaidFlag("true")).toBe(true);
|
|
expect(parseStripeInvoicePaidFlag("1")).toBe(true);
|
|
|
|
expect(parseStripeInvoicePaidFlag(false)).toBe(false);
|
|
expect(parseStripeInvoicePaidFlag(0)).toBe(false);
|
|
expect(parseStripeInvoicePaidFlag("false")).toBe(false);
|
|
expect(parseStripeInvoicePaidFlag("0")).toBe(false);
|
|
expect(parseStripeInvoicePaidFlag("open")).toBe(false);
|
|
});
|
|
|
|
it("requires paid status, a paid flag, and covered amount before unlocking invoice completion", () => {
|
|
expect(
|
|
normalizeStripeInvoice({
|
|
id: "in_unpaid_string",
|
|
paid: "false",
|
|
status: "open",
|
|
amount_due: "1000",
|
|
amount_paid: "0",
|
|
})?.paid
|
|
).toBe(false);
|
|
|
|
expect(
|
|
normalizeStripeInvoice({
|
|
id: "in_open_true_flag",
|
|
paid: true,
|
|
status: "open",
|
|
amount_due: "1000",
|
|
amount_paid: "1000",
|
|
})?.paid
|
|
).toBe(false);
|
|
|
|
expect(
|
|
normalizeStripeInvoice({
|
|
id: "in_underpaid",
|
|
paid: true,
|
|
status: "paid",
|
|
amount_due: "1000",
|
|
amount_paid: "999",
|
|
})?.paid
|
|
).toBe(false);
|
|
|
|
expect(
|
|
normalizeStripeInvoice({
|
|
id: "in_paid",
|
|
paid: "true",
|
|
status: "paid",
|
|
amount_due: "1000",
|
|
amount_paid: "1000",
|
|
})?.paid
|
|
).toBe(true);
|
|
});
|
|
});
|