Skip to content

Commit

Permalink
Merge pull request #817 from OneCommunityGlobal/abi_getactionItem_tests
Browse files Browse the repository at this point in the history
Abi Unit and Integration tests for getActionItem routes and Controllers
  • Loading branch information
DiegoSalas27 authored Mar 28, 2024
2 parents 58d8e78 + 9048f37 commit e936017
Show file tree
Hide file tree
Showing 16 changed files with 2,568 additions and 6,175 deletions.
7,740 changes: 1,738 additions & 6,002 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
"devDependencies": {
"@babel/eslint-parser": "^7.15.0",
"@types/express": "^4.17.6",
"@types/node": "^8.10.61",
"@types/jest": "^26.0.0",
"@types/node": "^8.10.61",
"@types/supertest": "^6.0.2",
"eslint": "^8.47.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-babel-module": "^5.3.1",
"eslint-plugin-import": "^2.28.0",
"lint-staged": "^12.5.0",
"nodemon": "^3.0.1",
"husky": "^8.0.1",
"jest": "^26.6.0",
"lint-staged": "^12.5.0",
"mongodb-memory-server": "^7.2.1",
"nodemon": "^3.0.1",
"prettier": "3.2.5",
"supertest": "^6.1.3"
},
Expand Down Expand Up @@ -69,6 +69,7 @@
"node-datetime": "^2.0.3",
"nodemailer": "^6.4.16",
"redis": "^4.2.0",
"supertest": "^6.3.4",
"uuid": "^3.4.0",
"ws": "^8.8.1"
},
Expand Down
20 changes: 20 additions & 0 deletions requirements/actionItemController/deleteactionItem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Check mark: ✅
Cross Mark: ❌

# Get Action Item

> ## Positive case
1. ❌ Receives a POST request in the **/api/userProfile** route
2. ✅ Returns 200 if get actionItem successfully finds and removes the matching `ActionItem`

> ## Negative case
3. ❌ Returns error 404 if the API does not exist
4. ✅ Returns 400 if any error occurs when finding an `ActionItem`.
5. ✅ Returns 400 if no `ActionItem` is found
6. ✅ Returns 400 if any error occurs when deleting an `ActionItem`.

> ## Edge case
1. ✅ Returns 400 if notificationdeleted method throws an error.
20 changes: 20 additions & 0 deletions requirements/actionItemController/editactionItem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Check mark: ✅
Cross Mark: ❌

# Get Action Item

> ## Positive case
1. ❌ Receives a POST request in the **/api/userProfile** route
2. ✅ Returns 200 if get actionItem successfully finds and edits the matching `ActionItem`

> ## Negative case
3. ❌ Returns error 404 if the API does not exist
4. ✅ Returns 400 if any error occurs when finding an `ActionItem`.
5. ✅ Returns 400 if no `ActionItem` is found
6. ✅ Returns 400 if any error occurs when saving an edited `ActionItem`.

> ## Edge case
1. ✅ Returns 400 if notificationedited method throws an error.
18 changes: 18 additions & 0 deletions requirements/actionItemController/getactionItem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Check mark: ✅
Cross Mark: ❌

# Get Action Item

> ## Positive case
1. ❌ Receives a POST request in the **/api/userProfile** route
2. ✅ Returns 200 if get actionItem successfully finds a matching `ActionItem`

> ## Negative case
3. ❌ Returns error 404 if the API does not exist
4. ✅ Returns 400 if any error occurs when finding an ActionItem.

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

# Post Action Item

> ## Positive case
1. ❌ Receives a POST request in the **/api/userProfile** route
2. ✅ Returns 200 if postactionItem is saved correctly

> ## Negative case
1. ❌ Returns error 404 if the API does not exist
2. ✅ Returns 400 if any error occurs during save.

> ## Edge case
1. ✅ Returns 400 if notificationcreated method throws an error.
154 changes: 79 additions & 75 deletions src/controllers/actionItemController.js
Original file line number Diff line number Diff line change
@@ -1,121 +1,125 @@
const mongoose = require('mongoose');
const notificationhelper = require('../helpers/notificationhelper')();
const closure = require('../helpers/notificationhelper');

const actionItemController = function (ActionItem) {
const getactionItem = function (req, res) {
const notificationhelper = closure();

const getactionItem = async function (req, res) {
const userid = req.params.userId;
ActionItem.find({
assignedTo: userid,
}, ('-createdDateTime -__v'))
.populate('createdBy', 'firstName lastName')
.then((results) => {
const actionitems = [];

results.forEach((element) => {
const actionitem = {};

actionitem._id = element._id;
actionitem.description = element.description;
actionitem.createdBy = `${element.createdBy.firstName} ${element.createdBy.lastName}`;
actionitem.assignedTo = element.assignedTo;

actionitems.push(actionitem);
});

res.status(200).send(actionitems);
})
.catch((error) => {
res.status(400).send(error);
try {
const actionItems = await ActionItem.find(
{
assignedTo: userid,
},
'-createdDateTime -__v',
).populate('createdBy', 'firstName lastName');
const actionitems = [];

actionItems.forEach((element) => {
const actionitem = {};

actionitem._id = element._id;
actionitem.description = element.description;
actionitem.createdBy = `${element.createdBy.firstName} ${element.createdBy.lastName}`;
actionitem.assignedTo = element.assignedTo;

actionitems.push(actionitem);
});

res.status(200).send(actionitems);
} catch (error) {
res.status(400).send(error);
}
};
const postactionItem = function (req, res) {
const postactionItem = async function (req, res) {
const { requestorId, assignedTo } = req.body.requestor;
const _actionItem = new ActionItem();

_actionItem.description = req.body.description;
_actionItem.assignedTo = req.body.assignedTo;
_actionItem.createdBy = req.body.requestor.requestorId;

_actionItem.save()
.then((result) => {
notificationhelper.notificationcreated(requestorId, assignedTo, _actionItem.description);
try {
const savedItem = await _actionItem.save();
notificationhelper.notificationcreated(requestorId, assignedTo, _actionItem.description);

const actionitem = {};
const actionitem = {};

actionitem.createdBy = 'You';
actionitem.description = _actionItem.description;
actionitem._id = result._id;
actionitem.assignedTo = _actionItem.assignedTo;
actionitem.createdBy = 'You';
actionitem.description = _actionItem.description;
actionitem._id = savedItem._id;
actionitem.assignedTo = _actionItem.assignedTo;

res.status(200).send(actionitem);
})
.catch((error) => {
res.status(400).send(error);
});
res.status(200).send(actionitem);
} catch (err) {
res.status(400).send(err);
}
};

const deleteactionItem = async function (req, res) {
const actionItemId = mongoose.Types.ObjectId(req.params.actionItemId);

const _actionItem = await ActionItem.findById(actionItemId)
.catch((error) => {
res.status(400).send(error);
});
try {
const _actionItem = await ActionItem.findById(actionItemId);

if (!_actionItem) {
res.status(400).send({
message: 'No valid records found',
});
return;
}
if (!_actionItem) {
res.status(400).send({
message: 'No valid records found',
});
return;
}

const { requestorId, assignedTo } = req.body.requestor;
const { requestorId, assignedTo } = req.body.requestor;

notificationhelper.notificationdeleted(requestorId, assignedTo, _actionItem.description);
notificationhelper.notificationdeleted(requestorId, assignedTo, _actionItem.description);

_actionItem.remove()
.then(() => {
res.status(200).send({
message: 'removed',
});
})
.catch((error) => {
res.status(400).send(error);
await _actionItem.remove();
res.status(200).send({
message: 'removed',
});
} catch (error) {
res.status(400).send(error);
}
};

const editactionItem = async function (req, res) {
const actionItemId = mongoose.Types.ObjectId(req.params.actionItemId);

const { requestorId, assignedTo } = req.body.requestor;

const _actionItem = await ActionItem.findById(actionItemId)
.catch((error) => {
res.status(400).send(error);
});
try {
const _actionItem = await ActionItem.findById(actionItemId);

if (!_actionItem) {
res.status(400).send({
message: 'No valid records found',
});
return;
if (!_actionItem) {
res.status(400).send({
message: 'No valid records found',
});
return;
}

notificationhelper.notificationedited(
requestorId,
assignedTo,
_actionItem.description,
req.body.description,
);

_actionItem.description = req.body.description;
_actionItem.assignedTo = req.body.assignedTo;

await _actionItem.save();
res.status(200).send({ message: 'Saved' });
} catch (error) {
res.status(400).send(error);
}
notificationhelper.notificationedited(requestorId, assignedTo, _actionItem.description, req.body.description);

_actionItem.description = req.body.description;
_actionItem.assignedTo = req.body.assignedTo;

_actionItem.save()
.then(res.status(200).send('Saved'))
.catch((error) => res.status(400).send(error));
};

return {
getactionItem,
postactionItem,
deleteactionItem,
editactionItem,

};
};

Expand Down
Loading

0 comments on commit e936017

Please sign in to comment.