66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import { getDefaultPayChannelForCountryCode } from "../default_pay_channel";
|
|
import {
|
|
canChoosePayChannel,
|
|
getPaymentMethodConfig,
|
|
resolvePayChannel,
|
|
} from "../payment_method";
|
|
|
|
describe("payment method rules", () => {
|
|
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(null)).toBe("stripe");
|
|
});
|
|
|
|
it("only allows Philippines users to choose in production", () => {
|
|
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "production");
|
|
|
|
expect(canChoosePayChannel("PH")).toBe(true);
|
|
expect(canChoosePayChannel("ph")).toBe(true);
|
|
expect(canChoosePayChannel("HK")).toBe(false);
|
|
expect(canChoosePayChannel(null)).toBe(false);
|
|
expect(
|
|
getPaymentMethodConfig({
|
|
countryCode: null,
|
|
requestedPayChannel: "ezpay",
|
|
}),
|
|
).toEqual({
|
|
canChoosePaymentMethod: false,
|
|
initialPayChannel: "stripe",
|
|
});
|
|
});
|
|
|
|
it("resolves requested and default channels for Philippines", () => {
|
|
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "production");
|
|
|
|
expect(
|
|
resolvePayChannel({ countryCode: "PH", requestedPayChannel: null }),
|
|
).toBe("ezpay");
|
|
expect(
|
|
resolvePayChannel({
|
|
countryCode: "PH",
|
|
requestedPayChannel: "stripe",
|
|
}),
|
|
).toBe("stripe");
|
|
});
|
|
|
|
it("allows every user and keeps the requested channel outside production", () => {
|
|
vi.stubEnv("NEXT_PUBLIC_APP_ENV", "test");
|
|
|
|
expect(canChoosePayChannel(null)).toBe(true);
|
|
expect(
|
|
resolvePayChannel({
|
|
countryCode: "HK",
|
|
requestedPayChannel: "ezpay",
|
|
}),
|
|
).toBe("ezpay");
|
|
});
|
|
});
|