Skip to content

Commit 07b0a75

Browse files
Merge pull request #4785 from linuxfoundation/unicron-4762-cypress-apis-test-coverage-6
Update test coverage to be able to run locally (no GW) and by using deployed dev version (with ACS and GW)
2 parents a8c17dc + f4552ef commit 07b0a75

File tree

2 files changed

+105
-6
lines changed

2 files changed

+105
-6
lines changed

tests/functional/cypress/e2e/cla-group.cy.ts

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
validate_200_Status,
44
validate_400_Status,
55
validate_401_Status,
6+
validate_403_Status,
67
validate_404_Status,
78
validate_404_Status_and_Message,
89
validate_404_Status_and_Message2,
@@ -175,6 +176,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
175176
expectedStatus: 422,
176177
expectedCode: 602,
177178
expectedMsg: 'claGroupInput in body is required',
179+
mode: 'both',
178180
},
179181

180182
// List CLA groups for a project - wrong SFID (missing)
@@ -184,6 +186,17 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
184186
expectedStatus: 404,
185187
expectedCode: 1,
186188
expectedMsg: 'path /v4/foundation//cla-groups was not found',
189+
mode: 'local',
190+
},
191+
192+
// List CLA groups for a project - wrong SFID (missing)
193+
{
194+
method: 'GET',
195+
url: `${claEndpoint}foundation//cla-groups`,
196+
expectedStatus: 403,
197+
expectedCode: 403,
198+
expectedMsg: '',
199+
mode: 'remote',
187200
},
188201

189202
// List CLA groups for a project - wrong SFID (too short)
@@ -193,6 +206,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
193206
expectedStatus: 422,
194207
expectedCode: 604,
195208
expectedMsg: 'projectSFID in path should be at least 15 chars long',
209+
mode: 'both',
196210
},
197211

198212
// List CLA groups for a project - wrong SFID (not matching regexp)
@@ -202,6 +216,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
202216
expectedStatus: 422,
203217
expectedCode: 605,
204218
expectedMsg: "projectSFID in path should match '^([0-9A-Za-z]{15}|[0-9A-Za-z]{18})$'",
219+
mode: 'both',
205220
},
206221

207222
// List CLA groups for a project (wrong SFID - too long)
@@ -211,6 +226,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
211226
expectedStatus: 422,
212227
expectedCode: 603,
213228
expectedMsg: 'projectSFID in path should be at most 18 chars long',
229+
mode: 'both',
214230
},
215231

216232
// Update CLA group (using dummy ID which isn't correct UUID v4)
@@ -221,15 +237,17 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
221237
expectedCode: 605,
222238
expectedMsg:
223239
"claGroupID in path should match '^[a-fA-F0-9]{8}-?[a-fA-F0-9]{4}-?4[a-fA-F0-9]{3}-?[89ab][a-fA-F0-9]{3}-?[a-fA-F0-9]{12}$'",
240+
mode: 'both',
224241
},
225242

226-
// Update CLA group (using dummy ID which is well-formed but no body paramaters)
243+
// Update CLA group (using dummy ID which is well-formed but no body parameters)
227244
{
228245
method: 'PUT',
229246
url: `${claEndpoint}cla-group/${exampleClaGroupId}`,
230247
expectedStatus: 400,
231248
expectedCode: 602,
232249
expectedMsg: 'EasyCLA - 400 Bad Request - missing update parameters - body missing required values',
250+
mode: 'both',
233251
},
234252

235253
// Enroll projects (using dummy ID - incorrect UUIDv4)
@@ -240,6 +258,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
240258
expectedCode: 605,
241259
expectedMsg:
242260
"claGroupID in path should match '^[a-fA-F0-9]{8}-?[a-fA-F0-9]{4}-?4[a-fA-F0-9]{3}-?[89ab][a-fA-F0-9]{3}-?[a-fA-F0-9]{12}$'",
261+
mode: 'both',
243262
},
244263

245264
// Enroll projects (using correct but non existing ID)
@@ -249,6 +268,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
249268
expectedStatus: 404,
250269
expectedCode: 2,
251270
expectedMsg: `EasyCLA - 404 Not Found - problem loading CLA Group by ID: ${exampleClaGroupId} - error: cla group ${exampleClaGroupId} not found`,
271+
mode: 'both',
252272
},
253273

