Skip to content

Commit

Permalink
test: FORMS-1444 add rbac routes tests (bcgov#1476)
Browse files Browse the repository at this point in the history
* test: FORMS-1444 add rbac routes

* route tests cleanup for consistency
  • Loading branch information
WalterMoar committed Aug 15, 2024
1 parent 413668a commit 5b45d80
Show file tree
Hide file tree
Showing 9 changed files with 709 additions and 438 deletions.
102 changes: 51 additions & 51 deletions app/tests/unit/forms/admin/routes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ describe(`${basePath}/externalAPIs`, () => {

await appRequest.get(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.getExternalAPIs).toHaveBeenCalledTimes(1);
expect(controller.getExternalAPIs).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -67,9 +67,9 @@ describe(`${basePath}/externalAPIs/:externalApiId`, () => {

await appRequest.put(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.updateExternalAPI).toHaveBeenCalledTimes(1);
expect(controller.updateExternalAPI).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -83,9 +83,9 @@ describe(`${basePath}/externalAPIs/statusCodes`, () => {

await appRequest.get(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.getExternalAPIStatusCodes).toHaveBeenCalledTimes(1);
expect(controller.getExternalAPIStatusCodes).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -100,9 +100,9 @@ describe(`${basePath}/formcomponents/proactivehelp/:publishStatus/:componentId`,

await appRequest.put(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.updateFormComponentsProactiveHelp).toHaveBeenCalledTimes(1);
expect(controller.updateFormComponentsProactiveHelp).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -117,9 +117,9 @@ describe(`${basePath}/formcomponents/proactivehelp/imageUrl/:componentId`, () =>

await appRequest.get(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.getFCProactiveHelpImageUrl).toHaveBeenCalledTimes(1);
expect(controller.getFCProactiveHelpImageUrl).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -133,9 +133,9 @@ describe(`${basePath}/formcomponents/proactivehelp/list`, () => {

await appRequest.get(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.listFormComponentsProactiveHelp).toHaveBeenCalledTimes(1);
expect(controller.listFormComponentsProactiveHelp).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -149,9 +149,9 @@ describe(`${basePath}/formcomponents/proactivehelp/object`, () => {

await appRequest.post(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.createFormComponentsProactiveHelp).toHaveBeenCalledTimes(1);
expect(controller.createFormComponentsProactiveHelp).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -165,9 +165,9 @@ describe(`${basePath}/forms`, () => {

await appRequest.get(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.listForms).toHaveBeenCalledTimes(1);
expect(controller.listForms).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -182,9 +182,9 @@ describe(`${basePath}/forms/:formId`, () => {

await appRequest.get(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.readForm).toHaveBeenCalledTimes(1);
expect(controller.readForm).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -199,9 +199,9 @@ describe(`${basePath}/forms/:formId/addUser`, () => {

await appRequest.put(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.setFormUserRoles).toHaveBeenCalledTimes(1);
expect(controller.setFormUserRoles).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -216,9 +216,9 @@ describe(`${basePath}/forms/:formId/apiKey`, () => {

await appRequest.delete(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.deleteApiKey).toHaveBeenCalledTimes(1);
expect(controller.deleteApiKey).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});

it('should have correct middleware for GET', async () => {
Expand All @@ -228,9 +228,9 @@ describe(`${basePath}/forms/:formId/apiKey`, () => {

await appRequest.get(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.readApiDetails).toHaveBeenCalledTimes(1);
expect(controller.readApiDetails).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -245,9 +245,9 @@ describe(`${basePath}/forms/:formId/formUsers`, () => {

await appRequest.get(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.getFormUserRoles).toHaveBeenCalledTimes(1);
expect(controller.getFormUserRoles).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -262,9 +262,9 @@ describe(`${basePath}/forms/:formId/restore`, () => {

await appRequest.put(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.restoreForm).toHaveBeenCalledTimes(1);
expect(controller.restoreForm).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -280,9 +280,9 @@ describe(`${basePath}/forms/:formId/versions/:formVersionId`, () => {

await appRequest.get(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.readVersion).toHaveBeenCalledTimes(1);
expect(controller.readVersion).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -296,9 +296,9 @@ describe(`${basePath}/users`, () => {

await appRequest.get(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(controller.getUsers).toHaveBeenCalledTimes(1);
expect(controller.getUsers).toBeCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
});
});

Expand All @@ -313,8 +313,8 @@ describe(`${basePath}/users/:userId`, () => {

await appRequest.get(path);

expect(mockJwtServiceProtect).toHaveBeenCalledTimes(1);
expect(userAccess.currentUser).toHaveBeenCalledTimes(1);
expect(userController.read).toHaveBeenCalledTimes(1);
expect(mockJwtServiceProtect).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
expect(userController.read).toBeCalledTimes(1);
});
});
4 changes: 2 additions & 2 deletions app/tests/unit/forms/bcgeoaddress/routes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe(`${basePath}/address`, () => {

await appRequest.get(path);

expect(controller.searchBCGeoAddress).toHaveBeenCalledTimes(1);
expect(controller.searchBCGeoAddress).toBeCalledTimes(1);
});
});

Expand All @@ -41,6 +41,6 @@ describe(`${basePath}/advance/address`, () => {

await appRequest.get(path);

expect(controller.advanceSearchBCGeoAddress).toHaveBeenCalledTimes(1);
expect(controller.advanceSearchBCGeoAddress).toBeCalledTimes(1);
});
});
12 changes: 6 additions & 6 deletions app/tests/unit/forms/file/routes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ describe(`${basePath}`, () => {

await appRequest.post(path);

expect(validateParameter.validateFileId).toBeCalledTimes(0);
expect(apiAccess).toBeCalledTimes(0);
expect(controller.create).toBeCalledTimes(1);
expect(filePermissions.currentFileRecord).toBeCalledTimes(0);
expect(filePermissions.hasFileCreate).toBeCalledTimes(1);
expect(hasFilePermissionsMock).toBeCalledTimes(0);
expect(rateLimiter.apiKeyRateLimiter).toBeCalledTimes(0);
expect(upload.fileUpload.upload).toBeCalledTimes(1);
expect(userAccess.currentUser).toBeCalledTimes(1);
expect(controller.create).toBeCalledTimes(1);
expect(validateParameter.validateFileId).toBeCalledTimes(0);
});
});

Expand All @@ -98,15 +98,15 @@ describe(`${basePath}/:id`, () => {

await appRequest.delete(path);

expect(validateParameter.validateFileId).toBeCalledTimes(1);
expect(apiAccess).toBeCalledTimes(0);
expect(controller.delete).toBeCalledTimes(1);
expect(filePermissions.currentFileRecord).toBeCalledTimes(1);
expect(filePermissions.hasFileCreate).toBeCalledTimes(0);
expect(hasFilePermissionsMock).toBeCalledTimes(1);
expect(rateLimiter.apiKeyRateLimiter).toBeCalledTimes(0);
expect(upload.fileUpload.upload).toBeCalledTimes(0);
expect(userAccess.currentUser).toBeCalledTimes(1);
expect(controller.delete).toBeCalledTimes(1);
expect(validateParameter.validateFileId).toBeCalledTimes(1);
});

it('should have correct middleware for GET', async () => {
Expand All @@ -116,14 +116,14 @@ describe(`${basePath}/:id`, () => {

await appRequest.get(path);

expect(validateParameter.validateFileId).toBeCalledTimes(1);
expect(apiAccess).toBeCalledTimes(1);
expect(controller.read).toBeCalledTimes(1);
expect(filePermissions.currentFileRecord).toBeCalledTimes(1);
expect(filePermissions.hasFileCreate).toBeCalledTimes(0);
expect(hasFilePermissionsMock).toBeCalledTimes(1);
expect(rateLimiter.apiKeyRateLimiter).toBeCalledTimes(1);
expect(upload.fileUpload.upload).toBeCalledTimes(0);
expect(userAccess.currentUser).toBeCalledTimes(1);
expect(controller.read).toBeCalledTimes(1);
expect(validateParameter.validateFileId).toBeCalledTimes(1);
});
});
Loading

0 comments on commit 5b45d80

Please sign in to comment.