style: fix linting issues met Prettier
This commit is contained in:
		
							parent
							
								
									aa1a85e64e
								
							
						
					
					
						commit
						2a2881ec30
					
				
					 84 changed files with 846 additions and 1013 deletions
				
			
		|  | @ -1,15 +1,13 @@ | |||
| import {beforeAll, describe, expect, it} from "vitest"; | ||||
| import {setupTestApp} from "../../setup-tests"; | ||||
| import {getLearningObjectRepository} 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 { | ||||
|     createExampleLearningObjectWithAttachments | ||||
| } from "../../test-assets/learning-objects/create-example-learning-object-with-attachments"; | ||||
| import {expectToBeCorrectFilteredLearningObject} from "../../test-utils/expectations"; | ||||
| import {FilteredLearningObject} from "../../../src/interfaces/learning-content"; | ||||
| import {Language} from "../../../src/entities/content/language"; | ||||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { getLearningObjectRepository } 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 { createExampleLearningObjectWithAttachments } from '../../test-assets/learning-objects/create-example-learning-object-with-attachments'; | ||||
| import { expectToBeCorrectFilteredLearningObject } from '../../test-utils/expectations'; | ||||
| import { FilteredLearningObject } from '../../../src/interfaces/learning-content'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| 
 | ||||
