Merge remote-tracking branch 'origin/feature/own-learning-objects' into feature/own-learning-objects
This commit is contained in:
		
						commit
						7af1404088
					
				
					 3 changed files with 57 additions and 60 deletions
				
			
		|  | @ -1,17 +1,12 @@ | |||
| import {LearningObjectProvider} from "./learning-object-provider"; | ||||
| import { | ||||
|     FilteredLearningObject, | ||||
|     LearningObjectIdentifier, | ||||
|     LearningPathIdentifier | ||||
| } from "../../interfaces/learning-content"; | ||||
| import {getLearningObjectRepository, getLearningPathRepository} from "../../data/repositories"; | ||||
| import {Language} from "../../entities/content/language"; | ||||
| import {LearningObject} from "../../entities/content/learning-object.entity"; | ||||
| import {getUrlStringForLearningObject} from "../../util/links"; | ||||
| import processingService from "./processing/processing-service"; | ||||
| import {NotFoundError} from "@mikro-orm/core"; | ||||
| import learningObjectService from "./learning-object-service"; | ||||
| 
 | ||||
| import { LearningObjectProvider } from './learning-object-provider'; | ||||
| import { FilteredLearningObject, LearningObjectIdentifier, LearningPathIdentifier } from '../../interfaces/learning-content'; | ||||
| import { getLearningObjectRepository, getLearningPathRepository } from '../../data/repositories'; | ||||
| import { Language } from '../../entities/content/language'; | ||||
| import { LearningObject } from '../../entities/content/learning-object.entity'; | ||||
| import { getUrlStringForLearningObject } from '../../util/links'; | ||||
| import processingService from './processing/processing-service'; | ||||
| import { NotFoundError } from '@mikro-orm/core'; | ||||
| import learningObjectService from './learning-object-service'; | ||||
| 
 | ||||
| function convertLearningObject(learningObject: LearningObject | null): FilteredLearningObject | null { | ||||
|     if (!learningObject) { | ||||
|  | @ -110,8 +105,8 @@ const databaseLearningObjectProvider: LearningObjectProvider = { | |||
|                 return learningObject; | ||||
|             }) | ||||
|         ); | ||||
|         return learningObjects.filter(it => it !== null); | ||||
|     } | ||||
|         return learningObjects.filter((it) => it !== null); | ||||
|     }, | ||||
| }; | ||||
| 
 | ||||
| export default databaseLearningObjectProvider; | ||||
|  |  | |||
|  | @ -1 +1 @@ | |||
| type PointOfView = {type: "student", student: Student} | {type: "group", group: Group}; | ||||
| type PointOfView = { type: 'student'; student: Student } | { type: 'group'; group: Group }; | ||||
|  |  | |||
|  | @ -1,27 +1,27 @@ | |||
| import {beforeAll, describe, expect, it} from "vitest"; | ||||
| import {setupTestApp} from "../../setup-tests"; | ||||
| import {getLearningObjectRepository, getLearningPathRepository} from "../../../src/data/repositories"; | ||||
| import example from "../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example"; | ||||
| import {LearningObject} from "../../../src/entities/content/learning-object.entity"; | ||||
| import databaseLearningObjectProvider from "../../../src/services/learning-objects/database-learning-object-provider"; | ||||
| import {expectToBeCorrectFilteredLearningObject} from "../../test-utils/expectations"; | ||||
| import {FilteredLearningObject} from "../../../src/interfaces/learning-content"; | ||||
| import {Language} from "../../../src/entities/content/language"; | ||||
| import learningObjectExample from "../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example"; | ||||
| import learningPathExample from "../../test-assets/learning-paths/pn-werking-example"; | ||||
| import {LearningPath} from "../../../src/entities/content/learning-path.entity"; | ||||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { getLearningObjectRepository, getLearningPathRepository } from '../../../src/data/repositories'; | ||||
| import example from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example'; | ||||
| import { LearningObject } from '../../../src/entities/content/learning-object.entity'; | ||||
| import databaseLearningObjectProvider from '../../../src/services/learning-objects/database-learning-object-provider'; | ||||
| import { expectToBeCorrectFilteredLearningObject } from '../../test-utils/expectations'; | ||||
| import { FilteredLearningObject } from '../../../src/interfaces/learning-content'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import learningObjectExample from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example'; | ||||
| import learningPathExample from '../../test-assets/learning-paths/pn-werking-example'; | ||||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity'; | ||||
| 
 | ||||
