Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions packages/validation/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,41 @@ describe("search threshold schemas", () => {

expect(searchSchemas).not.toContain(".transform(Number)")
expect(searchSchemas).not.toContain("v === undefined || (v >= 0 && v <= 1)")
expect(searchSchemas).not.toContain(
"v === undefined || (v > 0 && v <= 100)",
)
})

it.each([
1, 50, 100,
])("accepts in-range limit value %p on search schemas", (limit) => {
expect(SearchRequestSchema.parse({ q: "memory", limit }).limit).toBe(limit)
expect(Searchv4RequestSchema.parse({ q: "memory", limit }).limit).toBe(
limit,
)
})

it("preserves the limit default of 10 on search schemas", () => {
expect(SearchRequestSchema.parse({ q: "memory" }).limit).toBe(10)
expect(Searchv4RequestSchema.parse({ q: "memory" }).limit).toBe(10)
})

it("still rejects a limit above 100 on search schemas", () => {
expect(
SearchRequestSchema.safeParse({ q: "memory", limit: 101 }).success,
).toBe(false)
expect(
Searchv4RequestSchema.safeParse({ q: "memory", limit: 101 }).success,
).toBe(false)
})

it("still rejects a non-positive limit on search schemas", () => {
expect(
SearchRequestSchema.safeParse({ q: "memory", limit: 0 }).success,
).toBe(false)
expect(
Searchv4RequestSchema.safeParse({ q: "memory", limit: -1 }).success,
).toBe(false)
})

it("preserves threshold defaults", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/validation/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ export const SearchRequestSchema = z.object({
.positive()
.optional()
.default(10)
.refine((v) => v === undefined || (v > 0 && v <= 100), {
.refine((v) => v <= 100, {
message: "limit must be between 1 and 100",
params: {
max: 100,
Expand Down Expand Up @@ -527,7 +527,7 @@ export const Searchv4RequestSchema = z.object({
.positive()
.optional()
.default(10)
.refine((v) => v === undefined || (v > 0 && v <= 100), {
.refine((v) => v <= 100, {
message: "limit must be between 1 and 100",
params: {
max: 100,
Expand Down