test: questions data
This commit is contained in:
		
							parent
							
								
									5eaa93e18f
								
							
						
					
					
						commit
						49449b90be
					
				
					 2 changed files with 51 additions and 35 deletions
				
			
		|  | @ -1,45 +1,51 @@ | ||||||
| import { beforeAll, describe, expect, it } from 'vitest'; | import { beforeAll, describe, expect, it } from 'vitest'; | ||||||
| import { setupTestApp } from '../../setup-tests'; | import { setupTestApp } from '../../setup-tests'; | ||||||
| import { QuestionRepository } from '../../../src/data/questions/question-repository'; | import { QuestionRepository } from '../../../src/data/questions/question-repository'; | ||||||
| import { | import { getQuestionRepository } from '../../../src/data/repositories'; | ||||||
|     getAssignmentRepository, |  | ||||||
|     getClassRepository, |  | ||||||
|     getGroupRepository, |  | ||||||
|     getQuestionRepository, |  | ||||||
|     getStudentRepository, |  | ||||||
| } from '../../../src/data/repositories'; |  | ||||||
| import { StudentRepository } from '../../../src/data/users/student-repository'; |  | ||||||
| import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier'; | 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 { Question } from '../../../src/entities/questions/question.entity'; | ||||||
| import { Class } from '../../../src/entities/classes/class.entity'; | import { testLearningObject03, testLearningObject05 } from '../../test_assets/content/learning-objects.testdata'; | ||||||
| import { Assignment } from '../../../src/entities/assignments/assignment.entity'; | import { getQuestion01, getQuestion02, getQuestion03, getQuestion05, getQuestion06 } from '../../test_assets/questions/questions.testdata'; | ||||||
|  | import { getNoordkaap, getTool } from '../../test_assets/users/students.testdata'; | ||||||
|  | import { getAssignment01 } from '../../test_assets/assignments/assignments.testdata'; | ||||||
|  | import { getTestGroup01 } from '../../test_assets/assignments/groups.testdata'; | ||||||
| 
 | 
 | ||||||
