diff --git a/server/controllers/routes/user/cohort/getSpecificCohort.js b/server/controllers/routes/user/cohort/getSpecificCohort.js index fc1ca3ca..b11514e9 100644 --- a/server/controllers/routes/user/cohort/getSpecificCohort.js +++ b/server/controllers/routes/user/cohort/getSpecificCohort.js @@ -1,19 +1,26 @@ const getCohortQuery = require('../../../../database/queries'); -exports.getSpecificCohort = async (req, res) => { +exports.getSpecificCohort = async (req, res, next) => { try { const { cohortid } = req.params; - const { rows } = await getCohortQuery(cohortid); - const data = { ...rows[0] }; - if (data.id) { - res.json({ statusCode: 200, data }); + if (cohortid > 0) { + const { rows } = await getCohortQuery(cohortid); + const data = { ...rows[0] }; + if (data.id) { + res.json({ statusCode: 200, data }); + } else { + res.status(404).json({ + statusCode: 404, + message: "Sorry There's no cohort for this id", + }); + } } else { - throw new Error(); + res.status(404).json({ + statusCode: 404, + message: 'You enterd wrong cohort ID', + }); } } catch (err) { - res.status(404).json({ - statusCode: 404, - message: "Sorry There's no cohort for this id", - }); + next(err); } }; diff --git a/test/index.test.js b/test/index.test.js index 8717abaf..b3cbdf19 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -4,13 +4,9 @@ const dbBuild = require('../server/database/config/build'); const app = require('../server/app'); -beforeAll(() => { - return dbBuild(); -}); +beforeAll(() => dbBuild()); -afterAll(() => { - return connection.end(); -}); +afterAll(() => connection.end()); describe('Cohort', () => { test('Route /cohorts/1 status 200, json header, data.name =G8 ', (done) => {