test(frontend): searchLearningPathsByAdmin
This commit is contained in:
		
							parent
							
								
									1639fbdabf
								
							
						
					
					
						commit
						965ba5dd20
					
				
					 2 changed files with 30 additions and 1 deletions
				
			
		|  | @ -14,11 +14,14 @@ import { | ||||||
|     testLearningObjectEssayQuestion, |     testLearningObjectEssayQuestion, | ||||||
|     testLearningObjectMultipleChoice, |     testLearningObjectMultipleChoice, | ||||||
| } from '../../test_assets/content/learning-objects.testdata'; | } from '../../test_assets/content/learning-objects.testdata'; | ||||||
| import { testLearningPathWithConditions } from '../../test_assets/content/learning-paths.testdata'; | import { testLearningPath02, testLearningPathWithConditions } from '../../test_assets/content/learning-paths.testdata'; | ||||||
| import { mapToLearningPath } from '../../../src/services/learning-paths/learning-path-service'; | import { mapToLearningPath } from '../../../src/services/learning-paths/learning-path-service'; | ||||||
| import { getTestGroup01, getTestGroup02 } from '../../test_assets/assignments/groups.testdata'; | import { getTestGroup01, getTestGroup02 } from '../../test_assets/assignments/groups.testdata'; | ||||||
| import { Group } from '../../../src/entities/assignments/group.entity.js'; | import { Group } from '../../../src/entities/assignments/group.entity.js'; | ||||||
|  | import { Teacher } from '../../../src/entities/users/teacher.entity.js'; | ||||||
| import { RequiredEntityData } from '@mikro-orm/core'; | import { RequiredEntityData } from '@mikro-orm/core'; | ||||||
|  | import { getFooFighters, getLimpBizkit } from '../../test_assets/users/teachers.testdata'; | ||||||
|  | import { mapToTeacherDTO } from '../../../src/interfaces/teacher'; | ||||||
| 
 | 
 | ||||||
| function expectBranchingObjectNode(result: LearningPathResponse): LearningObjectNode { | function expectBranchingObjectNode(result: LearningPathResponse): LearningObjectNode { | ||||||
|     const branchingObjectMatches = result.data![0].nodes.filter((it) => it.learningobject_hruid === testLearningObjectMultipleChoice.hruid); |     const branchingObjectMatches = result.data![0].nodes.filter((it) => it.learningobject_hruid === testLearningObjectMultipleChoice.hruid); | ||||||
|  | @ -33,6 +36,8 @@ describe('DatabaseLearningPathProvider', () => { | ||||||
|     let finalLearningObject: RequiredEntityData<LearningObject>; |     let finalLearningObject: RequiredEntityData<LearningObject>; | ||||||
|     let groupA: Group; |     let groupA: Group; | ||||||
|     let groupB: Group; |     let groupB: Group; | ||||||
|  |     let teacherA: Teacher; | ||||||
|  |     let teacherB: Teacher; | ||||||
| 
 | 
 | ||||||
|     beforeAll(async () => { |     beforeAll(async () => { | ||||||
|         await setupTestApp(); |         await setupTestApp(); | ||||||
|  | @ -42,6 +47,8 @@ describe('DatabaseLearningPathProvider', () => { | ||||||
|         finalLearningObject = testLearningObjectEssayQuestion; |         finalLearningObject = testLearningObjectEssayQuestion; | ||||||
|         groupA = getTestGroup01(); |         groupA = getTestGroup01(); | ||||||
|         groupB = getTestGroup02(); |         groupB = getTestGroup02(); | ||||||
|  |         teacherA = getFooFighters(); | ||||||
|  |         teacherB = getLimpBizkit(); | ||||||
| 
 | 
 | ||||||
|         // Place different submissions for group A and B.
 |         // Place different submissions for group A and B.
 | ||||||
|         const submissionRepo = getSubmissionRepository(); |         const submissionRepo = getSubmissionRepository(); | ||||||
|  | @ -140,4 +147,24 @@ describe('DatabaseLearningPathProvider', () => { | ||||||
|             expect(result.length).toBe(0); |             expect(result.length).toBe(0); | ||||||
|         }); |         }); | ||||||
|     }); |     }); | ||||||
|  | 
 | ||||||
|  |     describe('searchLearningPathsByAdmin', () => { | ||||||
|  |         it('returns the learning path owned by the admin', async () => { | ||||||
|  |             const expectedLearningPath = mapToLearningPath(testLearningPath02, [mapToTeacherDTO(teacherB)]); | ||||||
|  |             const result = await databaseLearningPathProvider.searchLearningPathsByAdmin( | ||||||
|  |                 [teacherB], | ||||||
|  |                 expectedLearningPath.language | ||||||
|  |             ); | ||||||
|  |             expect(result.length).toBe(1); | ||||||
|  |             expect(result[0].title).toBe(expectedLearningPath.title); | ||||||
|  |             expect(result[0].description).toBe(expectedLearningPath.description); | ||||||
|  |         }); | ||||||
|  |         it('returns an empty result when querying admins that do not have custom learning paths', async() => { | ||||||
|  |             const result = await databaseLearningPathProvider.searchLearningPathsByAdmin( | ||||||
|  |                 [teacherA], | ||||||
|  |                 testLearningPath.language | ||||||
|  |             ); | ||||||
|  |             expect(result.length).toBe(0); | ||||||
|  |         }); | ||||||
|  |     }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -14,10 +14,12 @@ import { | ||||||
|     testLearningObjectMultipleChoice, |     testLearningObjectMultipleChoice, | ||||||
|     testLearningObjectPnNotebooks, |     testLearningObjectPnNotebooks, | ||||||
| } from './learning-objects.testdata'; | } from './learning-objects.testdata'; | ||||||
|  | import { getLimpBizkit } from '../users/teachers.testdata'; | ||||||
| 
 | 
 | ||||||
| export function makeTestLearningPaths(_em: EntityManager): LearningPath[] { | export function makeTestLearningPaths(_em: EntityManager): LearningPath[] { | ||||||
|     const learningPath01 = mapToLearningPath(testLearningPath01, []); |     const learningPath01 = mapToLearningPath(testLearningPath01, []); | ||||||
|     const learningPath02 = mapToLearningPath(testLearningPath02, []); |     const learningPath02 = mapToLearningPath(testLearningPath02, []); | ||||||
|  |     learningPath02.admins = [getLimpBizkit()]; | ||||||
| 
 | 
 | ||||||
|     const partiallyDatabasePartiallyDwengoApiLearningPath = mapToLearningPath(testPartiallyDatabaseAndPartiallyDwengoApiLearningPath, []); |     const partiallyDatabasePartiallyDwengoApiLearningPath = mapToLearningPath(testPartiallyDatabaseAndPartiallyDwengoApiLearningPath, []); | ||||||
|     const learningPathWithConditions = mapToLearningPath(testLearningPathWithConditions, []); |     const learningPathWithConditions = mapToLearningPath(testLearningPathWithConditions, []); | ||||||
|  |  | ||||||
		Reference in a new issue