Skip to content

Commit 4b20f15

Browse files
committed
add suggested tests from code review
1 parent 92e01dc commit 4b20f15

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

client/src/utils/__tests__/schemaUtils.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,36 @@ describe("generateDefaultValue", () => {
4747
expect(generateDefaultValue({ type: "object" })).toEqual({});
4848
});
4949

50+
test("generates undefined for nested optional object", () => {
51+
// When called WITH propertyName and parentSchema, and the property is NOT required,
52+
// nested optional objects should return undefined
53+
const parentSchema = {
54+
type: "object" as const,
55+
required: ["otherField"],
56+
properties: {
57+
optionalObject: { type: "object" as const },
58+
otherField: { type: "string" as const },
59+
},
60+
};
61+
expect(
62+
generateDefaultValue({ type: "object" }, "optionalObject", parentSchema),
63+
).toBe(undefined);
64+
});
65+
66+
test("generates empty object for root-level object with all optional properties", () => {
67+
// Root-level schema with properties but no required array
68+
// This is the exact scenario from PR #926 - elicitation with all optional fields
69+
const schema: JsonSchemaType = {
70+
type: "object",
71+
properties: {
72+
optionalField1: { type: "string" },
73+
optionalField2: { type: "number" },
74+
},
75+
// No required array - all fields are optional
76+
};
77+
expect(generateDefaultValue(schema)).toEqual({});
78+
});
79+
5080
test("generates default null for unknown types", () => {
5181
// @ts-expect-error Testing with invalid type
5282
expect(generateDefaultValue({ type: "unknown" })).toBe(undefined);

0 commit comments

Comments
 (0)