feat(backend): Testen voor nieuwe functie in QuestionRepository toegevoegd.
This commit is contained in:
		
							parent
							
								
									c863dc627f
								
							
						
					
					
						commit
						d21377cda4
					
				
					 2 changed files with 86 additions and 6 deletions
				
			
		|  | @ -10,6 +10,9 @@ import { | |||
| import { StudentRepository } from '../../../src/data/users/student-repository'; | ||||
| import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier'; | ||||
| import { Language } from '@dwengo-1/common/util/language'; | ||||
| import {Question} from "../../../src/entities/questions/question.entity"; | ||||
| import {Class} from "../../../src/entities/classes/class.entity"; | ||||
| import {Assignment} from "../../../src/entities/assignments/assignment.entity"; | ||||
| 
 | ||||
| describe('QuestionRepository', () => { | ||||
|     let questionRepository: QuestionRepository; | ||||
|  | @ -26,7 +29,7 @@ describe('QuestionRepository', () => { | |||
|         const questions = await questionRepository.findAllQuestionsAboutLearningObject(id); | ||||
| 
 | ||||
|         expect(questions).toBeTruthy(); | ||||
|         expect(questions).toHaveLength(2); | ||||
|         expect(questions).toHaveLength(4); | ||||
|     }); | ||||
| 
 | ||||
|     it('should create new question', async () => { | ||||
|  | @ -48,6 +51,53 @@ describe('QuestionRepository', () => { | |||
|         expect(question).toHaveLength(1); | ||||
|     }); | ||||
| 
 | ||||
|     let clazz: Class | null; | ||||
|     let assignment: Assignment | null; | ||||
|     let loId: LearningObjectIdentifier; | ||||
|     it('should find all questions for a certain learning object and assignment', async () => { | ||||
|         clazz = await getClassRepository().findById('id01'); | ||||
|         assignment = await getAssignmentRepository().findByClassAndId(clazz!, 1); | ||||
|         loId = { | ||||
|             hruid: "id05", | ||||
|             language: Language.English, | ||||
|             version: 1 | ||||
|         }; | ||||
|         const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!); | ||||
|         sortQuestions(result); | ||||
| 
 | ||||
|         expect(result).toHaveLength(3); | ||||
| 
 | ||||
|         // question01: About learning object 'id05', in group #1 for Assignment #1 in class 'id01'
 | ||||
|         expect(result[0].learningObjectHruid).toEqual(loId.hruid); | ||||
|         expect(result[0].sequenceNumber).toEqual(1); | ||||
| 
 | ||||
|         // question02: About learning object 'id05', in group #1 for Assignment #1 in class 'id01'
 | ||||
|         expect(result[1].learningObjectHruid).toEqual(loId.hruid); | ||||
|         expect(result[1].sequenceNumber).toEqual(2); | ||||
| 
 | ||||
|         // question05: About learning object 'id05', in group #2 for Assignment #1 in class 'id01'
 | ||||
|         expect(result[2].learningObjectHruid).toEqual(loId.hruid); | ||||
|         expect(result[2].sequenceNumber).toEqual(3); | ||||
| 
 | ||||
|         // question06: About learning object 'id05', but for Assignment #2 in class 'id01' => not expected.
 | ||||
|     }); | ||||
| 
 | ||||
|     it("should find only the questions for a certain learning object and assignment asked by the user's group", async () => { | ||||
|         const result = | ||||
|             await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, "Tool"); | ||||
|         // (student Tool is in group #2)
 | ||||
| 
 | ||||
|         expect(result).toHaveLength(1); | ||||
| 
 | ||||
|         // question01 and question02 are in group #1 => not displayed.
 | ||||
| 
 | ||||
|         // question05: About learning object 'id05', in group #2 for Assignment #1 in class 'id01'
 | ||||
|         expect(result[0].learningObjectHruid).toEqual(loId.hruid); | ||||
|         expect(result[0].sequenceNumber).toEqual(3); | ||||
| 
 | ||||
|         // question06: About learning object 'id05', but for Assignment #2 in class 'id01' => not expected.
 | ||||
|     }); | ||||
| 
 | ||||
|     it('should not find removed question', async () => { | ||||
|         const id = new LearningObjectIdentifier('id04', Language.English, 1); | ||||
|         await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(id, 1); | ||||
|  | @ -57,3 +107,11 @@ describe('QuestionRepository', () => { | |||
|         expect(question).toHaveLength(0); | ||||
|     }); | ||||
| }); | ||||
| 
 | ||||
| function sortQuestions(questions: Question[]) { | ||||
|     questions.sort((a, b) => { | ||||
|         if (a.learningObjectHruid < b.learningObjectHruid) return -1 | ||||
|         else if (a.learningObjectHruid > b.learningObjectHruid) return 1 | ||||
|         else return a.sequenceNumber! - b.sequenceNumber! | ||||
|     }); | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger