test(chat): add test for defaulting nullable content to an empty string
This commit is contained in:
@@ -61,4 +61,22 @@ describe("UnlockPrivateResponse", () => {
|
|||||||
expect(response.shortfallCredits).toBe(5);
|
expect(response.shortfallCredits).toBe(5);
|
||||||
expect(response.lockDetail.showUpgrade).toBe(true);
|
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 { z } from "zod";
|
||||||
|
|
||||||
|
import { stringOrEmpty } from "../nullable-defaults";
|
||||||
import { ChatLockDetailSchema } from "./chat_payloads";
|
import { ChatLockDetailSchema } from "./chat_payloads";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,7 +10,7 @@ export const UnlockPrivateReasonSchema = z.string().default("");
|
|||||||
|
|
||||||
export const UnlockPrivateResponseSchema = z.object({
|
export const UnlockPrivateResponseSchema = z.object({
|
||||||
unlocked: z.boolean(),
|
unlocked: z.boolean(),
|
||||||
content: z.string().default(""),
|
content: stringOrEmpty,
|
||||||
reason: UnlockPrivateReasonSchema,
|
reason: UnlockPrivateReasonSchema,
|
||||||
creditBalance: z.number().default(0),
|
creditBalance: z.number().default(0),
|
||||||
creditsCharged: z.number().default(0),
|
creditsCharged: z.number().default(0),
|
||||||
|
|||||||
Reference in New Issue
Block a user