diff --git a/src/app/subscription/__tests__/subscription-screen.helpers.test.ts b/src/app/subscription/__tests__/subscription-screen.helpers.test.ts index 8835c8f2..9e28537a 100644 --- a/src/app/subscription/__tests__/subscription-screen.helpers.test.ts +++ b/src/app/subscription/__tests__/subscription-screen.helpers.test.ts @@ -190,6 +190,26 @@ describe("subscription screen helpers", () => { ).toBeNull(); }); + it("maps normal VIP original price outside first recharge activity", () => { + expect( + toVipOfferPlanViews([ + makePlan({ + planId: "vip_monthly", + amountCents: 1990, + originalAmountCents: 2499, + isFirstRechargeOffer: false, + }), + ]), + ).toMatchObject([ + { + id: "vip_monthly", + price: "19.9", + originalPrice: "24.99", + isFirstRechargeOffer: false, + }, + ]); + }); + it("selects the first VIP plan by default when VIP can be purchased", () => { expect( getDefaultSubscriptionPlanId({ diff --git a/src/stores/payment/__tests__/payment-machine.test.ts b/src/stores/payment/__tests__/payment-machine.test.ts index 032c0e16..f519e8e8 100644 --- a/src/stores/payment/__tests__/payment-machine.test.ts +++ b/src/stores/payment/__tests__/payment-machine.test.ts @@ -230,7 +230,7 @@ describe("paymentMachine", () => { expect(context.isFirstRecharge).toBe(false); expect(context.plans[0]).toMatchObject({ amountCents: 1990, - originalAmountCents: null, + originalAmountCents: 1990, isFirstRechargeOffer: false, firstRechargeDiscountPercent: null, promotionType: null, @@ -239,6 +239,44 @@ describe("paymentMachine", () => { actor.stop(); }); + it("preserves normal VIP original price outside first recharge activity", async () => { + const actor = createActor( + paymentMachine.provide({ + actors: { + loadCachedPlans: fromPromise( + async () => null, + ), + refreshPlans: fromPromise(async () => + PaymentPlansResponse.from({ + isFirstRecharge: false, + plans: [ + { + ...monthlyPlan, + amountCents: 1990, + originalAmountCents: 2499, + isFirstRechargeOffer: false, + firstRechargeDiscountPercent: null, + promotionType: null, + }, + ], + }), + ), + }, + }), + ).start(); + + actor.send({ type: "PaymentInit" }); + await waitFor(actor, (snapshot) => snapshot.matches("ready")); + + expect(actor.getSnapshot().context.plans[0]).toMatchObject({ + amountCents: 1990, + originalAmountCents: 2499, + isFirstRechargeOffer: false, + }); + + actor.stop(); + }); + it("hydrates cached plans before refreshing with network plans", async () => { let resolveRefresh!: (value: PaymentPlansResponse) => void; const refreshPlansPromise = new Promise((resolve) => { diff --git a/src/stores/payment/payment-machine.helpers.ts b/src/stores/payment/payment-machine.helpers.ts index f69388c9..7f435d88 100644 --- a/src/stores/payment/payment-machine.helpers.ts +++ b/src/stores/payment/payment-machine.helpers.ts @@ -127,11 +127,20 @@ export function normalizeFirstRechargePlans( } export function consumeFirstRechargePlan(plan: PaymentPlan): PaymentPlan { + if (!plan.isFirstRechargeOffer) { + return PaymentPlan.from({ + ...plan.toJson(), + isFirstRechargeOffer: false, + firstRechargeDiscountPercent: null, + promotionType: null, + }); + } + const originalAmountCents = plan.originalAmountCents; return PaymentPlan.from({ ...plan.toJson(), amountCents: originalAmountCents ?? plan.amountCents, - originalAmountCents: null, + originalAmountCents: originalAmountCents ?? plan.originalAmountCents, isFirstRechargeOffer: false, firstRechargeDiscountPercent: null, promotionType: null,