Skip to content

Commit c6fc1cd

Browse files
authored
Merge pull request #6042 from bcgov/renovate/zod-4.x
fix(deps): update dependency zod to v4
2 parents 2b82a01 + 1f022f2 commit c6fc1cd

File tree

15 files changed

+126
-155
lines changed

15 files changed

+126
-155
lines changed

app/app/api/private-cloud/products/[licencePlate]/comments/_operations/create.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ describe('Create Private Cloud Comment - Validations', () => {
8484
expect(response.status).toBe(400);
8585
expect(responseBody.success).toBe(false);
8686
expect(responseBody.message).toBe('Bad Request');
87-
expect(responseBody.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'text')).not.toBeUndefined();
87+
const issues = JSON.parse(responseBody.error.message);
88+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'text')).not.toBeUndefined();
8889
});
8990

9091
it('should fail to submit a create comment request due to missing projectId and requestId', async () => {
@@ -102,8 +103,9 @@ describe('Create Private Cloud Comment - Validations', () => {
102103
expect(response.status).toBe(400);
103104
expect(responseBody.success).toBe(false);
104105
expect(responseBody.message).toBe('Bad Request');
106+
const issues = JSON.parse(responseBody.error.message);
105107
expect(
106-
responseBody.error.issues.find((iss: { path: string[] }) => ['projectId', 'requestId'].includes(iss.path[0])),
108+
issues.find((iss: { path: string[] }) => ['projectId', 'requestId'].includes(iss.path[0])),
107109
).not.toBeUndefined();
108110
});
109111

app/app/api/private-cloud/products/_operations/create.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ describe('Create Private Cloud Request - Validations', () => {
129129
const resData = await response.json();
130130
expect(resData.success).toBe(false);
131131
expect(resData.message).toBe('Bad Request');
132-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'name')).not.toBeUndefined();
132+
const issues = JSON.parse(resData.error.message);
133+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'name')).not.toBeUndefined();
133134
});
134135

135136
it('should fail to submit a create request due to an invalid description property', async () => {
@@ -144,7 +145,8 @@ describe('Create Private Cloud Request - Validations', () => {
144145
const resData = await response.json();
145146
expect(resData.success).toBe(false);
146147
expect(resData.message).toBe('Bad Request');
147-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'description')).not.toBeUndefined();
148+
const issues = JSON.parse(resData.error.message);
149+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'description')).not.toBeUndefined();
148150
});
149151

150152
it('should fail to submit a create request due to an invalid cluster property', async () => {
@@ -159,7 +161,8 @@ describe('Create Private Cloud Request - Validations', () => {
159161
const resData = await response.json();
160162
expect(resData.success).toBe(false);
161163
expect(resData.message).toBe('Bad Request');
162-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'cluster')).not.toBeUndefined();
164+
const issues = JSON.parse(resData.error.message);
165+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'cluster')).not.toBeUndefined();
163166
});
164167

165168
it('should fail to submit a create request due to an invalid ministry property', async () => {
@@ -174,7 +177,8 @@ describe('Create Private Cloud Request - Validations', () => {
174177
const resData = await response.json();
175178
expect(resData.success).toBe(false);
176179
expect(resData.message).toBe('Bad Request');
177-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'ministry')).not.toBeUndefined();
180+
const issues = JSON.parse(resData.error.message);
181+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'ministry')).not.toBeUndefined();
178182
});
179183

180184
it('should fail to submit a create request due to an invalid projectOwner property', async () => {
@@ -189,9 +193,8 @@ describe('Create Private Cloud Request - Validations', () => {
189193
const resData = await response.json();
190194
expect(resData.success).toBe(false);
191195
expect(resData.message).toBe('Bad Request');
192-
expect(
193-
resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'projectOwnerId'),
194-
).not.toBeUndefined();
196+
const issues = JSON.parse(resData.error.message);
197+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'projectOwnerId')).not.toBeUndefined();
195198
});
196199

197200
it('should fail to submit a create request due to an invalid primaryTechnicalLead property', async () => {
@@ -206,9 +209,8 @@ describe('Create Private Cloud Request - Validations', () => {
206209
const resData = await response.json();
207210
expect(resData.success).toBe(false);
208211
expect(resData.message).toBe('Bad Request');
209-
expect(
210-
resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'primaryTechnicalLeadId'),
211-
).not.toBeUndefined();
212+
const issues = JSON.parse(resData.error.message);
213+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'primaryTechnicalLeadId')).not.toBeUndefined();
212214
});
213215