254274
// Enroll projects (using correct ID - but without PUT data)
@@ -259,6 +279,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
259279
expectedCode: 400,
260280
expectedMsg:
261281
'EasyCLA - 400 Bad Request - unable to enroll projects in CLA Group - error: enroll validation error: invalid project ID value due to error: validation failure - there should be at least one project provided for the enroll request',
282+
mode: 'both',
262283
},
263284

264285
// Unenroll projects (using dummy ID - incorrect UUIDv4)
@@ -269,6 +290,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
269290
expectedCode: 605,
270291
expectedMsg:
271292
"claGroupID in path should match '^[a-fA-F0-9]{8}-?[a-fA-F0-9]{4}-?4[a-fA-F0-9]{3}-?[89ab][a-fA-F0-9]{3}-?[a-fA-F0-9]{12}$'",
293+
mode: 'both',
272294
},
273295

274296
// Unenroll projects (using correct but non-existing ID)
@@ -278,6 +300,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
278300
expectedStatus: 404,
279301
expectedCode: 2,
280302
expectedMsg: `EasyCLA - 404 Not Found - unable to locate CLA Group by ID: ${exampleClaGroupId} - error: cla group ${exampleClaGroupId} not found`,
303+
mode: 'both',
281304
},
282305

283306
// Unenroll projects (using correct ID - but without PUT data)
@@ -288,6 +311,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
288311
expectedCode: 400,
289312
expectedMsg:
290313
'EasyCLA - 400 Bad Request - unable to enroll projects in CLA Group - error: unenroll validation error: invalid project ID value due to error: validation failure - there should be at least one project provided for the unenroll request',
314+
mode: 'both',
291315
},
292316

293317
// Get GitHub orgs for project - no project provided
@@ -297,6 +321,17 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
297321
expectedStatus: 404,
298322
expectedCode: 1,
299323
expectedMsg: 'path /v4/project//github/organizations was not found',
324+
mode: 'local',
325+
},
326+
327+
// Get GitHub orgs for project - no project provided
328+
{
329+
method: 'GET',
330+
url: `${claEndpoint}project//github/organizations`,
331+
expectedStatus: 403,
332+
expectedCode: 403,
333+
expectedMsg: '',
334+
mode: 'remote',
300335
},
301336

302337
// LG: Get GitHub orgs for project - wrong SFID provided, but API is not verifying this in swagger
@@ -306,6 +341,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
306341
expectedStatus: 404,
307342
expectedCode: 2,
308343
expectedMsg: 'EasyCLA - 404 Not Found - github organization with project SFID not found: aaaa',
344+
mode: 'both',
309345
},
310346

311347
// Update GitHub org config missing project and github org name and update configuration data
@@ -315,6 +351,17 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
315351
expectedStatus: 404,
316352
expectedCode: 1,
317353
expectedMsg: 'path /v4/project//github/organizations//config was not found',
354+
mode: 'local',
355+
},
356+
357+
// Update GitHub org config missing project and github org name and update configuration data
358+
{
359+
method: 'PUT',
360+
url: `${claEndpoint}project//github/organizations//config`,
361+
expectedStatus: 403,
362+
expectedCode: 403,
363+
expectedMsg: '',
364+
mode: 'remote',
318365
},
319366

320367
// Update GitHub org config missing github org name and update configuration data
@@ -324,6 +371,17 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
324371
expectedStatus: 404,
325372
expectedCode: 1,
326373
expectedMsg: 'path /v4/project//github/organizations/org/config was not found',
374+
mode: 'local',
375+
},
376+
377+
// Update GitHub org config missing github org name and update configuration data
378+
{
379+
method: 'PUT',
380+
url: `${claEndpoint}project//github/organizations/org/config`,
381+
expectedStatus: 403,
382+
expectedCode: 403,
383+
expectedMsg: '',
384+
mode: 'remote',
327385
},
328386

329387
// Update GitHub org config missing project and update configuration data
@@ -333,6 +391,17 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
333391
expectedStatus: 405,
334392
expectedCode: 405,
335393
expectedMsg: 'method PUT is not allowed, but [DELETE] are',
394+
mode: 'local',
395+
},
396+
397+
// Update GitHub org config missing project and update configuration data
398+
{
399+
method: 'PUT',
400+
url: `${claEndpoint}project/aaa/github/organizations//config`,
401+
expectedStatus: 403,
402+
expectedCode: 403,
403+
expectedMsg: '',
404+
mode: 'remote',
336405
},
337406

