import { describe, expect, it } from "vitest"; import { PaymentPlan } from "@/data/dto/payment"; import type { PaymentPlanInput } from "@/data/schemas/payment/payment_plan"; import { findTipCoffeePlan, formatTipPrice, isRealLoginStatus, } from "../tip-screen.helpers"; function makePlan(input: Partial): PaymentPlan { return PaymentPlan.from({ planId: "coins_100", planName: "Coins", orderType: "dol", vipDays: null, dolAmount: 100, creditBalance: 100, amountCents: 990, originalAmountCents: null, dailyPriceCents: null, currency: "USD", isFirstRechargeOffer: false, firstRechargeDiscountPercent: null, promotionType: null, ...input, }); } describe("tip screen helpers", () => { it("prefers the exact tip coffee plan id", () => { const byOrderType = makePlan({ planId: "legacy_coffee", planName: "Legacy coffee", orderType: "tip_coffee", }); const byPlanId = makePlan({ planId: "tip_coffee", planName: "Coffee", orderType: "custom_tip", }); expect(findTipCoffeePlan([byOrderType, byPlanId])).toBe(byPlanId); }); it("falls back to the tip coffee order type", () => { const plan = makePlan({ planId: "legacy_coffee", orderType: "tip_coffee", }); expect(findTipCoffeePlan([makePlan({}), plan])).toBe(plan); }); it("formats USD prices with the product-style label", () => { expect(formatTipPrice(makePlan({ amountCents: 500, currency: "USD" }))).toBe( "US$ 5", ); }); it("treats guest and notLoggedIn as non-real login states", () => { expect(isRealLoginStatus("guest")).toBe(false); expect(isRealLoginStatus("notLoggedIn")).toBe(false); expect(isRealLoginStatus("facebook")).toBe(true); }); });