214216
it('should successfully create a request without an secondaryTechnicalLead property', async () => {

app/app/api/private-cloud/products/_operations/update.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ describe('Update Private Cloud Product - Validations', () => {
163163
const resData = await response.json();
164164
expect(resData.success).toBe(false);
165165
expect(resData.message).toBe('Bad Request');
166-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'name')).not.toBeUndefined();
166+
const issues = JSON.parse(resData.error.message);
167+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'name')).not.toBeUndefined();
167168
});
168169

169170
it('should fail to submit a update request due to an invalid description property', async () => {
@@ -176,7 +177,8 @@ describe('Update Private Cloud Product - Validations', () => {
176177
const resData = await response.json();
177178
expect(resData.success).toBe(false);
178179
expect(resData.message).toBe('Bad Request');
179-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'description')).not.toBeUndefined();
180+
const issues = JSON.parse(resData.error.message);
181+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'description')).not.toBeUndefined();
180182
});
181183

182184
it('should fail to submit a update request due to an invalid cluster property', async () => {
@@ -189,7 +191,8 @@ describe('Update Private Cloud Product - Validations', () => {
189191
const resData = await response.json();
190192
expect(resData.success).toBe(false);
191193
expect(resData.message).toBe('Bad Request');
192-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'cluster')).not.toBeUndefined();
194+
const issues = JSON.parse(resData.error.message);
195+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'cluster')).not.toBeUndefined();
193196
});
194197

195198
it('should ignore the cluster change on a new update request', async () => {
@@ -228,7 +231,8 @@ describe('Update Private Cloud Product - Validations', () => {
228231
const resData = await response.json();
229232
expect(resData.success).toBe(false);
230233
expect(resData.message).toBe('Bad Request');
231-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'ministry')).not.toBeUndefined();
234+
const issues = JSON.parse(resData.error.message);
235+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'ministry')).not.toBeUndefined();
232236
});
233237

234238
it('should fail to submit a update request due to an invalid projectOwner property', async () => {
@@ -241,9 +245,8 @@ describe('Update Private Cloud Product - Validations', () => {
241245
const resData = await response.json();
242246
expect(resData.success).toBe(false);
243247
expect(resData.message).toBe('Bad Request');
244-
expect(
245-
resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'projectOwnerId'),
246-
).not.toBeUndefined();
248+
const issues = JSON.parse(resData.error.message);
249+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'projectOwnerId')).not.toBeUndefined();
247250
});
248251

249252
it('should fail to submit a update request due to an invalid primaryTechnicalLead property', async () => {
@@ -256,9 +259,8 @@ describe('Update Private Cloud Product - Validations', () => {
256259
const resData = await response.json();
257260
expect(resData.success).toBe(false);
258261
expect(resData.message).toBe('Bad Request');
259-
expect(
260-
resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'primaryTechnicalLeadId'),
261-
).not.toBeUndefined();
262+
const issues = JSON.parse(resData.error.message);
263+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'primaryTechnicalLeadId')).not.toBeUndefined();
262264
});
263265

264266
it('should successfully create a request without an secondaryTechnicalLead property', async () => {

app/app/api/public-cloud/products/_operations/create.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ describe('Create Public Cloud Request - Validations', () => {
133133
const resData = await response.json();
134134
expect(resData.success).toBe(false);
135135
expect(resData.message).toBe('Bad Request');
136-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'name')).not.toBeUndefined();
136+
const issues = JSON.parse(resData.error.message);
137+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'name')).not.toBeUndefined();
137138
});
138139

139140
it('should fail to submit a create request due to an invalid description property', async () => {
@@ -148,7 +149,8 @@ describe('Create Public Cloud Request - Validations', () => {
148149
const resData = await response.json();
149150
expect(resData.success).toBe(false);
150151
expect(resData.message).toBe('Bad Request');
151-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'description')).not.toBeUndefined();
152+
const issues = JSON.parse(resData.error.message);
153+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'description')).not.toBeUndefined();
152154
});
153155

154156
it('should fail to submit a create request due to an invalid provider property', async () => {
@@ -163,7 +165,8 @@ describe('Create Public Cloud Request - Validations', () => {
163165
const resData = await response.json();
164166
expect(resData.success).toBe(false);
165167
expect(resData.message).toBe('Bad Request');
166-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'provider')).not.toBeUndefined();
168+
const issues = JSON.parse(resData.error.message);
169+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'provider')).not.toBeUndefined();
167170
});
168171

