feat: qol functies toegevoegd, tests voor submissions aan het schrijven
This commit is contained in:
		
							parent
							
								
									ef8bc71018
								
							
						
					
					
						commit
						c9739a1420
					
				
					 2 changed files with 84 additions and 0 deletions
				
			
		
							
								
								
									
										72
									
								
								backend/tests/controllers/submissions.test.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								backend/tests/controllers/submissions.test.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,72 @@ | |||
| import { setupTestApp } from '../setup-tests.js'; | ||||
| import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest'; | ||||
| import { getSubmissionHandler } from '../../src/controllers/submissions.js'; | ||||
| import { Request, Response } from 'express'; | ||||
| import { checkReturn404, checkReturnList } from './qol.js'; | ||||
| 
 | ||||
| 
 | ||||
| function createRequestObject(hruid: string, submissionNumber: string) { | ||||
| 	return { | ||||
| 		params: { | ||||
| 			hruid: hruid, | ||||
| 			id: submissionNumber, | ||||
| 		}, | ||||
| 		query: { | ||||
| 			language: 'nl', | ||||
| 			version: '1', | ||||
| 		}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| describe('Submission controllers', () => { | ||||
|     let req: Partial<Request>; | ||||
|     let res: Partial<Response>; | ||||
| 
 | ||||
|     let jsonMock: Mock; | ||||
|     let statusMock: Mock; | ||||
| 
 | ||||
|     beforeAll(async () => { | ||||
|         await setupTestApp(); | ||||
|     }); | ||||
|    | ||||
|     beforeEach(async () =>  { | ||||
|         jsonMock = vi.fn(); | ||||
|         statusMock = vi.fn().mockReturnThis(); | ||||
| 
 | ||||
|         res = { | ||||
|             json: jsonMock, | ||||
|             status: statusMock, | ||||
|         }; | ||||
|     }); | ||||
| 
 | ||||
|     it('should return a 404 and error if submission is not found', async () => { | ||||
| 		req = createRequestObject('id01', '1000000'); | ||||
| 
 | ||||
| 		await getSubmissionHandler(req as Request, res as Response); | ||||
| 
 | ||||
| 		checkReturn404(jsonMock, statusMock); | ||||
| 	}); | ||||
| 
 | ||||
| 	it('should return a 404 and error if learningobject is not found', async () => { | ||||
| 		req = createRequestObject('doesnotexist', '1000000'); | ||||
| 
 | ||||
| 		await getSubmissionHandler(req as Request, res as Response); | ||||
| 
 | ||||
| 		checkReturn404(jsonMock, statusMock); | ||||
| 	}); | ||||
| 
 | ||||
| 	it('should return an existing submission', async () => { | ||||
| 		req = createRequestObject('id01', '1'); | ||||
| 
 | ||||
| 		await getSubmissionHandler(req as Request, res as Response); | ||||
| 
 | ||||
| 		console.log(jsonMock.mock.lastCall![0]); | ||||
| 		// TODO
 | ||||
| 	}); | ||||
| 
 | ||||
| 	it('should return a list of submissions for a learning object', async () => { | ||||
| 		req = createRequestObject('id01', 'irrelevant'); | ||||
| 
 | ||||
| 	}); | ||||
| }); | ||||
| 
 | ||||
		Reference in a new issue
	
	 Adriaan Jacquet
						Adriaan Jacquet