Skip to content

Commit

Permalink
Unit test for the feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTail committed Jan 19, 2025
1 parent f4231d8 commit 90732f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/result-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const defaultResultHandler = new ResultHandler({
* */
export const arrayResultHandler = new ResultHandler({
positive: (output) => {
// Examples are taken for proxying: no validation needed for this
// Examples are taken for pulling down: no validation needed for this, no pulling up
const examples = getExamples({ schema: output, pullProps: false });
const responseSchema =
"shape" in output &&
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/common-helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,33 @@ describe("Common Helpers", () => {
]);
},
);
test.each([
{
schema: z.object({
a: z.string().example("one"),
b: z.number().example(1),
}),
pullProps: true,
expected: [{ a: "one", b: 1 }],
},
{
schema: z.object({ a: z.string().example("one") }),
pullProps: false,
expected: [],
},
{
schema: z
.object({ a: z.string().example("one"), b: z.number().example(1) })
.example({ a: "two", b: 2 }), // higher priority
pullProps: true,
expected: [{ a: "two", b: 2 }],
},
])(
"Feature #2324: should pull examples from object props %#",
({ schema, pullProps, expected }) => {
expect(getExamples({ schema, pullProps })).toEqual(expected);
},
);
});

describe("combinations()", () => {
Expand Down

0 comments on commit 90732f4

Please sign in to comment.