169172
it('should fail to submit a create request due to an invalid ministry property', async () => {
@@ -178,7 +181,8 @@ describe('Create Public Cloud Request - Validations', () => {
178181
const resData = await response.json();
179182
expect(resData.success).toBe(false);
180183
expect(resData.message).toBe('Bad Request');
181-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'ministry')).not.toBeUndefined();
184+
const issues = JSON.parse(resData.error.message);
185+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'ministry')).not.toBeUndefined();
182186
});
183187

184188
it('should fail to submit a create request due to an invalid projectOwner property', async () => {
@@ -193,9 +197,8 @@ describe('Create Public Cloud Request - Validations', () => {
193197
const resData = await response.json();
194198
expect(resData.success).toBe(false);
195199
expect(resData.message).toBe('Bad Request');
196-
expect(
197-
resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'projectOwnerId'),
198-
).not.toBeUndefined();
200+
const issues = JSON.parse(resData.error.message);
201+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'projectOwnerId')).not.toBeUndefined();
199202
});
200203

201204
it('should fail to submit a create request due to an invalid primaryTechnicalLead property', async () => {
@@ -210,9 +213,8 @@ describe('Create Public Cloud Request - Validations', () => {
210213
const resData = await response.json();
211214
expect(resData.success).toBe(false);
212215
expect(resData.message).toBe('Bad Request');
213-
expect(
214-
resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'primaryTechnicalLeadId'),
215-
).not.toBeUndefined();
216+
const issues = JSON.parse(resData.error.message);
217+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'primaryTechnicalLeadId')).not.toBeUndefined();
216218
});
217219

218220
it('should successfully create a request without an secondaryTechnicalLead property', async () => {

app/app/api/public-cloud/products/_operations/update.test.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ describe('Update Public Cloud Product - Validations', () => {
190190
const resData = await response.json();
191191
expect(resData.success).toBe(false);
192192
expect(resData.message).toBe('Bad Request');
193-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'name')).not.toBeUndefined();
193+
const issues = JSON.parse(resData.error.message);
194+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'name')).not.toBeUndefined();
194195
});
195196

196197
it('should fail to submit a update request due to an invalid description property', async () => {
@@ -203,7 +204,8 @@ describe('Update Public Cloud Product - Validations', () => {
203204
const resData = await response.json();
204205
expect(resData.success).toBe(false);
205206
expect(resData.message).toBe('Bad Request');
206-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'description')).not.toBeUndefined();
207+
const issues = JSON.parse(resData.error.message);
208+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'description')).not.toBeUndefined();
207209
});
208210

209211
it('should fail to submit a update request due to an invalid provider property', async () => {
@@ -216,7 +218,8 @@ describe('Update Public Cloud Product - Validations', () => {
216218
const resData = await response.json();
217219
expect(resData.success).toBe(false);
218220
expect(resData.message).toBe('Bad Request');
219-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'provider')).not.toBeUndefined();
221+
const issues = JSON.parse(resData.error.message);
222+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'provider')).not.toBeUndefined();
220223
});
221224

222225
it('should ignore the provider change on a new update request', async () => {
@@ -243,7 +246,8 @@ describe('Update Public Cloud Product - Validations', () => {
243246
const resData = await response.json();
244247
expect(resData.success).toBe(false);
245248
expect(resData.message).toBe('Bad Request');
246-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'ministry')).not.toBeUndefined();
249+
const issues = JSON.parse(resData.error.message);
250+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'ministry')).not.toBeUndefined();
247251
});
248252

249253
it('should fail to submit a update request due to an invalid projectOwner property', async () => {
@@ -255,9 +259,8 @@ describe('Update Public Cloud Product - Validations', () => {
255259
const resData = await response.json();
256260
expect(resData.success).toBe(false);
257261
expect(resData.message).toBe('Bad Request');
258-
expect(
259-
resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'projectOwnerId'),
260-
).not.toBeUndefined();
262+
const issues = JSON.parse(resData.error.message);
263+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'projectOwnerId')).not.toBeUndefined();
261264
});
262265

263266
it('should fail to submit a update request due to an invalid primaryTechnicalLead property', async () => {
@@ -269,9 +272,8 @@ describe('Update Public Cloud Product - Validations', () => {
269272
const resData = await response.json();
270273
expect(resData.success).toBe(false);
271274
expect(resData.message).toBe('Bad Request');
272-
expect(
273-
resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'primaryTechnicalLeadId'),
274-
).not.toBeUndefined();
275+
const issues = JSON.parse(resData.error.message);
276+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'primaryTechnicalLeadId')).not.toBeUndefined();
275277
});
276278

