feat(subscription): load vip and credit plans from api

This commit is contained in:
2026-06-26 15:09:27 +08:00
parent abf6d5ae88
commit 49b67064f7
15 changed files with 748 additions and 50 deletions
@@ -26,6 +26,7 @@ const monthlyPlan = {
original_amount_cents: null,
daily_price_cents: 33,
currency: "usd",
pricing_tier: "T1",
vip_days: 30,
dol_amount: null,
};
@@ -38,10 +39,24 @@ const lifetimePlan = {
original_amount_cents: null,
daily_price_cents: null,
currency: "usd",
pricing_tier: "T1",
vip_days: null,
dol_amount: null,
};
const creditPlan = {
plan_id: "credit_1000",
plan_name: "1000 Credits",
order_type: "credit_recharge",
amount_cents: 990,
original_amount_cents: null,
daily_price_cents: null,
currency: "usd",
pricing_tier: "T1",
vip_days: null,
dol_amount: 1000,
};
function createTestPaymentMachine(
overrides: Partial<{
createOrderSpy: CreateOrderSpy;
@@ -218,4 +233,19 @@ describe("paymentMachine", () => {
actor.stop();
});
it("disables auto renew for credit recharge plans", async () => {
const actor = createActor(createTestPaymentMachine()).start();
actor.send({ type: "PaymentInit" });
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
actor.send({ type: "PaymentPlanSelected", planId: creditPlan.plan_id });
const context = actor.getSnapshot().context;
expect(context.selectedPlanId).toBe("credit_1000");
expect(context.autoRenew).toBe(false);
actor.stop();
});
});