| describe('QuestionRepository', () => { | describe('QuestionRepository', () => { | ||||||
|     let questionRepository: QuestionRepository; |     let questionRepository: QuestionRepository; | ||||||
|     let studentRepository: StudentRepository; |  | ||||||
| 
 | 
 | ||||||
|     beforeAll(async () => { |     beforeAll(async () => { | ||||||
|         await setupTestApp(); |         await setupTestApp(); | ||||||
|         questionRepository = getQuestionRepository(); |         questionRepository = getQuestionRepository(); | ||||||
|         studentRepository = getStudentRepository(); |  | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('should return all questions part of the given learning object', async () => { |     it('should return all questions part of the given learning object', async () => { | ||||||
|         const id = new LearningObjectIdentifier('id05', Language.English, 1); |         const q1 = getQuestion01(); | ||||||
|         const questions = await questionRepository.findAllQuestionsAboutLearningObject(id); |         const q2 = getQuestion02(); | ||||||
|  |         const q3 = getQuestion05(); | ||||||
|  |         const q4 = getQuestion06(); | ||||||
|  |         const loid = { | ||||||
|  |             hruid: q1.learningObjectHruid, | ||||||
|  |             language: q1.learningObjectLanguage, | ||||||
|  |             version: q1.learningObjectVersion, | ||||||
|  |         } as LearningObjectIdentifier; | ||||||
|  |         const questions = await questionRepository.findAllQuestionsAboutLearningObject(loid); | ||||||
| 
 | 
 | ||||||
|         expect(questions).toBeTruthy(); |         expect(questions).toBeTruthy(); | ||||||
|         expect(questions).toHaveLength(4); |         expect(questions).toHaveLength(4); | ||||||
|  |         expect(questions[0].sequenceNumber!).toBeOneOf([q1.sequenceNumber, q2.sequenceNumber, q3.sequenceNumber, q4.sequenceNumber]); | ||||||
|  |         expect(questions[1].sequenceNumber!).toBeOneOf([q1.sequenceNumber, q2.sequenceNumber, q3.sequenceNumber, q4.sequenceNumber]); | ||||||
|  |         expect(questions[2].sequenceNumber!).toBeOneOf([q1.sequenceNumber, q2.sequenceNumber, q3.sequenceNumber, q4.sequenceNumber]); | ||||||
|  |         expect(questions[3].sequenceNumber!).toBeOneOf([q1.sequenceNumber, q2.sequenceNumber, q3.sequenceNumber, q4.sequenceNumber]); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('should create new question', async () => { |     it('should create new question', async () => { | ||||||
|         const id = new LearningObjectIdentifier('id03', Language.English, 1); |         const id = { | ||||||
|         const student = await studentRepository.findByUsername('Noordkaap'); |             hruid: testLearningObject03.hruid, | ||||||
| 
 |             language: testLearningObject03.language, | ||||||
|         const clazz = await getClassRepository().findById('8764b861-90a6-42e5-9732-c0d9eb2f55f9'); |             version: testLearningObject03.version, | ||||||
|         const assignment = await getAssignmentRepository().findByClassAndId(clazz!, 21000); |         } as LearningObjectIdentifier; | ||||||
|         const group = await getGroupRepository().findByAssignmentAndGroupNumber(assignment!, 21001); |         const student = getNoordkaap(); | ||||||
|  |         const group = getTestGroup01(); | ||||||
|         await questionRepository.createQuestion({ |         await questionRepository.createQuestion({ | ||||||
|             loId: id, |             loId: id, | ||||||
|             inGroup: group!, |             inGroup: group!, | ||||||
|  | @ -50,18 +56,15 @@ describe('QuestionRepository', () => { | ||||||
| 
 | 
 | ||||||
|         expect(question).toBeTruthy(); |         expect(question).toBeTruthy(); | ||||||
|         expect(question).toHaveLength(1); |         expect(question).toHaveLength(1); | ||||||
|  |         expect(question[0].content).toBe('question?'); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     let clazz: Class | null; |  | ||||||
|     let assignment: Assignment | null; |  | ||||||
|     let loId: LearningObjectIdentifier; |  | ||||||
|     it('should find all questions for a certain learning object and assignment', async () => { |     it('should find all questions for a certain learning object and assignment', async () => { | ||||||
|         clazz = await getClassRepository().findById('8764b861-90a6-42e5-9732-c0d9eb2f55f9'); |         const assignment = getAssignment01(); | ||||||
|         assignment = await getAssignmentRepository().findByClassAndId(clazz!, 21000); |         const loId = { | ||||||
|         loId = { |             hruid: testLearningObject05.hruid, | ||||||
|             hruid: 'id05', |             language: testLearningObject05.language, | ||||||
|             language: Language.English, |             version: testLearningObject05.version, | ||||||
|             version: 1, |  | ||||||
|         }; |         }; | ||||||
|         const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!); |         const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!); | ||||||
|         sortQuestions(result); |         sortQuestions(result); | ||||||
|  | @ -84,7 +87,14 @@ describe('QuestionRepository', () => { | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it("should find only the questions for a certain learning object and assignment asked by the user's group", async () => { |     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'); |         const loId = { | ||||||
|  |             hruid: testLearningObject05.hruid, | ||||||
|  |             language: testLearningObject05.language, | ||||||
|  |             version: testLearningObject05.version, | ||||||
|  |         }; | ||||||
|  |         const assignment = getAssignment01(); | ||||||
|  | 
 | ||||||
|  |         const result = await questionRepository.findAllQuestionsAboutLearningObjectInAssignment(loId, assignment!, getTool().username); | ||||||
|         // (student Tool is in group #2)
 |         // (student Tool is in group #2)
 | ||||||
| 
 | 
 | ||||||
|         expect(result).toHaveLength(1); |         expect(result).toHaveLength(1); | ||||||
|  | @ -99,12 +109,17 @@ describe('QuestionRepository', () => { | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('should not find removed question', async () => { |     it('should not find removed question', async () => { | ||||||
|         const id = new LearningObjectIdentifier('id04', Language.English, 1); |         const usedQuestion = getQuestion03(); | ||||||
|         await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(id, 1); |         const id = { | ||||||
|  |             hruid: usedQuestion.learningObjectHruid, | ||||||
|  |             language: usedQuestion.learningObjectLanguage, | ||||||
|  |             version: usedQuestion.learningObjectVersion, | ||||||
|  |         } as LearningObjectIdentifier; | ||||||
|  |         await questionRepository.removeQuestionByLearningObjectAndSequenceNumber(id, usedQuestion.sequenceNumber!); | ||||||
| 
 | 
 | ||||||
|         const question = await questionRepository.findAllQuestionsAboutLearningObject(id); |         const questions = await questionRepository.findAllQuestionsAboutLearningObject(id); | ||||||
| 
 | 
 | ||||||
|         expect(question).toHaveLength(0); |         expect(questions).toHaveLength(0); | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,6 +27,7 @@ export function makeTestQuestions(em: EntityManager): Question[] { | ||||||
|         content: 'question', |         content: 'question', | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|  |     //gets deleted
 | ||||||
|     question03 = em.create(Question, { |     question03 = em.create(Question, { | ||||||
|         learningObjectLanguage: testLearningObject04.language, |         learningObjectLanguage: testLearningObject04.language, | ||||||
|         learningObjectVersion: testLearningObject04.version, |         learningObjectVersion: testLearningObject04.version, | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 laurejablonski
						laurejablonski