fix(payment): default nullable first recharge offer

This commit is contained in:
2026-07-02 15:48:06 +08:00
parent 0cfef6bf57
commit f6932357c6
2 changed files with 22 additions and 3 deletions
@@ -114,4 +114,22 @@ describe("PaymentPlansResponse", () => {
promotionType: "first_recharge_half_price",
});
});
it("defaults nullable first recharge offer metadata", () => {
const response = PaymentPlansResponse.from({
isFirstRecharge: true,
firstRechargeOffer: {
enabled: null,
type: null,
discountPercent: null,
},
plans: [],
});
expect(response.firstRechargeOffer).toEqual({
enabled: false,
type: "",
discountPercent: 0,
});
});
});
@@ -3,12 +3,13 @@
*/
import { z } from "zod";
import { booleanOrFalse, numberOrZero, stringOrEmpty } from "../nullable-defaults";
import { PaymentPlanSchema } from "./payment_plan";
export const FirstRechargeOfferSchema = z.object({
enabled: z.boolean(),
type: z.string(),
discountPercent: z.number(),
enabled: booleanOrFalse,
type: stringOrEmpty,
discountPercent: numberOrZero,
});
export const PaymentPlansResponseSchema = z.object({