test(chat): add test for defaulting nullable credit fields to zero
This commit is contained in:
@@ -79,4 +79,29 @@ describe("UnlockPrivateResponse", () => {
|
|||||||
|
|
||||||
expect(response.content).toBe("");
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { stringOrEmpty } from "../nullable-defaults";
|
import { numberOrZero, stringOrEmpty } from "../nullable-defaults";
|
||||||
import { ChatLockDetailSchema } from "./chat_payloads";
|
import { ChatLockDetailSchema } from "./chat_payloads";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,10 +12,10 @@ export const UnlockPrivateResponseSchema = z.object({
|
|||||||
unlocked: z.boolean(),
|
unlocked: z.boolean(),
|
||||||
content: stringOrEmpty,
|
content: stringOrEmpty,
|
||||||
reason: UnlockPrivateReasonSchema,
|
reason: UnlockPrivateReasonSchema,
|
||||||
creditBalance: z.number().default(0),
|
creditBalance: numberOrZero,
|
||||||
creditsCharged: z.number().default(0),
|
creditsCharged: numberOrZero,
|
||||||
requiredCredits: z.number().default(0),
|
requiredCredits: numberOrZero,
|
||||||
shortfallCredits: z.number().default(0),
|
shortfallCredits: numberOrZero,
|
||||||
lockDetail: ChatLockDetailSchema,
|
lockDetail: ChatLockDetailSchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user