Skip to content

Commit 20fbf4c

Browse files
committed
refactor(api): remove redundant createJobFetchTypeSchema union
The union of jobTypeSchema and createJobFetchTypeSchema was a no-op since JOB_COMMANDS already includes fetch-one, fetch-ready, and fetch-all. Remove both derived schemas and use jobTypeSchema as the single source of truth. Update tests to expect INVALID_ENUM_VALUE (more precise) instead of VALIDATION_ERROR for invalid type field inputs.
1 parent f996c3d commit 20fbf4c

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

api-server/endpoint-schema-validation.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ describe("Endpoint Schema Validation - POST /jobs", () => {
157157

158158
if (result.success === false) {
159159
const formatted = formatZodError(result.error, "req_test_123");
160-
validateZodErrorFormat(formatted, ErrorCode.VALIDATION_ERROR);
160+
validateZodErrorFormat(formatted, ErrorCode.INVALID_ENUM_VALUE);
161161
expect(formatted.message).toBeDefined();
162162
}
163163
});
@@ -170,7 +170,7 @@ describe("Endpoint Schema Validation - POST /jobs", () => {
170170

171171
if (result.success === false) {
172172
const formatted = formatZodError(result.error, "req_test_456");
173-
validateZodErrorFormat(formatted, ErrorCode.VALIDATION_ERROR);
173+
validateZodErrorFormat(formatted, ErrorCode.INVALID_ENUM_VALUE);
174174
expect(formatted.message).toBeDefined();
175175
}
176176
});
@@ -183,7 +183,7 @@ describe("Endpoint Schema Validation - POST /jobs", () => {
183183

184184
if (result.success === false) {
185185
const formatted = formatZodError(result.error, "req_test_789");
186-
validateZodErrorFormat(formatted, ErrorCode.VALIDATION_ERROR);
186+
validateZodErrorFormat(formatted, ErrorCode.INVALID_ENUM_VALUE);
187187
// Zod reports the error - just verify it's formatted
188188
expect(formatted.message).toBeDefined();
189189
}
@@ -368,7 +368,7 @@ describe("Endpoint Schema Validation - GET /jobs", () => {
368368

369369
if (result.success === false) {
370370
const formatted = formatZodError(result.error, "req_test_type");
371-
validateZodErrorFormat(formatted, ErrorCode.VALIDATION_ERROR);
371+
validateZodErrorFormat(formatted, ErrorCode.INVALID_ENUM_VALUE);
372372
expect(formatted.message).toBeDefined();
373373
}
374374
});

api-server/validation-schemas.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe("Validation Schemas - Create Job Request", () => {
296296
const result = createJobRequestSchema.safeParse({});
297297
expect(result.success).toBe(false);
298298
if (!result.success && result.error) {
299-
expect(result.error.issues[0].message).toContain("Invalid input");
299+
expect(result.error.issues[0].message).toContain("Invalid option");
300300
}
301301
});
302302

api-server/validation-schemas.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,6 @@ export const jobIdSchema = z
115115
* - Derived from JOB_COMMANDS keys (single source of truth)
116116
*/
117117
export const jobTypeSchema = z.enum(VALID_JOB_TYPES as [string, ...string[]]);
118-
export const createJobFetchTypeSchema = z.enum([
119-
"fetch-one",
120-
"fetch-ready",
121-
"fetch-all",
122-
]);
123-
export const createJobTypeSchema = z.union([
124-
jobTypeSchema,
125-
createJobFetchTypeSchema,
126-
]);
127118

128119
/**
129120
* Job status validation schema
@@ -165,7 +156,7 @@ export const jobOptionsSchema = z
165156
*/
166157
export const createJobRequestSchema = z
167158
.object({
168-
type: createJobTypeSchema,
159+
type: jobTypeSchema,
169160
options: jobOptionsSchema.optional(),
170161
})
171162
.superRefine((data, ctx) => {
@@ -191,7 +182,7 @@ export const createJobRequestSchema = z
191182
*/
192183
export const jobsQuerySchema = z.object({
193184
status: jobStatusSchema.optional(),
194-
type: createJobTypeSchema.optional(),
185+
type: jobTypeSchema.optional(),
195186
});
196187

197188
// =============================================================================
@@ -222,7 +213,7 @@ export const jobResultSchema = z.object({
222213
*/
223214
export const jobSchema = z.object({
224215
id: z.string(),
225-
type: createJobTypeSchema,
216+
type: jobTypeSchema,
226217
status: jobStatusSchema,
227218
createdAt: z.string().datetime(),
228219
startedAt: z.string().datetime().nullable(),

0 commit comments

Comments
 (0)