feat(tip): support tiered coffee gifts
This commit is contained in:
@@ -29,34 +29,51 @@ function makePlan(input: Partial<PaymentPlanInput>): PaymentPlan {
|
||||
}
|
||||
|
||||
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({
|
||||
it("uses the legacy tip coffee plan only for small", () => {
|
||||
const plan = makePlan({
|
||||
planId: "tip_coffee",
|
||||
planName: "Coffee",
|
||||
orderType: "custom_tip",
|
||||
});
|
||||
|
||||
expect(findTipCoffeePlan([byOrderType, byPlanId])).toBe(byPlanId);
|
||||
expect(findTipCoffeePlan([makePlan({}), plan], "small")).toBe(plan);
|
||||
expect(findTipCoffeePlan([plan], "medium")).toBeNull();
|
||||
});
|
||||
|
||||
it("falls back to the tip coffee order type", () => {
|
||||
const plan = makePlan({
|
||||
planId: "legacy_coffee",
|
||||
orderType: "tip_coffee",
|
||||
it("matches medium and large coffee plans independently", () => {
|
||||
const medium = makePlan({
|
||||
planId: "tip_coffee_medium",
|
||||
orderType: "tip_coffee_medium",
|
||||
amountCents: 999,
|
||||
});
|
||||
const large = makePlan({
|
||||
planId: "tip_coffee_large",
|
||||
orderType: "tip_coffee_large",
|
||||
amountCents: 1999,
|
||||
});
|
||||
|
||||
expect(findTipCoffeePlan([makePlan({}), plan])).toBe(plan);
|
||||
expect(findTipCoffeePlan([large, medium], "medium")).toBe(medium);
|
||||
expect(findTipCoffeePlan([medium, large], "large")).toBe(large);
|
||||
});
|
||||
|
||||
it("does not infer a coffee tier from order type or amount", () => {
|
||||
const ambiguousPlan = makePlan({
|
||||
planId: "legacy_coffee",
|
||||
orderType: "tip_coffee_medium",
|
||||
amountCents: 999,
|
||||
});
|
||||
|
||||
expect(findTipCoffeePlan([ambiguousPlan], "medium")).toBeNull();
|
||||
});
|
||||
|
||||
it("formats USD prices with the product-style label", () => {
|
||||
expect(formatTipPrice(makePlan({ amountCents: 500, currency: "USD" }))).toBe(
|
||||
"US$ 5",
|
||||
);
|
||||
expect(
|
||||
formatTipPrice(makePlan({ amountCents: 500, currency: "USD" }), "small"),
|
||||
).toBe("US$ 5");
|
||||
});
|
||||
|
||||
it("uses the selected coffee price when its plan is unavailable", () => {
|
||||
expect(formatTipPrice(null, "small")).toBe("US$ 4.99");
|
||||
expect(formatTipPrice(null, "medium")).toBe("US$ 9.99");
|
||||
expect(formatTipPrice(null, "large")).toBe("US$ 19.99");
|
||||
});
|
||||
|
||||
it("treats guest and notLoggedIn as non-real login states", () => {
|
||||
|
||||
Reference in New Issue
Block a user