feat(payment): share payment method selector
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
PaymentPlanSchema,
|
||||
@@ -7,12 +7,9 @@ import {
|
||||
} from "@/data/schemas/payment";
|
||||
|
||||
import {
|
||||
canChooseSubscriptionPayChannel,
|
||||
findSelectedSubscriptionPlan,
|
||||
getDefaultPayChannelForCountryCode,
|
||||
getDefaultSubscriptionPlanId,
|
||||
getFirstRechargeOfferView,
|
||||
resolveSubscriptionPayChannel,
|
||||
toCoinsOfferPlanViews,
|
||||
toVipOfferPlanViews,
|
||||
} from "../subscription-screen.helpers";
|
||||
@@ -34,68 +31,6 @@ function makePlan(overrides: Partial<PaymentPlanInput>): PaymentPlan {
|
||||
}
|
||||
|
||||
describe("subscription screen helpers", () => {
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
it("defaults Philippines users to GCash and other countries to Stripe", () => {
|
||||
expect(getDefaultPayChannelForCountryCode("PH")).toBe("ezpay");
|
||||
expect(getDefaultPayChannelForCountryCode("ph")).toBe("ezpay");
|
||||
expect(getDefaultPayChannelForCountryCode("HK")).toBe("stripe");
|
||||
expect(getDefaultPayChannelForCountryCode("")).toBe("stripe");
|
||||
expect(getDefaultPayChannelForCountryCode(null)).toBe("stripe");
|
||||
});
|
||||
|
||||
it("only allows payment method switching for Philippines users in production", () => {
|
||||
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "production");
|
||||
|
||||
expect(canChooseSubscriptionPayChannel("PH")).toBe(true);
|
||||
expect(canChooseSubscriptionPayChannel("ph")).toBe(true);
|
||||
expect(canChooseSubscriptionPayChannel("HK")).toBe(false);
|
||||
expect(canChooseSubscriptionPayChannel(null)).toBe(false);
|
||||
});
|
||||
|
||||
it("allows payment method switching in non-production", () => {
|
||||
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "test");
|
||||
|
||||
expect(canChooseSubscriptionPayChannel("HK")).toBe(true);
|
||||
expect(canChooseSubscriptionPayChannel(null)).toBe(true);
|
||||
});
|
||||
|
||||
it("resolves subscription pay channel by country in production", () => {
|
||||
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "production");
|
||||
|
||||
expect(
|
||||
resolveSubscriptionPayChannel({
|
||||
countryCode: "PH",
|
||||
requestedPayChannel: null,
|
||||
}),
|
||||
).toBe("ezpay");
|
||||
expect(
|
||||
resolveSubscriptionPayChannel({
|
||||
countryCode: "PH",
|
||||
requestedPayChannel: "stripe",
|
||||
}),
|
||||
).toBe("stripe");
|
||||
expect(
|
||||
resolveSubscriptionPayChannel({
|
||||
countryCode: "HK",
|
||||
requestedPayChannel: "ezpay",
|
||||
}),
|
||||
).toBe("stripe");
|
||||
});
|
||||
|
||||
it("keeps requested pay channel in non-production", () => {
|
||||
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "test");
|
||||
|
||||
expect(
|
||||
resolveSubscriptionPayChannel({
|
||||
countryCode: "HK",
|
||||
requestedPayChannel: "ezpay",
|
||||
}),
|
||||
).toBe("ezpay");
|
||||
});
|
||||
|
||||
it("maps at most three VIP plans and all coin plans", () => {
|
||||
const plans = [
|
||||
makePlan({ planId: "vip_monthly", planName: "Monthly" }),
|
||||
|
||||
Reference in New Issue
Block a user