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 565520dc..d16ac68d 100644 --- a/src/data/dto/chat/__tests__/unlock_private_response.test.ts +++ b/src/data/dto/chat/__tests__/unlock_private_response.test.ts @@ -61,4 +61,22 @@ describe("UnlockPrivateResponse", () => { expect(response.shortfallCredits).toBe(5); expect(response.lockDetail.showUpgrade).toBe(true); }); + + it("defaults nullable content to an empty string", () => { + const response = UnlockPrivateResponse.from({ + unlocked: false, + content: null, + reason: "insufficient_balance", + lockDetail: { + locked: true, + showContent: false, + showUpgrade: true, + reason: "insufficient_balance", + hint: null, + detail: null, + }, + }); + + expect(response.content).toBe(""); + }); }); diff --git a/src/data/schemas/chat/unlock_private_response.ts b/src/data/schemas/chat/unlock_private_response.ts index d3e96b53..d7c30210 100644 --- a/src/data/schemas/chat/unlock_private_response.ts +++ b/src/data/schemas/chat/unlock_private_response.ts @@ -1,5 +1,6 @@ import { z } from "zod"; +import { stringOrEmpty } from "../nullable-defaults"; import { ChatLockDetailSchema } from "./chat_payloads"; /** @@ -9,7 +10,7 @@ export const UnlockPrivateReasonSchema = z.string().default(""); export const UnlockPrivateResponseSchema = z.object({ unlocked: z.boolean(), - content: z.string().default(""), + content: stringOrEmpty, reason: UnlockPrivateReasonSchema, creditBalance: z.number().default(0), creditsCharged: z.number().default(0),