| async function initExampleData(): Promise<LearningObject> { | ||||
|     const learningObjectRepo = getLearningObjectRepository(); | ||||
|  | @ -18,39 +16,39 @@ async function initExampleData(): Promise<LearningObject> { | |||
|     return exampleLearningObject; | ||||
| } | ||||
| 
 | ||||
| describe("DatabaseLearningObjectProvider", () => { | ||||
| describe('DatabaseLearningObjectProvider', () => { | ||||
|     let exampleLearningObject: LearningObject; | ||||
| 
 | ||||
|     beforeAll(async () => { | ||||
|         await setupTestApp(); | ||||
|         exampleLearningObject = await initExampleData(); | ||||
|     }); | ||||
|     describe("getLearningObjectById", () => { | ||||
|         it("should return the learning object when it is queried by its id", async () => { | ||||
|     describe('getLearningObjectById', () => { | ||||
|         it('should return the learning object when it is queried by its id', async () => { | ||||
|             const result: FilteredLearningObject | null = await databaseLearningObjectProvider.getLearningObjectById(exampleLearningObject); | ||||
|             expect(result).toBeTruthy(); | ||||
|             expectToBeCorrectFilteredLearningObject(result!, exampleLearningObject); | ||||
|         }); | ||||
| 
 | ||||
|         it("should return the learning object when it is queried by only hruid and language (but not version)", async () => { | ||||
|         it('should return the learning object when it is queried by only hruid and language (but not version)', async () => { | ||||
|             const result: FilteredLearningObject | null = await databaseLearningObjectProvider.getLearningObjectById({ | ||||
|                 hruid: exampleLearningObject.hruid, | ||||
|                 language: exampleLearningObject.language | ||||
|                 language: exampleLearningObject.language, | ||||
|             }); | ||||
|             expect(result).toBeTruthy(); | ||||
|             expectToBeCorrectFilteredLearningObject(result!, exampleLearningObject); | ||||
|         }); | ||||
| 
 | ||||
|         it("should return null when queried with an id that does not exist", async () => { | ||||
|         it('should return null when queried with an id that does not exist', async () => { | ||||
|             const result: FilteredLearningObject | null = await databaseLearningObjectProvider.getLearningObjectById({ | ||||
|                 hruid: "non_existing_hruid", | ||||
|                 language: Language.Dutch | ||||
|                 hruid: 'non_existing_hruid', | ||||
|                 language: Language.Dutch, | ||||
|             }); | ||||
|             expect(result).toBeNull(); | ||||
|         }); | ||||
|     }); | ||||
|     describe("getLearningObjectHTML", () => { | ||||
|         it("should return the correct rendering of the learning object", async () => { | ||||
|     describe('getLearningObjectHTML', () => { | ||||
|         it('should return the correct rendering of the learning object', async () => { | ||||
|             const result = await databaseLearningObjectProvider.getLearningObjectHTML(exampleLearningObject); | ||||
|             expect(result).toEqual(example.getHTMLRendering()); | ||||
|         }); | ||||
|  |  | |||
|  | @ -1,30 +1,30 @@ | |||
| import {beforeAll, describe, expect, it} from "vitest"; | ||||
| import {setupTestApp} from "../../setup-tests"; | ||||
| import {LearningObject} from "../../../src/entities/content/learning-object.entity"; | ||||
| import {getLearningObjectRepository} 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 {LearningObjectIdentifier} from "../../../src/interfaces/learning-content"; | ||||
| import {Language} from "../../../src/entities/content/language"; | ||||
| import {EnvVars, getEnvVar} from "../../../src/util/envvars"; | ||||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { LearningObject } from '../../../src/entities/content/learning-object.entity'; | ||||
| import { getLearningObjectRepository } 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 { LearningObjectIdentifier } from '../../../src/interfaces/learning-content'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import { EnvVars, getEnvVar } from '../../../src/util/envvars'; | ||||
| 
 | ||||
| const TEST_LEARNING_OBJECT_TITLE = "Test title"; | ||||
| const EXPECTED_DWENGO_LEARNING_OBJECT_TITLE = "Werken met notebooks"; | ||||
| const TEST_LEARNING_OBJECT_TITLE = 'Test title'; | ||||
| const EXPECTED_DWENGO_LEARNING_OBJECT_TITLE = 'Werken met notebooks'; | ||||
| const DWENGO_TEST_LEARNING_OBJECT_ID: LearningObjectIdentifier = { | ||||
|     hruid: "pn_werkingnotebooks", | ||||
|     hruid: 'pn_werkingnotebooks', | ||||
|     language: Language.Dutch, | ||||
|     version: 3 | ||||
|     version: 3, | ||||
| }; | ||||
| 
 | ||||
| async function initExampleData(): Promise<LearningObject> { | ||||
|     const learningObjectRepo = getLearningObjectRepository(); | ||||
|     const learningObject = learningObjectExample.createLearningObject(); | ||||
|     learningObject.title = TEST_LEARNING_OBJECT_TITLE | ||||
|     learningObject.title = TEST_LEARNING_OBJECT_TITLE; | ||||
|     await learningObjectRepo.save(learningObject); | ||||
|     return learningObject; | ||||
| } | ||||
| 
 | ||||
| describe("LearningObjectService", () => { | ||||
| describe('LearningObjectService', () => { | ||||
|     let exampleLearningObject: LearningObject; | ||||
| 
 | ||||
|     beforeAll(async () => { | ||||
|  | @ -32,47 +32,50 @@ describe("LearningObjectService", () => { | |||
|         exampleLearningObject = await initExampleData(); | ||||
|     }); | ||||
| 
 | ||||
|     describe("getLearningObjectById", () => { | ||||
|         it("returns the learning object from the Dwengo API if it does not have the user content prefix", async () => { | ||||
|     describe('getLearningObjectById', () => { | ||||
|         it('returns the learning object from the Dwengo API if it does not have the user content prefix', async () => { | ||||
|             const result = await learningObjectService.getLearningObjectById(DWENGO_TEST_LEARNING_OBJECT_ID); | ||||
|             expect(result).not.toBeNull(); | ||||
|             expect(result?.title).toBe(EXPECTED_DWENGO_LEARNING_OBJECT_TITLE); | ||||
|         }); | ||||
|         it("returns the learning object from the database if it does have the user content prefix", async () => { | ||||
|         it('returns the learning object from the database if it does have the user content prefix', async () => { | ||||
|             const result = await learningObjectService.getLearningObjectById(exampleLearningObject); | ||||
|             expect(result).not.toBeNull(); | ||||
|             expect(result?.title).toBe(exampleLearningObject.title); | ||||
|         }); | ||||
|         it("returns null if the hruid does not have the user content prefix and does not exist in the Dwengo repo", async () => { | ||||
|         it('returns null if the hruid does not have the user content prefix and does not exist in the Dwengo repo', async () => { | ||||
|             const result = await learningObjectService.getLearningObjectById({ | ||||
|                 hruid: "non-existing", | ||||
|                 language: Language.Dutch | ||||
|                 hruid: 'non-existing', | ||||
|                 language: Language.Dutch, | ||||
|             }); | ||||
|             expect(result).toBeNull(); | ||||
|         }); | ||||
|     }); | ||||
| 
 | ||||
|     describe("getLearningObjectHTML", () => { | ||||
|         it("returns the expected HTML when queried with the identifier of a learning object saved in the database", async () => { | ||||
|     describe('getLearningObjectHTML', () => { | ||||
|         it('returns the expected HTML when queried with the identifier of a learning object saved in the database', async () => { | ||||
|             const result = await learningObjectService.getLearningObjectHTML(exampleLearningObject); | ||||
|             expect(result).not.toBeNull(); | ||||
|             expect(result).toEqual(learningObjectExample.getHTMLRendering()); | ||||
|         }); | ||||
|         it("returns the same HTML as the Dwengo API when queried with the identifier of a learning object that does " + | ||||
|             "not start with the user content prefix", async () => { | ||||
|             const result = await learningObjectService.getLearningObjectHTML(DWENGO_TEST_LEARNING_OBJECT_ID); | ||||
|             expect(result).not.toBeNull(); | ||||
|         it( | ||||
|             'returns the same HTML as the Dwengo API when queried with the identifier of a learning object that does ' + | ||||
|                 'not start with the user content prefix', | ||||
|             async () => { | ||||
|                 const result = await learningObjectService.getLearningObjectHTML(DWENGO_TEST_LEARNING_OBJECT_ID); | ||||
|                 expect(result).not.toBeNull(); | ||||
| 
 | ||||
|             const htmlFromDwengoApi = await fetch( | ||||
|                 getEnvVar(EnvVars.LearningContentRepoApiBaseUrl) | ||||
|                 + `/learningObject/getRaw?hruid=${DWENGO_TEST_LEARNING_OBJECT_ID.hruid}&language=${DWENGO_TEST_LEARNING_OBJECT_ID.language}&version=${DWENGO_TEST_LEARNING_OBJECT_ID.version}` | ||||
|             ).then(it => it.text()); | ||||
|             expect(result).toEqual(htmlFromDwengoApi); | ||||
|         }); | ||||
|         it("returns null when queried with a non-existing identifier", async () => { | ||||
|                 const htmlFromDwengoApi = await fetch( | ||||
|                     getEnvVar(EnvVars.LearningContentRepoApiBaseUrl) + | ||||
|                         `/learningObject/getRaw?hruid=${DWENGO_TEST_LEARNING_OBJECT_ID.hruid}&language=${DWENGO_TEST_LEARNING_OBJECT_ID.language}&version=${DWENGO_TEST_LEARNING_OBJECT_ID.version}` | ||||
|                 ).then((it) => it.text()); | ||||
|                 expect(result).toEqual(htmlFromDwengoApi); | ||||
|             } | ||||
|         ); | ||||
|         it('returns null when queried with a non-existing identifier', async () => { | ||||
|             const result = await learningObjectService.getLearningObjectHTML({ | ||||
|                 hruid: "non_existing_hruid", | ||||
|                 language: Language.Dutch | ||||
|                 hruid: 'non_existing_hruid', | ||||
|                 language: Language.Dutch, | ||||
|             }); | ||||
|             expect(result).toBeNull(); | ||||
|         }); | ||||
|  |  | |||
|  | @ -1,23 +1,23 @@ | |||
| import {describe, expect, it} from "vitest"; | ||||
| import mdExample from "../../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example"; | ||||
| import multipleChoiceExample from "../../../test-assets/learning-objects/test-multiple-choice/test-multiple-choice-example"; | ||||
| import essayExample from "../../../test-assets/learning-objects/test-essay/test-essay-example"; | ||||
| import processingService from "../../../../src/services/learning-objects/processing/processing-service"; | ||||
| import { describe, expect, it } from 'vitest'; | ||||
| import mdExample from '../../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example'; | ||||
| import multipleChoiceExample from '../../../test-assets/learning-objects/test-multiple-choice/test-multiple-choice-example'; | ||||
| import essayExample from '../../../test-assets/learning-objects/test-essay/test-essay-example'; | ||||
| import processingService from '../../../../src/services/learning-objects/processing/processing-service'; | ||||
| 
 | ||||
| describe("ProcessingService", () => { | ||||
|     it("renders a markdown learning object correctly", async () => { | ||||
| describe('ProcessingService', () => { | ||||
|     it('renders a markdown learning object correctly', async () => { | ||||
|         const markdownLearningObject = mdExample.createLearningObject(); | ||||
|         const result = await processingService.render(markdownLearningObject); | ||||
|         expect(result).toEqual(mdExample.getHTMLRendering()); | ||||
|     }); | ||||
| 
 | ||||
|     it("renders a multiple choice question correctly", async () => { | ||||
|     it('renders a multiple choice question correctly', async () => { | ||||
|         const multipleChoiceLearningObject = multipleChoiceExample.createLearningObject(); | ||||
|         const result = await processingService.render(multipleChoiceLearningObject); | ||||
|         expect(result).toEqual(multipleChoiceExample.getHTMLRendering()); | ||||
|     }); | ||||
| 
 | ||||
|     it("renders an essay question correctly", async () => { | ||||
|     it('renders an essay question correctly', async () => { | ||||
|         const essayLearningObject = essayExample.createLearningObject(); | ||||
|         const result = await processingService.render(essayLearningObject); | ||||
|         expect(result).toEqual(essayExample.getHTMLRendering()); | ||||
|  |  | |||
|  | @ -1,17 +1,17 @@ | |||
| import {beforeAll, describe, expect, it} from "vitest"; | ||||
| import {LearningObject} from "../../../src/entities/content/learning-object.entity"; | ||||
| import {setupTestApp} from "../../setup-tests"; | ||||
| import {LearningPath} from "../../../src/entities/content/learning-path.entity"; | ||||
| import {getLearningObjectRepository, getLearningPathRepository} from "../../../src/data/repositories"; | ||||
| import learningObjectExample from "../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example"; | ||||
| import learningPathExample from "../../test-assets/learning-paths/pn-werking-example" | ||||
| import databaseLearningPathProvider from "../../../src/services/learning-paths/database-learning-path-provider"; | ||||
| import {expectToBeCorrectLearningPath} from "../../test-utils/expectations"; | ||||
| import {LearningObjectRepository} from "../../../src/data/content/learning-object-repository"; | ||||
| import learningObjectService from "../../../src/services/learning-objects/learning-object-service"; | ||||
| import {Language} from "../../../src/entities/content/language"; | ||||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { LearningObject } from '../../../src/entities/content/learning-object.entity'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity'; | ||||
| import { getLearningObjectRepository, getLearningPathRepository } from '../../../src/data/repositories'; | ||||
| import learningObjectExample from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example'; | ||||
| import learningPathExample from '../../test-assets/learning-paths/pn-werking-example'; | ||||
| import databaseLearningPathProvider from '../../../src/services/learning-paths/database-learning-path-provider'; | ||||
| import { expectToBeCorrectLearningPath } from '../../test-utils/expectations'; | ||||
| import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository'; | ||||
| import learningObjectService from '../../../src/services/learning-objects/learning-object-service'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| 
 | ||||
| async function initExampleData(): Promise<{ learningObject: LearningObject, learningPath: LearningPath }> { | ||||
| async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> { | ||||
|     const learningObjectRepo = getLearningObjectRepository(); | ||||
|     const learningPathRepo = getLearningPathRepository(); | ||||
|     const learningObject = learningObjectExample.createLearningObject(); | ||||
|  | @ -21,9 +21,9 @@ async function initExampleData(): Promise<{ learningObject: LearningObject, lear | |||
|     return { learningObject, learningPath }; | ||||
| } | ||||
| 
 | ||||
| describe("DatabaseLearningPathProvider", () => { | ||||
| describe('DatabaseLearningPathProvider', () => { | ||||
|     let learningObjectRepo: LearningObjectRepository; | ||||
|     let example: {learningObject: LearningObject, learningPath: LearningPath}; | ||||
|     let example: { learningObject: LearningObject; learningPath: LearningPath }; | ||||
| 
 | ||||
|     beforeAll(async () => { | ||||
|         await setupTestApp(); | ||||
|  | @ -31,40 +31,43 @@ describe("DatabaseLearningPathProvider", () => { | |||
|         learningObjectRepo = getLearningObjectRepository(); | ||||
|     }); | ||||
| 
 | ||||
|     describe("fetchLearningPaths", () => { | ||||
|         it("returns the learning path correctly", async () => { | ||||
|     describe('fetchLearningPaths', () => { | ||||
|         it('returns the learning path correctly', async () => { | ||||
|             const result = await databaseLearningPathProvider.fetchLearningPaths( | ||||
|                 [example.learningPath.hruid], | ||||
|                 example.learningPath.language, | ||||
|                 "the source" | ||||
|                 'the source' | ||||
|             ); | ||||
|             expect(result.success).toBe(true); | ||||
|             expect(result.data?.length).toBe(1); | ||||
| 
 | ||||
|             const learningObjectsOnPath = (await Promise.all( | ||||
|                 example.learningPath.nodes.map(node => | ||||
|                     learningObjectService.getLearningObjectById({ | ||||
|                         hruid: node.learningObjectHruid, | ||||
|                         version: node.version, | ||||
|                         language: node.language | ||||
|                     })) | ||||
|             )).filter(it => it !== null); | ||||
|             const learningObjectsOnPath = ( | ||||
|                 await Promise.all( | ||||
|                     example.learningPath.nodes.map((node) => | ||||
|                         learningObjectService.getLearningObjectById({ | ||||
|                             hruid: node.learningObjectHruid, | ||||
|                             version: node.version, | ||||
|                             language: node.language, | ||||
|                         }) | ||||
|                     ) | ||||
|                 ) | ||||
|             ).filter((it) => it !== null); | ||||
| 
 | ||||
|             expectToBeCorrectLearningPath(result.data![0], example.learningPath, learningObjectsOnPath) | ||||
|             expectToBeCorrectLearningPath(result.data![0], example.learningPath, learningObjectsOnPath); | ||||
|         }); | ||||
|         it("returns a non-successful response if a non-existing learning path is queried", async () => { | ||||
|         it('returns a non-successful response if a non-existing learning path is queried', async () => { | ||||
|             const result = await databaseLearningPathProvider.fetchLearningPaths( | ||||
|                 [example.learningPath.hruid], | ||||
|                 Language.Abkhazian, // Wrong language
 | ||||
|                 "the source" | ||||
|                 'the source' | ||||
|             ); | ||||
| 
 | ||||
|             expect(result.success).toBe(false); | ||||
|         }); | ||||
|     }); | ||||
| 
 | ||||
|     describe("searchLearningPaths", () => { | ||||
|         it("returns the correct learning path when queried with a substring of its title", async () => { | ||||
|     describe('searchLearningPaths', () => { | ||||
|         it('returns the correct learning path when queried with a substring of its title', async () => { | ||||
|             const result = await databaseLearningPathProvider.searchLearningPaths( | ||||
|                 example.learningPath.title.substring(2, 6), | ||||
|                 example.learningPath.language | ||||
|  | @ -73,7 +76,7 @@ describe("DatabaseLearningPathProvider", () => { | |||
|             expect(result[0].title).toBe(example.learningPath.title); | ||||
|             expect(result[0].description).toBe(example.learningPath.description); | ||||
|         }); | ||||
|         it("returns the correct learning path when queried with a substring of the description", async () => { | ||||
|         it('returns the correct learning path when queried with a substring of the description', async () => { | ||||
|             const result = await databaseLearningPathProvider.searchLearningPaths( | ||||
|                 example.learningPath.description.substring(5, 12), | ||||
|                 example.learningPath.language | ||||
|  | @ -82,9 +85,9 @@ describe("DatabaseLearningPathProvider", () => { | |||
|             expect(result[0].title).toBe(example.learningPath.title); | ||||
|             expect(result[0].description).toBe(example.learningPath.description); | ||||
|         }); | ||||
|         it("returns an empty result when queried with a text which is not a substring of the title or the description of a learning path", async () => { | ||||
|         it('returns an empty result when queried with a text which is not a substring of the title or the description of a learning path', async () => { | ||||
|             const result = await databaseLearningPathProvider.searchLearningPaths( | ||||
|                 "substring which does not occur in the title or the description of a learning object", | ||||
|                 'substring which does not occur in the title or the description of a learning object', | ||||
|                 example.learningPath.language | ||||
|             ); | ||||
|             expect(result.length).toBe(0); | ||||
|  |  | |||
|  | @ -1,14 +1,14 @@ | |||
| import {beforeAll, describe, expect, it} from "vitest"; | ||||
| import {setupTestApp} from "../../setup-tests"; | ||||
| import {LearningObject} from "../../../src/entities/content/learning-object.entity"; | ||||
| import {LearningPath} from "../../../src/entities/content/learning-path.entity"; | ||||
| import {getLearningObjectRepository, getLearningPathRepository} from "../../../src/data/repositories"; | ||||
| import learningObjectExample from "../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example"; | ||||
| import learningPathExample from "../../test-assets/learning-paths/pn-werking-example"; | ||||
| import {Language} from "../../../src/entities/content/language"; | ||||
| import learningPathService from "../../../src/services/learning-paths/learning-path-service"; | ||||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||||
| import { setupTestApp } from '../../setup-tests'; | ||||
| import { LearningObject } from '../../../src/entities/content/learning-object.entity'; | ||||
| import { LearningPath } from '../../../src/entities/content/learning-path.entity'; | ||||
| import { getLearningObjectRepository, getLearningPathRepository } from '../../../src/data/repositories'; | ||||
| import learningObjectExample from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example'; | ||||
| import learningPathExample from '../../test-assets/learning-paths/pn-werking-example'; | ||||
| import { Language } from '../../../src/entities/content/language'; | ||||
| import learningPathService from '../../../src/services/learning-paths/learning-path-service'; | ||||
| 
 | ||||
| async function initExampleData(): Promise<{ learningObject: LearningObject, learningPath: LearningPath }> { | ||||
| async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> { | ||||
|     const learningObjectRepo = getLearningObjectRepository(); | ||||
|     const learningPathRepo = getLearningPathRepository(); | ||||
|     const learningObject = learningObjectExample.createLearningObject(); | ||||
|  | @ -18,88 +18,63 @@ async function initExampleData(): Promise<{ learningObject: LearningObject, lear | |||
|     return { learningObject, learningPath }; | ||||
| } | ||||
| 
 | ||||
| const TEST_DWENGO_LEARNING_PATH_HRUID = "pn_werking"; | ||||
| const TEST_DWENGO_LEARNING_PATH_TITLE = "Werken met notebooks"; | ||||
| const TEST_DWENGO_EXCLUSIVE_LEARNING_PATH_SEARCH_QUERY = "Microscopie"; | ||||
| const TEST_SEARCH_QUERY_EXPECTING_NO_MATCHES = "su$m8f9usf89ud<p9<U8SDP8UP9"; | ||||
| const TEST_DWENGO_LEARNING_PATH_HRUID = 'pn_werking'; | ||||
| const TEST_DWENGO_LEARNING_PATH_TITLE = 'Werken met notebooks'; | ||||
| const TEST_DWENGO_EXCLUSIVE_LEARNING_PATH_SEARCH_QUERY = 'Microscopie'; | ||||
| const TEST_SEARCH_QUERY_EXPECTING_NO_MATCHES = 'su$m8f9usf89ud<p9<U8SDP8UP9'; | ||||
| 
 | ||||
| describe("LearningPathService", () => { | ||||
|     let example: { learningObject: LearningObject, learningPath: LearningPath }; | ||||
| describe('LearningPathService', () => { | ||||
|     let example: { learningObject: LearningObject; learningPath: LearningPath }; | ||||
|     beforeAll(async () => { | ||||
|         await setupTestApp(); | ||||
|         example = await initExampleData(); | ||||
|     }); | ||||
|     describe("fetchLearningPaths", () => { | ||||
|         it("should return learning paths both from the database and from the Dwengo API", async () => { | ||||
|     describe('fetchLearningPaths', () => { | ||||
|         it('should return learning paths both from the database and from the Dwengo API', async () => { | ||||
|             const result = await learningPathService.fetchLearningPaths( | ||||
|                 [example.learningPath.hruid, TEST_DWENGO_LEARNING_PATH_HRUID], | ||||
|                 example.learningPath.language, | ||||
|                 "the source" | ||||
|                 'the source' | ||||
|             ); | ||||
|             expect(result.success).toBeTruthy(); | ||||
|             expect(result.data?.filter(it => it.hruid == TEST_DWENGO_LEARNING_PATH_HRUID).length).not.toBe(0); | ||||
|             expect(result.data?.filter(it => it.hruid == example.learningPath.hruid).length).not.toBe(0); | ||||
|             expect(result.data?.filter(it => it.hruid == TEST_DWENGO_LEARNING_PATH_HRUID)[0].title) | ||||
|                 .toEqual(TEST_DWENGO_LEARNING_PATH_TITLE); | ||||
|             expect(result.data?.filter(it => it.hruid == example.learningPath.hruid)[0].title) | ||||
|                 .toEqual(example.learningPath.title); | ||||
|             expect(result.data?.filter((it) => it.hruid == TEST_DWENGO_LEARNING_PATH_HRUID).length).not.toBe(0); | ||||
|             expect(result.data?.filter((it) => it.hruid == example.learningPath.hruid).length).not.toBe(0); | ||||
|             expect(result.data?.filter((it) => it.hruid == TEST_DWENGO_LEARNING_PATH_HRUID)[0].title).toEqual(TEST_DWENGO_LEARNING_PATH_TITLE); | ||||
|             expect(result.data?.filter((it) => it.hruid == example.learningPath.hruid)[0].title).toEqual(example.learningPath.title); | ||||
|         }); | ||||
|         it("should include both the learning objects from the Dwengo API and learning objects from the database in its response", async () => { | ||||
|             const result = await learningPathService.fetchLearningPaths( | ||||
|                 [example.learningPath.hruid], | ||||
|                 example.learningPath.language, | ||||
|                 "the source" | ||||
|             ); | ||||
|         it('should include both the learning objects from the Dwengo API and learning objects from the database in its response', async () => { | ||||
|             const result = await learningPathService.fetchLearningPaths([example.learningPath.hruid], example.learningPath.language, 'the source'); | ||||
|             expect(result.success).toBeTruthy(); | ||||
|             expect(result.data?.length).toBe(1); | ||||
| 
 | ||||
|             // Should include all the nodes, even those pointing to foreign learning objects.
 | ||||
|             expect( | ||||
|                 [...result.data![0].nodes.map(it => it.learningobject_hruid)].sort() | ||||
|             ).toEqual( | ||||
|                 example.learningPath.nodes.map(it => it.learningObjectHruid).sort() | ||||
|             expect([...result.data![0].nodes.map((it) => it.learningobject_hruid)].sort()).toEqual( | ||||
|                 example.learningPath.nodes.map((it) => it.learningObjectHruid).sort() | ||||
|             ); | ||||
|         }); | ||||
|     }); | ||||
|     describe("searchLearningPath", () => { | ||||
|         it("should include both the learning paths from the Dwengo API and those from the database in its response", async () => { | ||||
|     describe('searchLearningPath', () => { | ||||
|         it('should include both the learning paths from the Dwengo API and those from the database in its response', async () => { | ||||
|             // This matches the learning object in the database, but definitely also some learning objects in the Dwengo API.
 | ||||
|             const result = await learningPathService.searchLearningPaths( | ||||
|                 example.learningPath.title.substring(2, 3), | ||||
|                 example.learningPath.language | ||||
|             ); | ||||
|             const result = await learningPathService.searchLearningPaths(example.learningPath.title.substring(2, 3), example.learningPath.language); | ||||
| 
 | ||||
|             // Should find the one from the database
 | ||||
|             expect( | ||||
|                 result.filter(it => | ||||
|                     it.hruid === example.learningPath.hruid && it.title === example.learningPath.title | ||||
|                 ).length | ||||
|             ).toBe(1); | ||||
|             expect(result.filter((it) => it.hruid === example.learningPath.hruid && it.title === example.learningPath.title).length).toBe(1); | ||||
| 
 | ||||
|             // But should not only find that one.
 | ||||
|             expect(result.length).not.toBeLessThan(2); | ||||
|         }); | ||||
|         it("should still return results from the Dwengo API even though there are no matches in the database", async () => { | ||||
|             const result = await learningPathService.searchLearningPaths( | ||||
|                 TEST_DWENGO_EXCLUSIVE_LEARNING_PATH_SEARCH_QUERY, | ||||
|                 Language.Dutch | ||||
|             ); | ||||
|         it('should still return results from the Dwengo API even though there are no matches in the database', async () => { | ||||
|             const result = await learningPathService.searchLearningPaths(TEST_DWENGO_EXCLUSIVE_LEARNING_PATH_SEARCH_QUERY, Language.Dutch); | ||||
| 
 | ||||
|             // Should find something...
 | ||||
|             expect(result.length).not.toBe(0); | ||||
| 
 | ||||
|             // But not the example learning path.
 | ||||
|             expect( | ||||
|                 result.filter(it => | ||||
|                     it.hruid === example.learningPath.hruid && it.title === example.learningPath.title | ||||
|                 ).length | ||||
|             ).toBe(0); | ||||
|             expect(result.filter((it) => it.hruid === example.learningPath.hruid && it.title === example.learningPath.title).length).toBe(0); | ||||
|         }); | ||||
|         it("should return an empty list if neither the Dwengo API nor the database contains matches", async () => { | ||||
|             const result = await learningPathService.searchLearningPaths( | ||||
|                 TEST_SEARCH_QUERY_EXPECTING_NO_MATCHES, | ||||
|                 Language.Dutch | ||||
|             ); | ||||
|         it('should return an empty list if neither the Dwengo API nor the database contains matches', async () => { | ||||
|             const result = await learningPathService.searchLearningPaths(TEST_SEARCH_QUERY_EXPECTING_NO_MATCHES, Language.Dutch); | ||||
|             expect(result.length).toBe(0); | ||||
|         }); | ||||
|     }); | ||||
|  |  | |||
		Reference in a new issue
	
	 Lint Action
						Lint Action