diff --git a/src/data/dto/chat/__tests__/unlock_private_response.test.ts b/src/data/dto/chat/__tests__/unlock_private_response.test.ts index d16ac68d..b9ad2fa7 100644 --- a/src/data/dto/chat/__tests__/unlock_private_response.test.ts +++ b/src/data/dto/chat/__tests__/unlock_private_response.test.ts @@ -79,4 +79,29 @@ describe("UnlockPrivateResponse", () => { expect(response.content).toBe(""); }); + + it("defaults nullable credit fields to zero", () => { + const response = UnlockPrivateResponse.from({ + unlocked: false, + content: "", + reason: "insufficient_balance", + creditBalance: null, + creditsCharged: null, + requiredCredits: null, + shortfallCredits: null, + lockDetail: { + locked: true, + showContent: false, + showUpgrade: true, + reason: "insufficient_balance", + hint: null, + detail: null, + }, + }); + + expect(response.creditBalance).toBe(0); + expect(response.creditsCharged).toBe(0); + expect(response.requiredCredits).toBe(0); + expect(response.shortfallCredits).toBe(0); + }); }); diff --git a/src/data/schemas/chat/unlock_private_response.ts b/src/data/schemas/chat/unlock_private_response.ts index d7c30210..08f74ab3 100644 --- a/src/data/schemas/chat/unlock_private_response.ts +++ b/src/data/schemas/chat/unlock_private_response.ts @@ -1,6 +1,6 @@ import { z } from "zod"; -import { stringOrEmpty } from "../nullable-defaults"; +import { numberOrZero, stringOrEmpty } from "../nullable-defaults"; import { ChatLockDetailSchema } from "./chat_payloads"; /** @@ -12,10 +12,10 @@ export const UnlockPrivateResponseSchema = z.object({ unlocked: z.boolean(), content: stringOrEmpty, reason: UnlockPrivateReasonSchema, - creditBalance: z.number().default(0), - creditsCharged: z.number().default(0), - requiredCredits: z.number().default(0), - shortfallCredits: z.number().default(0), + creditBalance: numberOrZero, + creditsCharged: numberOrZero, + requiredCredits: numberOrZero, + shortfallCredits: numberOrZero, lockDetail: ChatLockDetailSchema, });