test(chat): add test for defaulting nullable content to an empty string

This commit is contained in:
2026-06-30 19:29:41 +08:00
parent ed109f25a0
commit a105820b88
2 changed files with 20 additions and 1 deletions
@@ -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("");
});
});
@@ -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),