fix(backend): Testen LearningObjectService gerepareerd na refactoring.
This commit is contained in:
		
							parent
							
								
									51268af79c
								
							
						
					
					
						commit
						1815371a7b
					
				
					 1 changed files with 28 additions and 25 deletions
				
			
		|  | @ -1,14 +1,20 @@ | ||||||
| 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 { LearningObject } from '../../../src/entities/content/learning-object.entity'; | import { LearningObject } from '../../../src/entities/content/learning-object.entity'; | ||||||
| import { getLearningObjectRepository, getLearningPathRepository } from '../../../src/data/repositories'; |  | ||||||
| import learningObjectExample from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example'; |  | ||||||
| import learningObjectService from '../../../src/services/learning-objects/learning-object-service'; | import learningObjectService from '../../../src/services/learning-objects/learning-object-service'; | ||||||
| import { envVars, getEnvVar } from '../../../src/util/envVars'; | import { envVars, getEnvVar } from '../../../src/util/envVars'; | ||||||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity'; | import { | ||||||
| import learningPathExample from '../../test-assets/learning-paths/pn-werking-example'; |     LearningObjectIdentifierDTO, | ||||||
| import { LearningObjectIdentifierDTO, LearningPathIdentifier } from '@dwengo-1/common/interfaces/learning-content'; |     LearningPath as LearningPathDTO, | ||||||
|  |     LearningPathIdentifier | ||||||
|  | } from '@dwengo-1/common/interfaces/learning-content'; | ||||||
| import { Language } from '@dwengo-1/common/util/language'; | import { Language } from '@dwengo-1/common/util/language'; | ||||||
|  | import {testLearningObjectPnNotebooks} from "../../test_assets/content/learning-objects.testdata"; | ||||||
|  | import { | ||||||
|  |     testPartiallyDatabaseAndPartiallyDwengoApiLearningPath | ||||||
|  | } from "../../test_assets/content/learning-paths.testdata"; | ||||||
|  | import {RequiredEntityData} from "@mikro-orm/core"; | ||||||
|  | import {getHtmlRenderingForTestLearningObject} from "../../test-utils/get-html-rendering"; | ||||||
| 
 | 
 | ||||||