338407
// Update GitHub org config missing update configuration data
@@ -342,6 +411,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
342411
expectedStatus: 422,
343412
expectedCode: 602,
344413
expectedMsg: 'body in body is required',
414+
mode: 'both',
345415
},
346416

347417
// Delete CLA group - but not specifying claGroupID at all
@@ -351,6 +421,17 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
351421
expectedStatus: 405,
352422
expectedCode: 405,
353423
expectedMsg: 'method DELETE is not allowed, but [POST] are',
424+
mode: 'local',
425+
},
426+
427+
// Delete CLA group - but not specifying claGroupID at all
428+
{
429+
method: 'DELETE',
430+
url: `${claEndpoint}cla-group/`,
431+
expectedStatus: 403,
432+
expectedCode: 403,
433+
expectedMsg: '',
434+
mode: 'remote',
354435
},
355436

356437
// Delete CLA group specifying dummy ID which is not a correct UUIDv4
@@ -361,6 +442,7 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
361442
expectedCode: 605,
362443
expectedMsg:
363444
"claGroupID in path should match '^[a-fA-F0-9]{8}-?[a-fA-F0-9]{4}-?4[a-fA-F0-9]{3}-?[89ab][a-fA-F0-9]{3}-?[a-fA-F0-9]{12}$'",
445+
mode: 'both',
364446
},
365447

366448
// Delete CLA group specifying an ID that does not exist
@@ -370,11 +452,14 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
370452
expectedStatus: 404,
371453
expectedCode: 2,
372454
expectedMsg: `EasyCLA - 404 Not Found - cla group ${exampleClaGroupId} not found`,
455+
mode: 'both',
373456
},
374457
];
375458

376-
cy.wrap(requests).each((req: any) => {
377-
const { method, url, expectedStatus, expectedCode, expectedMsg } = req;
459+
const effectiveMode = local ? 'local' : 'remote';
460+
const filtered = requests.filter((r) => r.mode === 'both' || r.mode === effectiveMode);
461+
cy.wrap(filtered).each((req: any) => {
462+
const { method, url, expectedStatus, expectedCode, expectedMsg, mode } = req;
378463
cy.task('log', `--> ${method} ${url}`);
379464
cy.request({
380465
method: method,
@@ -391,6 +476,8 @@ describe("To Validate 'GET, CREATE, UPDATE and DELETE' CLA groups API call on ch
391476
switch (expectedStatus) {
392477
case 400:
393478
return validate_400_Status(response, expectedMsg);
479+
case 403:
480+
return validate_403_Status(response);
394481
case 404:
395482
if (expectedCode === 1) {
396483
return validate_404_Status_and_Message(response, expectedMsg);

tests/functional/cypress/support/commands.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,26 @@ export function validate_401_Status(response, local) {
5252
if (local === true) {
5353
expect(response.body.message).to.eq('unauthenticated for invalid credentials');
5454
} else {
55-
expect(response.body).to.eq("no token provided\n");
55+
expect(response.body).to.eq('no token provided\n');
5656
}
5757
}
5858

59+
function parseJsonBody(resp) {
60+
if (resp && typeof resp.body === 'string') {
61+
const s = resp.body.trim();
62+
try {
63+
return JSON.parse(s);
64+
} catch (e) {}
65+
}
66+
return resp.body;
67+
}
68+
5969
export function validate_403_Status(response) {
70+
const body = parseJsonBody(response);
6071
expect(response.status).to.eq(403);
6172
expect(response.statusText).to.eq('Forbidden');
62-
expect(response.body.Code).to.eq('403');
73+
const code = body && (body.Code ?? body.code);
74+
expect(code).to.eq(403);
6375
}
6476

6577
export function validate_404_Status(response) {
@@ -78,7 +90,7 @@ export function validate_404_Status_and_Message(response, message) {
7890
export function validate_404_Status_and_Message2(response, message) {
7991
expect(response.status).to.eq(404);
8092
expect(response.statusText).to.eq('Not Found');
81-
expect(response.body.Code).to.eq("404");
93+
expect(response.body.Code).to.eq('404');
8294
expect(response.body.Message).to.eq(message);
8395
}
8496

0 commit comments

Comments
 (0)