92 lines
2.5 KiB
TypeScript
92 lines
2.5 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import {
|
|
BillingResponseSchema,
|
|
ConfirmCheckoutParamsSchema,
|
|
DomesticPaymentProvider,
|
|
} from "@autumn/shared";
|
|
|
|
describe("domestic payment action schema", () => {
|
|
test("accepts WeChat Native QR payment actions in billing responses", () => {
|
|
const result = BillingResponseSchema.safeParse({
|
|
customer_id: "cus_test",
|
|
payment_url: null,
|
|
required_action: {
|
|
code: "domestic_payment_required",
|
|
reason: "Customer must complete the WeChat payment.",
|
|
provider_action: {
|
|
provider: DomesticPaymentProvider.WeChatPay,
|
|
action: "qr_code",
|
|
code_url: "weixin://wxpay/bizpayurl?pr=test",
|
|
expires_at: 1_774_000_000_000,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
});
|
|
|
|
test("accepts Alipay redirect payment actions in billing responses", () => {
|
|
const result = BillingResponseSchema.safeParse({
|
|
customer_id: "cus_test",
|
|
payment_url: null,
|
|
required_action: {
|
|
code: "domestic_payment_required",
|
|
reason: "Customer must complete the Alipay payment.",
|
|
provider_action: {
|
|
provider: DomesticPaymentProvider.Alipay,
|
|
action: "redirect",
|
|
url: "https://openapi.alipay.com/gateway.do?biz_content=test",
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(result.success).toBe(true);
|
|
});
|
|
|
|
test("rejects provider actions with mismatched provider and action fields", () => {
|
|
const result = BillingResponseSchema.safeParse({
|
|
customer_id: "cus_test",
|
|
payment_url: null,
|
|
required_action: {
|
|
code: "domestic_payment_required",
|
|
reason: "Invalid provider action.",
|
|
provider_action: {
|
|
provider: DomesticPaymentProvider.Alipay,
|
|
action: "jsapi",
|
|
payload: {
|
|
appId: "wx_test",
|
|
timeStamp: "1774000000",
|
|
nonceStr: "nonce",
|
|
package: "prepay_id=wx201410272009395522657a690389285100",
|
|
signType: "RSA",
|
|
paySign: "signature",
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(result.success).toBe(false);
|
|
});
|
|
|
|
test("accepts WeChat Native payment selection in checkout confirm params", () => {
|
|
const parsed = ConfirmCheckoutParamsSchema.parse({
|
|
payment_provider: "wechatpay",
|
|
payment_method_type: "wechatpay_native",
|
|
});
|
|
|
|
expect(parsed).toEqual({
|
|
payment_provider: DomesticPaymentProvider.WeChatPay,
|
|
payment_method_type: "wechatpay_native",
|
|
});
|
|
});
|
|
|
|
test("rejects Alipay provider with WeChat Native method", () => {
|
|
expect(() =>
|
|
ConfirmCheckoutParamsSchema.parse({
|
|
payment_provider: "alipay",
|
|
payment_method_type: "wechatpay_native",
|
|
}),
|
|
).toThrow();
|
|
});
|
|
});
|