| async function initExampleData(): Promise<{learningObject: LearningObject, learningPath: LearningPath}> { | ||||
| async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> { | ||||
|     const learningObjectRepo = getLearningObjectRepository(); | ||||
|     const learningPathRepo = getLearningPathRepository(); | ||||
|     let learningObject = learningObjectExample.createLearningObject(); | ||||
|     let learningPath = learningPathExample.createLearningPath(); | ||||
|     const learningObject = learningObjectExample.createLearningObject(); | ||||
|     const learningPath = learningPathExample.createLearningPath(); | ||||
|     await learningObjectRepo.save(learningObject); | ||||
|     await learningPathRepo.save(learningPath); | ||||
|     return { learningObject, learningPath }; | ||||
| } | ||||
| 
 | ||||
| const EXPECTED_TITLE_FROM_DWENGO_LEARNING_OBJECT = "Notebook opslaan"; | ||||
| const EXPECTED_TITLE_FROM_DWENGO_LEARNING_OBJECT = 'Notebook opslaan'; | ||||
| 
 | ||||
| describe('DatabaseLearningObjectProvider', () => { | ||||
|     let exampleLearningObject: LearningObject; | ||||
|  | @ -29,7 +29,7 @@ describe('DatabaseLearningObjectProvider', () => { | |||
| 
 | ||||
|     beforeAll(async () => { | ||||
|         await setupTestApp(); | ||||
|         let exampleData = await initExampleData(); | ||||
|         const exampleData = await initExampleData(); | ||||
|         exampleLearningObject = exampleData.learningObject; | ||||
|         exampleLearningPath = exampleData.learningPath; | ||||
|     }); | ||||
|  | @ -62,45 +62,47 @@ describe('DatabaseLearningObjectProvider', () => { | |||
|             const result = await databaseLearningObjectProvider.getLearningObjectHTML(exampleLearningObject); | ||||
|             expect(result).toEqual(example.getHTMLRendering()); | ||||
|         }); | ||||
|         it("should return null for a non-existing learning object", async () => { | ||||
|         it('should return null for a non-existing learning object', async () => { | ||||
|             const result = await databaseLearningObjectProvider.getLearningObjectHTML({ | ||||
|                 hruid: "non_existing_hruid", | ||||
|                 language: Language.Dutch | ||||
|                 hruid: 'non_existing_hruid', | ||||
|                 language: Language.Dutch, | ||||
|             }); | ||||
|             expect(result).toBeNull(); | ||||
|         }); | ||||
|     }); | ||||
|     describe("getLearningObjectIdsFromPath", () => { | ||||
|         it("should return all learning object IDs from a path", async () => { | ||||
|     describe('getLearningObjectIdsFromPath', () => { | ||||
|         it('should return all learning object IDs from a path', async () => { | ||||
|             const result = await databaseLearningObjectProvider.getLearningObjectIdsFromPath(exampleLearningPath); | ||||
|             expect(new Set(result)) | ||||
|                 .toEqual(new Set(exampleLearningPath.nodes.map(it => it.learningObjectHruid))); | ||||
|             expect(new Set(result)).toEqual(new Set(exampleLearningPath.nodes.map((it) => it.learningObjectHruid))); | ||||
|         }); | ||||
|         it("should throw an error if queried with a path identifier for which there is no learning path", async () => { | ||||
|             await expect((async () => { | ||||
|         it('should throw an error if queried with a path identifier for which there is no learning path', async () => { | ||||
|             await expect( | ||||
|                 (async () => { | ||||
|                     await databaseLearningObjectProvider.getLearningObjectIdsFromPath({ | ||||
|                     hruid: "non_existing_hruid", | ||||
|                     language: Language.Dutch | ||||
|                         hruid: 'non_existing_hruid', | ||||
|                         language: Language.Dutch, | ||||
|                     }); | ||||
|             })()).rejects.toThrowError(); | ||||
|                 })() | ||||
|             ).rejects.toThrowError(); | ||||
|         }); | ||||
|     }); | ||||
|     describe("getLearningObjectsFromPath", () => { | ||||
|         it("should correctly return all learning objects which are on the path, even those who are not in the database", async () => { | ||||
|     describe('getLearningObjectsFromPath', () => { | ||||
|         it('should correctly return all learning objects which are on the path, even those who are not in the database', async () => { | ||||
|             const result = await databaseLearningObjectProvider.getLearningObjectsFromPath(exampleLearningPath); | ||||
|             expect(result.length).toBe(exampleLearningPath.nodes.length); | ||||
|             expect(new Set(result.map(it => it.key))) | ||||
|                 .toEqual(new Set(exampleLearningPath.nodes.map(it => it.learningObjectHruid))); | ||||
|             expect(new Set(result.map((it) => it.key))).toEqual(new Set(exampleLearningPath.nodes.map((it) => it.learningObjectHruid))); | ||||
| 
 | ||||
|             expect(result.map(it => it.title)).toContainEqual(EXPECTED_TITLE_FROM_DWENGO_LEARNING_OBJECT); | ||||
|             expect(result.map((it) => it.title)).toContainEqual(EXPECTED_TITLE_FROM_DWENGO_LEARNING_OBJECT); | ||||
|         }); | ||||
|         it("should throw an error if queried with a path identifier for which there is no learning path", async () => { | ||||
|             await expect((async () => { | ||||
|         it('should throw an error if queried with a path identifier for which there is no learning path', async () => { | ||||
|             await expect( | ||||
|                 (async () => { | ||||
|                     await databaseLearningObjectProvider.getLearningObjectsFromPath({ | ||||
|                     hruid: "non_existing_hruid", | ||||
|                     language: Language.Dutch | ||||
|                         hruid: 'non_existing_hruid', | ||||
|                         language: Language.Dutch, | ||||
|                     }); | ||||
|             })()).rejects.toThrowError(); | ||||
|                 })() | ||||
|             ).rejects.toThrowError(); | ||||
|         }); | ||||
|     }); | ||||
| }); | ||||
|  |  | |||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger