feat: testen voor submissions geimplementeerd
This commit is contained in:
		
							parent
							
								
									f0eb4822d9
								
							
						
					
					
						commit
						7a443c0686
					
				
					 3 changed files with 27 additions and 14 deletions
				
			
		|  | @ -6,12 +6,15 @@ import { Student } from '../../entities/users/student.entity.js'; | ||||||
| 
 | 
 | ||||||
| export class SubmissionRepository extends DwengoEntityRepository<Submission> { | export class SubmissionRepository extends DwengoEntityRepository<Submission> { | ||||||
|     public findSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<Submission | null> { |     public findSubmissionByLearningObjectAndSubmissionNumber(loId: LearningObjectIdentifier, submissionNumber: number): Promise<Submission | null> { | ||||||
|         return this.findOne({ |         return this.findOne( | ||||||
|             learningObjectHruid: loId.hruid, |             { | ||||||
|             learningObjectLanguage: loId.language, |                 learningObjectHruid: loId.hruid, | ||||||
|             learningObjectVersion: loId.version, |                 learningObjectLanguage: loId.language, | ||||||
|             submissionNumber: submissionNumber, |                 learningObjectVersion: loId.version, | ||||||
|         }); |                 submissionNumber: submissionNumber, | ||||||
|  |             }, | ||||||
|  |             { populate: ['submitter', 'onBehalfOf'] }, | ||||||
|  |         );   | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public findSubmissionsByLearningObject(loId: LearningObjectIdentifier): Promise<Submission[]> { |     public findSubmissionsByLearningObject(loId: LearningObjectIdentifier): Promise<Submission[]> { | ||||||
|  |  | ||||||
|  | @ -1,12 +1,16 @@ | ||||||
| export function checkReturnList(jsonMock: Mock, listName: string) { | export function checkReturnList(jsonMock: Mock, listName: string, length?: number) { | ||||||
| 	expect(jsonMock).toHaveBeenCalled(); | 	expect(jsonMock).toHaveBeenCalled(); | ||||||
| 
 | 
 | ||||||
| 	const result = jsonMock.mock.lastCall![0]; | 	const result = jsonMock.mock.lastCall![0]; | ||||||
| 		 | 		 | ||||||
| 	expect(listName in result).toBeTruthy(); | 	expect(listName in result).toBeTruthy(); | ||||||
|  | 
 | ||||||
|  | 	if (length) { | ||||||
|  | 		expect(result[listName].length).toBe(length); | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export function checkReturn404(jsonMock: Mock, statusMock: Mock) { | export function checkReturn404(jsonMock: Mock, statusMock: Mock) { | ||||||
| 		expect(statusMock).toHaveBeenCalledWith(404); | 	expect(statusMock).toHaveBeenCalledWith(404); | ||||||
| 		expect(jsonMock).toHaveBeenCalled(); | 	expect(jsonMock).toHaveBeenCalled(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,8 +1,10 @@ | ||||||
| import { setupTestApp } from '../setup-tests.js'; | import { setupTestApp } from '../setup-tests.js'; | ||||||
| import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest'; | import { describe, it, expect, beforeAll, beforeEach, vi, Mock } from 'vitest'; | ||||||
| import { getSubmissionHandler } from '../../src/controllers/submissions.js'; | import { getSubmissionHandler, getAllSubmissionsHandler } from '../../src/controllers/submissions.js'; | ||||||
| import { Request, Response } from 'express'; | import { Request, Response } from 'express'; | ||||||
| import { checkReturn404, checkReturnList } from './qol.js'; | import { checkReturn404, checkReturnList } from './qol.js'; | ||||||
|  | import { getSubmission } from '../../src/services/submissions.js'; | ||||||
|  | import { Language } from '../../src/entities/content/language.js'; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| function createRequestObject(hruid: string, submissionNumber: string) { | function createRequestObject(hruid: string, submissionNumber: string) { | ||||||
|  | @ -12,7 +14,7 @@ function createRequestObject(hruid: string, submissionNumber: string) { | ||||||
| 			id: submissionNumber, | 			id: submissionNumber, | ||||||
| 		}, | 		}, | ||||||
| 		query: { | 		query: { | ||||||
| 			language: 'nl', | 			language: 'en', | ||||||
| 			version: '1', | 			version: '1', | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
|  | @ -60,13 +62,17 @@ describe('Submission controllers', () => { | ||||||
| 
 | 
 | ||||||
| 		await getSubmissionHandler(req as Request, res as Response); | 		await getSubmissionHandler(req as Request, res as Response); | ||||||
| 
 | 
 | ||||||
| 		console.log(jsonMock.mock.lastCall![0]); | 		const expectedResult = await getSubmission('id01', Language.English, 1, 1); | ||||||
| 		// TODO
 | 
 | ||||||
|  |         expect(jsonMock.mock.lastCall![0]).toStrictEqual(expectedResult); | ||||||
| 	}); | 	}); | ||||||
| 
 | 
 | ||||||
| 	it('should return a list of submissions for a learning object', async () => { | 	it('should return a list of submissions for a learning object', async () => { | ||||||
| 		req = createRequestObject('id01', 'irrelevant'); | 		req = createRequestObject('id02', 'irrelevant'); | ||||||
| 
 | 
 | ||||||
|  | 		await getAllSubmissionsHandler(req as Request, res as Response); | ||||||
|  | 
 | ||||||
|  | 		checkReturnList(jsonMock, 'submissions', 2); | ||||||
| 	}); | 	}); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Adriaan Jacquet
						Adriaan Jacquet