From f6932357c61887edb9262a02d96981503b76166a Mon Sep 17 00:00:00 2001 From: chenhang Date: Thu, 2 Jul 2026 15:48:06 +0800 Subject: [PATCH] fix(payment): default nullable first recharge offer --- .../dto/payment/__tests__/payment_plan.test.ts | 18 ++++++++++++++++++ .../schemas/payment/payment_plans_response.ts | 7 ++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/data/dto/payment/__tests__/payment_plan.test.ts b/src/data/dto/payment/__tests__/payment_plan.test.ts index b46a4819..ec94c9fb 100644 --- a/src/data/dto/payment/__tests__/payment_plan.test.ts +++ b/src/data/dto/payment/__tests__/payment_plan.test.ts @@ -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, + }); + }); }); diff --git a/src/data/schemas/payment/payment_plans_response.ts b/src/data/schemas/payment/payment_plans_response.ts index d685abed..d0c87242 100644 --- a/src/data/schemas/payment/payment_plans_response.ts +++ b/src/data/schemas/payment/payment_plans_response.ts @@ -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({