-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35f5bd2
commit 219b70f
Showing
15 changed files
with
195 additions
and
16 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
api/controllers/coursesControllers/__tests__/renderStudentList.controller.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
jest.mock('../../helpers'); | ||
jest.mock('../../../../database/services/modelServices/courseServices'); | ||
|
||
const { | ||
renderStudentListController, | ||
} = require('../renderStudentList.controller'); | ||
const { | ||
render500ErrorHelper, | ||
redirectNonexistentCourseHelper, | ||
} = require('../../helpers'); | ||
const { | ||
findOneCourseService, | ||
} = require('../../../../database/services/modelServices/courseServices'); | ||
const { | ||
validateMockValueToHaveBeenCalled, | ||
} = require('../../../../utils/test-utils/validators.utils'); | ||
const { | ||
mockRequest, | ||
mockResponse, | ||
} = require('../../../../utils/test-utils/interceptors.utils'); | ||
|
||
let req; | ||
let res; | ||
|
||
describe('renderStudentList Controller Test Suite', () => { | ||
beforeEach(() => { | ||
req = mockRequest(); | ||
res = mockResponse(); | ||
|
||
req.user = { | ||
local: expect.anything(), | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('should validate render500ErrorHelper is called', async () => { | ||
findOneCourseService.mockReturnValueOnce(new Error()); | ||
|
||
await renderStudentListController(req, res); | ||
|
||
validateMockValueToHaveBeenCalled(render500ErrorHelper); | ||
}); | ||
|
||
test('should validate redirectNonexistentCourseHelper is called', async () => { | ||
findOneCourseService.mockReturnValueOnce(null); | ||
|
||
await renderStudentListController(req, res); | ||
|
||
validateMockValueToHaveBeenCalled(redirectNonexistentCourseHelper); | ||
}); | ||
|
||
test('should validate res.status & res.render is called', async () => { | ||
await renderStudentListController(req, res); | ||
|
||
const { status, render } = res; | ||
|
||
validateMockValueToHaveBeenCalled(status); | ||
validateMockValueToHaveBeenCalled(render); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
api/controllers/coursesControllers/renderStudentList.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { | ||
findOneCourseService, | ||
} = require('../../../database/services/modelServices/courseServices'); | ||
|
||
const { | ||
render500ErrorHelper, | ||
redirectNonexistentCourseHelper, | ||
} = require('../helpers'); | ||
|
||
exports.renderStudentListController = async (req, res) => { | ||
const { local } = req.user; | ||
const { id } = req.params; | ||
|
||
const isCourse = await findOneCourseService(id); | ||
|
||
if (isCourse instanceof Error) { | ||
render500ErrorHelper(res); | ||
return; | ||
} | ||
|
||
if (isCourse === null) { | ||
redirectNonexistentCourseHelper(req, res); | ||
return; | ||
} | ||
|
||
res.status(200).render('users/instructors/student-list', { local }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
api/controllers/helpers/__tests__/redirectNonexistentCourse.helper.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { redirectNonexistentCourseHelper } = require('../index'); | ||
const { | ||
mockRequest, | ||
mockResponse, | ||
} = require('../../../../utils/test-utils/interceptors.utils'); | ||
|
||
const { | ||
validateMockValueToHaveBeenCalled, | ||
} = require('../../../../utils/test-utils/validators.utils'); | ||
|
||
describe('redirectNonexistentCourse Helper Test Suite', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('should validate res.status & res.render being called', () => { | ||
const req = mockRequest(); | ||
const res = mockResponse(); | ||
|
||
redirectNonexistentCourseHelper(req, res); | ||
|
||
const { flash } = req; | ||
const { redirect } = res; | ||
|
||
validateMockValueToHaveBeenCalled(flash); | ||
validateMockValueToHaveBeenCalled(redirect); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
exports.redirectNonexistentCourseHelper = (request, response) => { | ||
request.flash('error_msg', "Course doesn't exist!"); | ||
response.redirect(302, '/'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<section> | ||
<h2>Students List</h2> | ||
|
||
{{!-- <table> | ||
<thead> | ||
<tr> | ||
<th>Firstname</th> | ||
<th>Lastname</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{{#each nameList}} | ||
<tr> | ||
<td>{{this.firstName}}</td> | ||
<td>{{this.lastName}}</td> | ||
</tr> | ||
{{/each}} | ||
</tbody> | ||
</table> --}} | ||
</section> |