feat: extra tests op nieuwe func student en teacher
This commit is contained in:
		
							parent
							
								
									65bce19fcf
								
							
						
					
					
						commit
						c7155fb438
					
				
					 2 changed files with 31 additions and 17 deletions
				
			
		|  | @ -198,15 +198,34 @@ describe('Student controllers', () => { | ||||||
|         ); |         ); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('Create join request', async () => { |     it('Create and delete join request', async () => { | ||||||
|         req = { |         req = { | ||||||
|             params: { username: 'Noordkaap' }, |             params: { username: 'TheDoors' }, | ||||||
|             body: { classId: 'id02' }, |             body: { classId: 'id02' }, | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         await createStudentRequestHandler(req as Request, res as Response); |         await createStudentRequestHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
|         expect(jsonMock).toHaveBeenCalledWith(expect.objectContaining({ request: expect.anything() })); |         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 () => { |     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); |         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); |  | ||||||
|     }); |  | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -16,6 +16,7 @@ import { BadRequestException } from '../../src/exceptions/bad-request-exception. | ||||||
| import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js'; | import { EntityAlreadyExistsException } from '../../src/exceptions/entity-already-exists-exception.js'; | ||||||
| import { getStudentRequestsHandler } from '../../src/controllers/students.js'; | import { getStudentRequestsHandler } from '../../src/controllers/students.js'; | ||||||
| import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher'; | import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher'; | ||||||
|  | import {getClassHandler} from "../../src/controllers/classes"; | ||||||
| 
 | 
 | ||||||
| describe('Teacher controllers', () => { | describe('Teacher controllers', () => { | ||||||
|     let req: Partial<Request>; |     let req: Partial<Request>; | ||||||
|  | @ -168,7 +169,6 @@ describe('Teacher controllers', () => { | ||||||
| 
 | 
 | ||||||
|     it('Get join requests by class', async () => { |     it('Get join requests by class', async () => { | ||||||
|         req = { |         req = { | ||||||
|             query: { username: 'LimpBizkit' }, |  | ||||||
|             params: { classId: 'id02' }, |             params: { classId: 'id02' }, | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|  | @ -183,8 +183,7 @@ describe('Teacher controllers', () => { | ||||||
| 
 | 
 | ||||||
|     it('Update join request status', async () => { |     it('Update join request status', async () => { | ||||||
|         req = { |         req = { | ||||||
|             query: { username: 'LimpBizkit', studentUsername: 'PinkFloyd' }, |             params: { classId: 'id02', studentUsername: 'PinkFloyd'}, | ||||||
|             params: { classId: 'id02' }, |  | ||||||
|             body: { accepted: 'true' }, |             body: { accepted: 'true' }, | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|  | @ -200,5 +199,13 @@ describe('Teacher controllers', () => { | ||||||
| 
 | 
 | ||||||
|         const status: boolean = jsonMock.mock.lastCall?.[0].requests[0].status; |         const status: boolean = jsonMock.mock.lastCall?.[0].requests[0].status; | ||||||
|         expect(status).toBeTruthy(); |         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"); | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl