Skip to content

Commit

Permalink
edit test for this route
Browse files Browse the repository at this point in the history
relates #28
  • Loading branch information
rehabas committed Apr 3, 2020
1 parent f1d5083 commit ff2b557
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
9 changes: 7 additions & 2 deletions server/controllers/routes/admin/stats.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const { getCohorts } = require('../../../database/queries');
const { getAlumniQuery } = require('../../../database/queries');
const { getAllProjects } = require('../../../database/queries');

const getStats = async (req, res, next) => {
try {
const cohorts = await getCohorts();
const cohortsCount = cohorts.rowCount;
const projectsCount = 16;
const studentsCount = 45;
const projects = await getAllProjects();
const projectsCount = projects.rowCount;
const students = await getAlumniQuery();
const studentsCount = students.rowCount;

res.json({
StatusCode: 200,
data: [
Expand Down
2 changes: 2 additions & 0 deletions server/database/queries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
deleteProject,
getCohortProjectsQuery,
getProjects,
getAllProjects,
} = require('./project');

module.exports = {
Expand All @@ -31,4 +32,5 @@ module.exports = {
getProjectById,
deleteProject,
getProjects,
getAllProjects,
};
5 changes: 5 additions & 0 deletions server/database/queries/project/getAllProjects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const connection = require('../../config/connection');

const getAllProjects = () => connection.query('SELECT * FROM project');

module.exports = getAllProjects;
2 changes: 2 additions & 0 deletions server/database/queries/project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const getCohortProjectsQuery = require('./getCohortProjects');
const editProjectQuery = require('./editProject');
const getProjectById = require('./getProjectById');
const deleteProject = require('./deleteProject');
const getAllProjects = require('./getAllProjects');

module.exports = {
getProjects,
Expand All @@ -12,4 +13,5 @@ module.exports = {
editProjectQuery,
getProjectById,
deleteProject,
getAllProjects,
};
4 changes: 3 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,10 @@ describe('Get stats', () => {
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) return done(err);
const { data } = res.body;
const { data } = res.body;console.log(data)
expect(data[0].numOfCohorts).toBe(2);
expect(data[1].numOfProjects).toBe(7);
expect(data[2].numOfStudents).toBe(2);
done();
});
});
Expand Down

0 comments on commit ff2b557

Please sign in to comment.