diff --git a/backend/tests/controllers/students.test.ts b/backend/tests/controllers/students.test.ts index 93f35c48..7bb07f8c 100644 --- a/backend/tests/controllers/students.test.ts +++ b/backend/tests/controllers/students.test.ts @@ -198,15 +198,34 @@ describe('Student controllers', () => { ); }); - it('Create join request', async () => { + it('Create and delete join request', async () => { req = { - params: { username: 'Noordkaap' }, + params: { username: 'TheDoors' }, body: { classId: 'id02' }, }; await createStudentRequestHandler(req as Request, res as Response); expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ request: expect.anything() })); + + req = { + params: { username: 'TheDoors', classId: 'id02' }, + }; + + await deleteClassJoinRequestHandler(req as Request, res as Response); + + expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ request: expect.anything() })); + + await expect(async () => deleteClassJoinRequestHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException); + }); + + it('Create join request student already in class error', async () => { + req = { + params: { username: 'Noordkaap' }, + body: { classId: 'id02' }, + }; + + await expect(async () => createStudentRequestHandler(req as Request, res as Response)).rejects.toThrow(ConflictException); }); it('Create join request duplicate', async () => { @@ -217,16 +236,4 @@ describe('Student controllers', () => { await expect(async () => createStudentRequestHandler(req as Request, res as Response)).rejects.toThrow(ConflictException); }); - - it('Delete join request', async () => { - req = { - params: { username: 'Noordkaap', classId: 'id02' }, - }; - - await deleteClassJoinRequestHandler(req as Request, res as Response); - - expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ request: expect.anything() })); - - await expect(async () => deleteClassJoinRequestHandler(req as Request, res as Response)).rejects.toThrow(NotFoundException); - }); }); diff --git a/backend/tests/controllers/teachers.test.ts b/backend/tests/controllers/teachers.test.ts index bee23987..21533876 100644 --- a/backend/tests/controllers/teachers.test.ts +++ b/backend/tests/controllers/teachers.test.ts @@ -16,6 +16,7 @@ import { BadRequestException } from '../../src/exceptions/bad-request-exception. import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js'; import { getStudentRequestsHandler } from '../../src/controllers/students.js'; import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher'; +import {getClassHandler} from "../../src/controllers/classes"; describe('Teacher controllers', () => { let req: Partial; @@ -168,7 +169,6 @@ describe('Teacher controllers', () => { it('Get join requests by class', async () => { req = { - query: { username: 'LimpBizkit' }, params: { classId: 'id02' }, }; @@ -183,8 +183,7 @@ describe('Teacher controllers', () => { it('Update join request status', async () => { req = { - query: { username: 'LimpBizkit', studentUsername: 'PinkFloyd' }, - params: { classId: 'id02' }, + params: { classId: 'id02', studentUsername: 'PinkFloyd'}, body: { accepted: 'true' }, }; @@ -200,5 +199,13 @@ describe('Teacher controllers', () => { const status: boolean = jsonMock.mock.lastCall?.[0].requests[0].status; expect(status).toBeTruthy(); + + req = { + params: { id: 'id02' } + } + + await getClassHandler(req as Request, res as Response); + const students: string[] = jsonMock.mock.lastCall?.[0].class.students; + expect(students).contains("PinkFloyd"); }); });