| const EXPECTED_DWENGO_LEARNING_OBJECT_TITLE = 'Werken met notebooks'; | const EXPECTED_DWENGO_LEARNING_OBJECT_TITLE = 'Werken met notebooks'; | ||||||
| const DWENGO_TEST_LEARNING_OBJECT_ID: LearningObjectIdentifierDTO = { | const DWENGO_TEST_LEARNING_OBJECT_ID: LearningObjectIdentifierDTO = { | ||||||
|  | @ -23,25 +29,20 @@ const DWENGO_TEST_LEARNING_PATH_ID: LearningPathIdentifier = { | ||||||
| }; | }; | ||||||
| const DWENGO_TEST_LEARNING_PATH_HRUIDS = new Set(['pn_werkingnotebooks', 'pn_werkingnotebooks2', 'pn_werkingnotebooks3']); | const DWENGO_TEST_LEARNING_PATH_HRUIDS = new Set(['pn_werkingnotebooks', 'pn_werkingnotebooks2', 'pn_werkingnotebooks3']); | ||||||
| 
 | 
 | ||||||
| async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> { |  | ||||||
|     const learningObjectRepo = getLearningObjectRepository(); |  | ||||||
|     const learningPathRepo = getLearningPathRepository(); |  | ||||||
|     const learningObject = learningObjectExample.createLearningObject(); |  | ||||||
|     const learningPath = learningPathExample.createLearningPath(); |  | ||||||
|     await learningObjectRepo.save(learningObject); |  | ||||||
|     await learningPathRepo.save(learningPath); |  | ||||||
|     return { learningObject, learningPath }; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| describe('LearningObjectService', () => { | describe('LearningObjectService', () => { | ||||||
|     let exampleLearningObject: LearningObject; |     let exampleLearningObject: RequiredEntityData<LearningObject>; | ||||||
|     let exampleLearningPath: LearningPath; |     let exampleLearningPath: LearningPathDTO; | ||||||
|  |     let exampleLearningPathId: LearningPathIdentifier; | ||||||
| 
 | 
 | ||||||
|     beforeAll(async () => { |     beforeAll(async () => { | ||||||
|         await setupTestApp(); |         await setupTestApp(); | ||||||
|         const exampleData = await initExampleData(); |         exampleLearningObject = testLearningObjectPnNotebooks; | ||||||
|         exampleLearningObject = exampleData.learningObject; |         exampleLearningPath = testPartiallyDatabaseAndPartiallyDwengoApiLearningPath; | ||||||
|         exampleLearningPath = exampleData.learningPath; | 
 | ||||||
|  |         exampleLearningPathId = { | ||||||
|  |             hruid: exampleLearningPath.hruid, | ||||||
|  |             language: exampleLearningPath.language as Language | ||||||
|  |         } | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     describe('getLearningObjectById', () => { |     describe('getLearningObjectById', () => { | ||||||
|  | @ -69,7 +70,7 @@ describe('LearningObjectService', () => { | ||||||
|             const result = await learningObjectService.getLearningObjectHTML(exampleLearningObject); |             const result = await learningObjectService.getLearningObjectHTML(exampleLearningObject); | ||||||
|             expect(result).not.toBeNull(); |             expect(result).not.toBeNull(); | ||||||
|             // Set newlines so your tests are platform-independent.
 |             // Set newlines so your tests are platform-independent.
 | ||||||
|             expect(result).toEqual(learningObjectExample.getHTMLRendering().replace(/\r\n/g, '\n')); |             expect(result).toEqual(getHtmlRenderingForTestLearningObject(exampleLearningObject).replace(/\r\n/g, '\n')); | ||||||
|         }); |         }); | ||||||
|         it( |         it( | ||||||
|             'returns the same HTML as the Dwengo API when queried with the identifier of a learning object that does ' + |             'returns the same HTML as the Dwengo API when queried with the identifier of a learning object that does ' + | ||||||
|  | @ -97,8 +98,10 @@ describe('LearningObjectService', () => { | ||||||
| 
 | 
 | ||||||
|     describe('getLearningObjectsFromPath', () => { |     describe('getLearningObjectsFromPath', () => { | ||||||
|         it('returns all learning objects when a learning path in the database is queried', async () => { |         it('returns all learning objects when a learning path in the database is queried', async () => { | ||||||
|             const result = await learningObjectService.getLearningObjectsFromPath(exampleLearningPath); |             const result = await learningObjectService.getLearningObjectsFromPath(exampleLearningPathId); | ||||||
|             expect(result.map((it) => it.key)).toEqual(exampleLearningPath.nodes.map((it) => it.learningObjectHruid)); |             expect(result.map(it=> it.key)).toEqual( | ||||||
|  |                 exampleLearningPath.nodes.map(it => it.learningobject_hruid) | ||||||
|  |             ); | ||||||
|         }); |         }); | ||||||
|         it('also returns all learning objects when a learning path from the Dwengo API is queried', async () => { |         it('also returns all learning objects when a learning path from the Dwengo API is queried', async () => { | ||||||
|             const result = await learningObjectService.getLearningObjectsFromPath(DWENGO_TEST_LEARNING_PATH_ID); |             const result = await learningObjectService.getLearningObjectsFromPath(DWENGO_TEST_LEARNING_PATH_ID); | ||||||
|  | @ -115,8 +118,8 @@ describe('LearningObjectService', () => { | ||||||
| 
 | 
 | ||||||
|     describe('getLearningObjectIdsFromPath', () => { |     describe('getLearningObjectIdsFromPath', () => { | ||||||
|         it('returns all learning objects when a learning path in the database is queried', async () => { |         it('returns all learning objects when a learning path in the database is queried', async () => { | ||||||
|             const result = await learningObjectService.getLearningObjectIdsFromPath(exampleLearningPath); |             const result = await learningObjectService.getLearningObjectIdsFromPath(exampleLearningPathId); | ||||||
|             expect(result).toEqual(exampleLearningPath.nodes.map((it) => it.learningObjectHruid)); |             expect(result).toEqual(exampleLearningPath.nodes.map(it => it.learningobject_hruid)); | ||||||
|         }); |         }); | ||||||
|         it('also returns all learning object hruids when a learning path from the Dwengo API is queried', async () => { |         it('also returns all learning object hruids when a learning path from the Dwengo API is queried', async () => { | ||||||
|             const result = await learningObjectService.getLearningObjectIdsFromPath(DWENGO_TEST_LEARNING_PATH_ID); |             const result = await learningObjectService.getLearningObjectIdsFromPath(DWENGO_TEST_LEARNING_PATH_ID); | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger