Skip to content

Commit

Permalink
Merge pull request #887 from OneCommunityGlobal/Ivy-InformationContro…
Browse files Browse the repository at this point in the history
…ller-getInformation-test

Ivy-InformationController-Unit Test-Catch Err
  • Loading branch information
one-community authored Sep 13, 2024
2 parents 7af8811 + 924178c commit 5b06f43
Show file tree
Hide file tree
Showing 7 changed files with 595 additions and 3 deletions.
16 changes: 16 additions & 0 deletions requirements/informationController/addInformation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Check mark: ✅
Cross Mark: ❌

# Add Information

> ## Positive case
1. ✅ Returns 201 if adding new information successfullyn and no cache.
2. ✅ Returns if adding new information successfully and hascache.

> ## Negative case
1. ✅ Returns error 500 if if there are no information in the database and any error occurs when finding the infoName.
2. ✅ Returns error 400 if if there are duplicate infoName in the database.
3. ✅ Returns error 400 if if there are issues when saving new informations.
4. ✅ Returns error 400 if if there are errors when saving the new information.

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

# Delete Information

> ## Positive case
1. ✅ Returns 200 if deleting informations successfull and no cache.
2. ✅ Returns if deleting informations successfully and has cache.

> ## Negative case
1. ✅ Returns error 400 if if there is any error when finding the information by information id.

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

# Get Information

> ## Positive case
1. ✅ Returns 200 if the informations key exists in NodeCache.
2. ✅ Returns 200 if there are information in the database.

> ## Negative case
1. ✅ Returns error 404 if if there are no information in the database and any error occurs when finding the information.

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

# Update Information

> ## Positive case
1. ✅ Returns 200 if updating informations successfully when no cache.
2. ✅ Returns if updating informations successfully when hascache.

> ## Negative case
1. ✅ Returns error 400 if if there is any error when finding the information by information id.

> ## Edge case
6 changes: 3 additions & 3 deletions src/controllers/informationController.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const mongoose = require('mongoose');
// const mongoose = require('mongoose');
// const userProfile = require('../models/userProfile');
// const hasPermission = require('../utilities/permissions');
const escapeRegex = require('../utilities/escapeRegex');
const cache = require('../utilities/nodeCache')();
const cacheClosure = require('../utilities/nodeCache');

const informationController = function (Information) {
const cache = cacheClosure();
const getInformations = function (req, res) {
// return all informations if cache is available
if (cache.hasCache('informations')) {
res.status(200).send(cache.getCache('informations'));
return;
}

Information.find({}, 'infoName infoContent visibility')
.then((results) => {
// cache results
Expand Down
Loading

0 comments on commit 5b06f43

Please sign in to comment.