fix(backend): Overige falende testen gerepareerd.
This commit is contained in:
		
							parent
							
								
									c624e36680
								
							
						
					
					
						commit
						0609152cb3
					
				
					 10 changed files with 36 additions and 29 deletions
				
			
		|  | @ -1,28 +1,21 @@ | ||||||
| import { beforeAll, describe, expect, it } from 'vitest'; | import { beforeAll, describe, expect, it } from 'vitest'; | ||||||
| import { setupTestApp } from '../../setup-tests.js'; | import { setupTestApp } from '../../setup-tests.js'; | ||||||
| import { getAttachmentRepository, getLearningObjectRepository } from '../../../src/data/repositories.js'; | import { getAttachmentRepository } from '../../../src/data/repositories.js'; | ||||||
| import { AttachmentRepository } from '../../../src/data/content/attachment-repository.js'; | import { AttachmentRepository } from '../../../src/data/content/attachment-repository.js'; | ||||||
| import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository.js'; | import { testLearningObject02 } from "../../test_assets/content/learning-objects.testdata"; | ||||||
| import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier.js'; |  | ||||||
| import { Language } from '@dwengo-1/common/util/language'; |  | ||||||
| 
 | 
 | ||||||
| describe('AttachmentRepository', () => { | describe('AttachmentRepository', () => { | ||||||
|     let attachmentRepository: AttachmentRepository; |     let attachmentRepository: AttachmentRepository; | ||||||
|     let learningObjectRepository: LearningObjectRepository; |  | ||||||
| 
 | 
 | ||||||
|     beforeAll(async () => { |     beforeAll(async () => { | ||||||
|         await setupTestApp(); |         await setupTestApp(); | ||||||
|         attachmentRepository = getAttachmentRepository(); |         attachmentRepository = getAttachmentRepository(); | ||||||
|         learningObjectRepository = getLearningObjectRepository(); |  | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('should return the requested attachment', async () => { |     it('should return the requested attachment', async () => { | ||||||
|         const id = new LearningObjectIdentifier('id02', Language.English, 1); |  | ||||||
|         const learningObject = await learningObjectRepository.findByIdentifier(id); |  | ||||||
| 
 |  | ||||||
|         const attachment = await attachmentRepository.findByMostRecentVersionOfLearningObjectAndName( |         const attachment = await attachmentRepository.findByMostRecentVersionOfLearningObjectAndName( | ||||||
|             learningObject!.hruid, |             testLearningObject02.hruid, | ||||||
|             Language.English, |             testLearningObject02.language, | ||||||
|             'attachment01' |             'attachment01' | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -9,6 +9,7 @@ import { | ||||||
|     testLearningObject02, |     testLearningObject02, | ||||||
|     testLearningObject03 |     testLearningObject03 | ||||||
| } from "../../test_assets/content/learning-objects.testdata"; | } from "../../test_assets/content/learning-objects.testdata"; | ||||||
|  | import {v4} from "uuid"; | ||||||
| 
 | 
 | ||||||
| describe('LearningObjectRepository', () => { | describe('LearningObjectRepository', () => { | ||||||
|     let learningObjectRepository: LearningObjectRepository; |     let learningObjectRepository: LearningObjectRepository; | ||||||
|  | @ -43,6 +44,7 @@ describe('LearningObjectRepository', () => { | ||||||
|         let testLearningObject01Newer = structuredClone(testLearningObject01); |         let testLearningObject01Newer = structuredClone(testLearningObject01); | ||||||
|         testLearningObject01Newer.version = 10; |         testLearningObject01Newer.version = 10; | ||||||
|         testLearningObject01Newer.title += " (nieuw)"; |         testLearningObject01Newer.title += " (nieuw)"; | ||||||
|  |         testLearningObject01Newer.uuid = v4(); | ||||||
|         testLearningObject01Newer.content = Buffer.from("This is the new content."); |         testLearningObject01Newer.content = Buffer.from("This is the new content."); | ||||||
|         newerExample = learningObjectRepository.create(testLearningObject01Newer); |         newerExample = learningObjectRepository.create(testLearningObject01Newer); | ||||||
|         await learningObjectRepository.save(newerExample); |         await learningObjectRepository.save(newerExample); | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ import { getLearningObjectRepository } from '../../../src/data/repositories'; | ||||||
| import { setupTestApp } from '../../setup-tests'; | import { setupTestApp } from '../../setup-tests'; | ||||||
| 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 { Language } from '@dwengo-1/common/util/language'; | ||||||
|  | import {testLearningObject01} from "../../test_assets/content/learning-objects.testdata"; | ||||||
| 
 | 
 | ||||||
| describe('LearningObjectRepository', () => { | describe('LearningObjectRepository', () => { | ||||||
|     let learningObjectRepository: LearningObjectRepository; |     let learningObjectRepository: LearningObjectRepository; | ||||||
|  | @ -13,8 +14,8 @@ describe('LearningObjectRepository', () => { | ||||||
|         learningObjectRepository = getLearningObjectRepository(); |         learningObjectRepository = getLearningObjectRepository(); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     const id01 = new LearningObjectIdentifier('id01', Language.English, 1); |     const id01 = new LearningObjectIdentifier(testLearningObject01.hruid, testLearningObject01.language, testLearningObject01.version); | ||||||
|     const id02 = new LearningObjectIdentifier('test_id', Language.English, 1); |     const id02 = new LearningObjectIdentifier('non_existing_id', Language.English, 1); | ||||||
| 
 | 
 | ||||||
|     it('should return the learning object that matches identifier 1', async () => { |     it('should return the learning object that matches identifier 1', async () => { | ||||||
|         const learningObject = await learningObjectRepository.findByIdentifier(id01); |         const learningObject = await learningObjectRepository.findByIdentifier(id01); | ||||||
|  |  | ||||||
|  | @ -1,26 +1,40 @@ | ||||||
| import { describe, expect, it } from 'vitest'; | import {beforeAll, 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 processingService from '../../../../src/services/learning-objects/processing/processing-service'; | ||||||
|  | import { | ||||||
|  |     testLearningObjectEssayQuestion, | ||||||
|  |     testLearningObjectMultipleChoice, testLearningObjectPnNotebooks | ||||||
|  | } from "../../../test_assets/content/learning-objects.testdata"; | ||||||
|  | import {getHtmlRenderingForTestLearningObject} from "../../../test-utils/get-html-rendering"; | ||||||
|  | import {getLearningObjectRepository} from "../../../../src/data/repositories"; | ||||||
|  | import {setupTestApp} from "../../../setup-tests"; | ||||||
| 
 | 
 | ||||||
| describe('ProcessingService', () => { | describe('ProcessingService', () => { | ||||||
|  |     beforeAll(async () => { | ||||||
|  |         await setupTestApp(); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|     it('renders a markdown learning object correctly', async () => { |     it('renders a markdown learning object correctly', async () => { | ||||||
|         const markdownLearningObject = mdExample.createLearningObject(); |         const markdownLearningObject = getLearningObjectRepository().create(testLearningObjectPnNotebooks); | ||||||
|         const result = await processingService.render(markdownLearningObject); |         const result = await processingService.render(markdownLearningObject); | ||||||
|         // Set newlines so your tests are platform-independent.
 |         // Set newlines so your tests are platform-independent.
 | ||||||
|         expect(result).toEqual(mdExample.getHTMLRendering().replace(/\r\n/g, '\n')); |         expect(result).toEqual( | ||||||
|  |             getHtmlRenderingForTestLearningObject(markdownLearningObject).replace(/\r\n/g, '\n') | ||||||
|  |         ); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('renders a multiple choice question correctly', async () => { |     it('renders a multiple choice question correctly', async () => { | ||||||
|         const multipleChoiceLearningObject = multipleChoiceExample.createLearningObject(); |         const testLearningObject = getLearningObjectRepository().create(testLearningObjectMultipleChoice); | ||||||
|         const result = await processingService.render(multipleChoiceLearningObject); |         const result = await processingService.render(testLearningObject); | ||||||
|         expect(result).toEqual(multipleChoiceExample.getHTMLRendering().replace(/\r\n/g, '\n')); |         expect(result).toEqual( | ||||||
|  |             getHtmlRenderingForTestLearningObject(testLearningObjectMultipleChoice).replace(/\r\n/g, '\n') | ||||||
|  |         ); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('renders an essay question correctly', async () => { |     it('renders an essay question correctly', async () => { | ||||||
|         const essayLearningObject = essayExample.createLearningObject(); |         const essayLearningObject = getLearningObjectRepository().create(testLearningObjectEssayQuestion); | ||||||
|         const result = await processingService.render(essayLearningObject); |         const result = await processingService.render(essayLearningObject); | ||||||
|         expect(result).toEqual(essayExample.getHTMLRendering().replace(/\r\n/g, '\n')); |         expect(result).toEqual( | ||||||
|  |             getHtmlRenderingForTestLearningObject(essayLearningObject).replace(/\r\n/g, '\n') | ||||||
|  |         ); | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -15,7 +15,6 @@ import { makeTestAnswers } from './test_assets/questions/answers.testdata.js'; | ||||||
| import { makeTestSubmissions } from './test_assets/assignments/submission.testdata.js'; | import { makeTestSubmissions } from './test_assets/assignments/submission.testdata.js'; | ||||||
| import {Collection} from "@mikro-orm/core"; | import {Collection} from "@mikro-orm/core"; | ||||||
| import {Group} from "../src/entities/assignments/group.entity"; | import {Group} from "../src/entities/assignments/group.entity"; | ||||||
| import {LearningObject} from "../src/entities/content/learning-object.entity"; |  | ||||||
| 
 | 
 | ||||||
| export async function setupTestApp(): Promise<void> { | export async function setupTestApp(): Promise<void> { | ||||||
|     dotenv.config({ path: '.env.test' }); |     dotenv.config({ path: '.env.test' }); | ||||||
|  | @ -59,6 +58,4 @@ export async function setupTestApp(): Promise<void> { | ||||||
|         ...answers, |         ...answers, | ||||||
|         ...submissions, |         ...submissions, | ||||||
|     ]); |     ]); | ||||||
| 
 |  | ||||||
|     console.log(await em.findAll(LearningObject)); |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -179,7 +179,7 @@ export const testLearningObjectMultipleChoice: RequiredEntityData<LearningObject | ||||||
|     targetAges: [10, 11, 12, 13, 14, 15, 16, 17, 18], |     targetAges: [10, 11, 12, 13, 14, 15, 16, 17, 18], | ||||||
|     admins: [], |     admins: [], | ||||||
|     contentType: DwengoContentType.GIFT, |     contentType: DwengoContentType.GIFT, | ||||||
|     content: loadTestAsset('content/learning-object-resources/test-multiple-choice/content.txt'), |     content: loadTestAsset('content/learning-object-resources/test_multiple_choice/content.txt'), | ||||||
|     returnValue: { |     returnValue: { | ||||||
|         callbackUrl: `%SUBMISSION%`, |         callbackUrl: `%SUBMISSION%`, | ||||||
|         callbackSchema: '["antwoord vraag 1"]', |         callbackSchema: '["antwoord vraag 1"]', | ||||||
|  | @ -205,7 +205,7 @@ export const testLearningObjectEssayQuestion: RequiredEntityData<LearningObject> | ||||||
|     targetAges: [10, 11, 12, 13, 14, 15, 16, 17, 18], |     targetAges: [10, 11, 12, 13, 14, 15, 16, 17, 18], | ||||||
|     admins: [], |     admins: [], | ||||||
|     contentType: DwengoContentType.GIFT, |     contentType: DwengoContentType.GIFT, | ||||||
|     content: loadTestAsset('content/learning-object-resources/test-essay/content.txt'), |     content: loadTestAsset('content/learning-object-resources/test_essay_question/content.txt'), | ||||||
|     returnValue: { |     returnValue: { | ||||||
|         callbackUrl: `%SUBMISSION%`, |         callbackUrl: `%SUBMISSION%`, | ||||||
|         callbackSchema: '["antwoord vraag 1"]', |         callbackSchema: '["antwoord vraag 1"]', | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger