fix(subscription): preserve vip original price
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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<PaymentPlansResponse | null>(
|
||||
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<PaymentPlansResponse>((resolve) => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user