277279
it('should successfully provision the request', async () => {

app/app/api/v1/private-cloud/products/route.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ describe('API: List Private Cloud Products - Validations', () => {
252252
const resData = await response.json();
253253
expect(resData.success).toBe(false);
254254
expect(resData.message).toBe('Bad Request');
255-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'ministry')).not.toBeUndefined();
255+
const issues = JSON.parse(resData.error.message);
256+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'ministry')).not.toBeUndefined();
256257
});
257258
});

app/app/api/v1/public-cloud/products/route.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ describe('API: List Public Cloud Products - Validations', () => {
286286
const resData = await response.json();
287287
expect(resData.success).toBe(false);
288288
expect(resData.message).toBe('Bad Request');
289-
expect(resData.error.issues.find((iss: { path: string[] }) => iss.path[0] === 'ministry')).not.toBeUndefined();
289+
const issues = JSON.parse(resData.error.message);
290+
expect(issues.find((iss: { path: string[] }) => iss.path[0] === 'ministry')).not.toBeUndefined();
290291
});
291292
});

app/core/api-handler.ts

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,27 @@ interface RouteProps<TPathParams, TQueryParams, TBody> {
4343
}
4444

4545
function createApiHandler<
46-
TPathParams extends ZodType<any, any>,
47-
TQueryParams extends ZodType<any, any>,
48-
TBody extends ZodType<any, any>,
46+
TPathParams extends ZodType<any, any> = ZodType<z.ZodTypeAny>,
47+
TQueryParams extends ZodType<any, any> = ZodType<z.ZodTypeAny>,
48+
TBody extends ZodType<any, any> = ZodType<z.ZodTypeAny>,
4949
>({
5050
roles,
5151
permissions,
5252
validations,
5353
keycloakOauth2,
5454
useServiceAccount,
5555
}: HandlerProps<TPathParams, TQueryParams, TBody>) {
56-
const {
57-
pathParams: pathParamVal = z.object({}),
58-
queryParams: queryParamVal = z.object({}),
59-
body: bodyVal = z.object({}),
60-
} = validations ?? {};
61-
let pathParams: TypeOf<typeof pathParamVal> | null = null;
62-
let queryParams: TypeOf<typeof queryParamVal> | null = null;
63-
let body: TypeOf<typeof bodyVal> | null = null;
64-
6556
return function apiHandler(
6657
fn: (
6758
props: RouteProps<TypeOf<TPathParams>, TypeOf<TQueryParams>, TypeOf<TBody>>,
6859
) => Promise<NextResponse<unknown> | Response>,
6960
) {
7061
return async function (req: NextRequest, context: any) {
7162
const { params: paramsProm } = context ?? {};
72-
const params = paramsProm && (await paramsProm);
73-
63+
const params = (paramsProm && (await paramsProm)) ?? {};
64+
let pathParams: TypeOf<TPathParams> = {} as TypeOf<TPathParams>;
65+
let queryParams: TypeOf<TQueryParams> = {} as TypeOf<TQueryParams>;
66+
let body: TypeOf<TBody> = {} as TypeOf<TBody>;
7467
try {
7568
let session = await getServerSession(authOptions);
7669
let jwtData!: any;
@@ -183,7 +176,7 @@ function createApiHandler<
183176

184177
// Parse & validate path params
185178
if (validations?.pathParams) {
186-
const parsed = validations?.pathParams.safeParse(params);
179+
const parsed = validations.pathParams.safeParse(params);
187180
if (!parsed.success) {
188181
return BadRequestResponse(parsed.error);
189182
}
@@ -194,7 +187,7 @@ function createApiHandler<
194187
// Parse & validate query params
195188
if (validations?.queryParams) {
196189
const query = parseQueryString(req.nextUrl.search);
197-
const parsed = validations?.queryParams.safeParse(query);
190+
const parsed = validations.queryParams.safeParse(query);
198191
if (!parsed.success) {
199192
return BadRequestResponse(parsed.error);
200193
}
@@ -216,7 +209,7 @@ function createApiHandler<
216209
return BadRequestResponse('invalid request data');
217210
}
218211

219-
const parsed = validations?.body.safeParse(json);
212+
const parsed = validations.body.safeParse(json);
220213
if (!parsed.success) {
221214
return BadRequestResponse(parsed.error);
222215
}

0 commit comments

Comments
 (0)