Skip to content

Commit

Permalink
Merge pull request #954 from OneCommunityGlobal/Ivy-rolePresetsContro…
Browse files Browse the repository at this point in the history
…ller-unit-test

Ivy-rolePresetsController-create-delete-update-get-test-integration
  • Loading branch information
one-community authored Jun 8, 2024
2 parents cbb7020 + 0fe64a5 commit 6f6fd53
Show file tree
Hide file tree
Showing 7 changed files with 754 additions and 5 deletions.
18 changes: 18 additions & 0 deletions requirements/rolePresetsController/createNewPresets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Check mark: ✅
Cross Mark: ❌

# createNewPreset

> ## Positive case
1. ✅ Receives a POST request in the **/api/rolePreset** route
2. ✅ Return 201 if create New Presets successfully.

> ## Negative case
1. ✅ Returns error 403 if user doesn't have permissions for putRole
2. ✅ Returns 400 if missing presetName
3. ✅ Returns 400 if missing roleName
4. ✅ Returns 400 if missing premissions
5. ✅ Returns error 400 when saving new presets

> ## Edge case
17 changes: 17 additions & 0 deletions requirements/rolePresetsController/deletePresetById.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Check mark: ✅
Cross Mark: ❌

# deletePresetById

> ## Positive case
1. ✅ Return 200 if removing preset by id successfully.

> ## Negative case
1. ✅ Returns error 403 if user doesn't have permissions for putRole
2. ✅ Returns 400 if error in finding by id
3. ✅ Returns 400 if the route doesn't exist
4. ✅ Returns 400 if any error when removing results

> ## Edge case
15 changes: 15 additions & 0 deletions requirements/rolePresetsController/getPresetsByRole.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Check mark: ✅
Cross Mark: ❌

# getPresetsByRole

> ## Positive case
1. ✅ Receives a GET request in the **/api/rolePreset** route
2. ✅ Return 200 if get Presets by roleName successfully.

> ## Negative case
1. ✅ Returns error 403 if user doesn't have permissions for putRole
2. ✅ Returns 400 when catching any error in finding roleName

> ## Edge case
17 changes: 17 additions & 0 deletions requirements/rolePresetsController/updatePresetById.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Check mark: ✅
Cross Mark: ❌

# updatePresetById

> ## Positive case
1. ✅ Return 200 if update preset by id successfully.

> ## Negative case
1. ✅ Returns error 403 if user doesn't have permissions for putRole
2. ✅ Returns 400 if the router doesn't exist
3. ✅ Returns 400 if error in finding by id
3. ✅ Returns 400 if any error when saving results

> ## Edge case
10 changes: 5 additions & 5 deletions src/controllers/rolePresetsController.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { hasPermission } = require('../utilities/permissions');
const helper = require('../utilities/permissions');

const rolePresetsController = function (Preset) {
const getPresetsByRole = async function (req, res) {
if (!(await hasPermission(req.body.requestor, 'putRole'))) {
if (!(await helper.hasPermission(req.body.requestor, 'putRole'))) {
res.status(403).send('You are not authorized to make changes to roles.');
return;
}
Expand All @@ -18,7 +18,7 @@ const rolePresetsController = function (Preset) {
};

const createNewPreset = async function (req, res) {
if (!(await hasPermission(req.body.requestor, 'putRole'))) {
if (!(await helper.hasPermission(req.body.requestor, 'putRole'))) {
res.status(403).send('You are not authorized to make changes to roles.');
return;
}
Expand All @@ -41,7 +41,7 @@ const rolePresetsController = function (Preset) {
};

const updatePresetById = async function (req, res) {
if (!(await hasPermission(req.body.requestor, 'putRole'))) {
if (!(await helper.hasPermission(req.body.requestor, 'putRole'))) {
res.status(403).send('You are not authorized to make changes to roles.');
return;
}
Expand All @@ -61,7 +61,7 @@ const rolePresetsController = function (Preset) {
};

const deletePresetById = async function (req, res) {
if (!(await hasPermission(req.body.requestor, 'putRole'))) {
if (!(await helper.hasPermission(req.body.requestor, 'putRole'))) {
res.status(403).send('You are not authorized to make changes to roles.');
return;
}
Expand Down
Loading

0 comments on commit 6f6fd53

Please sign in to comment.