fix(backend): Testen DatabaseLearningObjectProvider gerepareerd na refactoring.

This commit is contained in:
Gerald Schmittinger 2025-04-16 07:58:55 +02:00
parent ee9afab6ca
commit 51268af79c
20 changed files with 72 additions and 210 deletions

View file

@ -1,32 +0,0 @@
import { LearningObjectExample } from '../learning-object-example';
import { LearningObject } from '../../../../../src/entities/content/learning-object.entity';
import { Language } from '@dwengo-1/common/dist/util/language';
import { loadTestAsset } from '../../../../test-utils/load-test-asset';
import { DwengoContentType } from '../../../../../src/services/learning-objects/processing/content-type';
import { envVars, getEnvVar } from '../../../../../src/util/envVars';
/**
* Create a dummy learning object to be used in tests where multiple learning objects are needed (for example for use
* on a path), but where the precise contents of the learning object are not important.
*/
export function dummyLearningObject(hruid: string, language: Language, title: string): LearningObjectExample {
return {
createLearningObject: (): LearningObject => {
const learningObject = new LearningObject();
learningObject.hruid = getEnvVar(envVars.UserContentPrefix) + hruid;
learningObject.language = language;
learningObject.version = 1;
learningObject.title = title;
learningObject.description = 'Just a dummy learning object for testing purposes';
learningObject.contentType = DwengoContentType.TEXT_PLAIN;
learningObject.content = Buffer.from('Dummy content');
learningObject.returnValue = {
callbackUrl: `/learningObject/${hruid}/submissions`,
callbackSchema: '[]',
};
return learningObject;
},
createAttachment: {},
getHTMLRendering: () => loadTestAsset('learning-objects/dummy/rendering.txt').toString(),
};
}

View file

@ -1,74 +0,0 @@
import { LearningObjectExample } from '../learning-object-example';
import { Language } from '@dwengo-1/common/dist/util/language';
import { DwengoContentType } from '../../../../../src/services/learning-objects/processing/content-type';
import { loadTestAsset } from '../../../../test-utils/load-test-asset';
import { LearningObject } from '../../../../../src/entities/content/learning-object.entity';
import { Attachment } from '../../../../../src/entities/content/attachment.entity';
import { envVars, getEnvVar } from '../../../../../src/util/envVars';
import { EducationalGoal } from '../../../../../src/entities/content/educational-goal.entity';
import { ReturnValue } from '../../../../../src/entities/content/return-value.entity';
const ASSETS_PREFIX = 'learning-objects/pn-werkingnotebooks/';
const example: LearningObjectExample = {
createLearningObject: () => {
const learningObject = new LearningObject();
learningObject.hruid = `${getEnvVar(envVars.UserContentPrefix)}pn_werkingnotebooks`;
learningObject.version = 3;
learningObject.language = Language.Dutch;
learningObject.title = 'Werken met notebooks';
learningObject.description = 'Leren werken met notebooks';
learningObject.keywords = ['Python', 'KIKS', 'Wiskunde', 'STEM', 'AI'];
const educationalGoal1 = new EducationalGoal();
educationalGoal1.source = 'Source';
educationalGoal1.id = 'id';
const educationalGoal2 = new EducationalGoal();
educationalGoal2.source = 'Source2';
educationalGoal2.id = 'id2';
learningObject.educationalGoals = [educationalGoal1, educationalGoal2];
learningObject.admins = [];
learningObject.contentType = DwengoContentType.TEXT_MARKDOWN;
learningObject.teacherExclusive = false;
learningObject.skosConcepts = [
'http://ilearn.ilabt.imec.be/vocab/curr1/s-vaktaal',
'http://ilearn.ilabt.imec.be/vocab/curr1/s-digitale-media-en-toepassingen',
'http://ilearn.ilabt.imec.be/vocab/curr1/s-computers-en-systemen',
];
learningObject.copyright = 'dwengo';
learningObject.license = 'dwengo';
learningObject.estimatedTime = 10;
const returnValue = new ReturnValue();
returnValue.callbackUrl = 'callback_url_example';
returnValue.callbackSchema = '{"att": "test", "att2": "test2"}';
learningObject.returnValue = returnValue;
learningObject.available = true;
learningObject.content = loadTestAsset(`${ASSETS_PREFIX}/content.md`);
return learningObject;
},
createAttachment: {
dwengoLogo: (learningObject) => {
const att = new Attachment();
att.learningObject = learningObject;
att.name = 'dwengo.png';
att.mimeType = 'image/png';
att.content = loadTestAsset(`${ASSETS_PREFIX}/dwengo.png`);
return att;
},
knop: (learningObject) => {
const att = new Attachment();
att.learningObject = learningObject;
att.name = 'Knop.png';
att.mimeType = 'image/png';
att.content = loadTestAsset(`${ASSETS_PREFIX}/Knop.png`);
return att;
},
},
getHTMLRendering: () => loadTestAsset(`${ASSETS_PREFIX}/rendering.txt`).toString(),
};
export default example;

View file

@ -1,28 +0,0 @@
import { LearningObjectExample } from '../learning-object-example';
import { LearningObject } from '../../../../../src/entities/content/learning-object.entity';
import { loadTestAsset } from '../../../../test-utils/load-test-asset';
import { envVars, getEnvVar } from '../../../../../src/util/envVars';
import { Language } from '@dwengo-1/common/dist/util/language';
import { DwengoContentType } from '../../../../../src/services/learning-objects/processing/content-type';
const example: LearningObjectExample = {
createLearningObject: () => {
const learningObject = new LearningObject();
learningObject.hruid = `${getEnvVar(envVars.UserContentPrefix)}test_essay`;
learningObject.language = Language.English;
learningObject.version = 1;
learningObject.title = 'Essay question for testing';
learningObject.description = 'This essay question was only created for testing purposes.';
learningObject.contentType = DwengoContentType.GIFT;
learningObject.returnValue = {
callbackUrl: `/learningObject/${learningObject.hruid}/submissions`,
callbackSchema: '["antwoord vraag 1"]',
};
learningObject.content = loadTestAsset('learning-objects/test-essay/content.txt');
return learningObject;
},
createAttachment: {},
getHTMLRendering: () => loadTestAsset('learning-objects/test-essay/rendering.txt').toString(),
};
export default example;

View file

@ -1,28 +0,0 @@
import { LearningObjectExample } from '../learning-object-example';
import { LearningObject } from '../../../../../src/entities/content/learning-object.entity';
import { loadTestAsset } from '../../../../test-utils/load-test-asset';
import { envVars, getEnvVar } from '../../../../../src/util/envVars';
import { DwengoContentType } from '../../../../../src/services/learning-objects/processing/content-type';
import { Language } from '@dwengo-1/common/dist/util/language';
const example: LearningObjectExample = {
createLearningObject: () => {
const learningObject = new LearningObject();
learningObject.hruid = `${getEnvVar(envVars.UserContentPrefix)}test_multiple_choice`;
learningObject.language = Language.English;
learningObject.version = 1;
learningObject.title = 'Multiple choice question for testing';
learningObject.description = 'This multiple choice question was only created for testing purposes.';
learningObject.contentType = DwengoContentType.GIFT;
learningObject.returnValue = {
callbackUrl: `/learningObject/${learningObject.hruid}/submissions`,
callbackSchema: '["antwoord vraag 1"]',
};
learningObject.content = loadTestAsset('learning-objects/test-multiple-choice/content.txt');
return learningObject;
},
createAttachment: {},
getHTMLRendering: () => loadTestAsset('learning-objects/test-multiple-choice/rendering.txt').toString(),
};
export default example;

View file

@ -5,6 +5,7 @@ import {DwengoContentType} from '../../../src/services/learning-objects/processi
import {ReturnValue} from '../../../src/entities/content/return-value.entity';
import {envVars, getEnvVar} from "../../../src/util/envVars";
import {loadTestAsset} from "../../test-utils/load-test-asset";
import {v4} from "uuid";
export function makeTestLearningObjects(em: EntityManager): LearningObject[] {
const returnValue: ReturnValue = new ReturnValue();
@ -30,8 +31,8 @@ export function makeTestLearningObjects(em: EntityManager): LearningObject[] {
export function createReturnValue(): ReturnValue {
const returnValue: ReturnValue = new ReturnValue();
returnValue.callbackSchema = '';
returnValue.callbackUrl = '';
returnValue.callbackSchema = '[]';
returnValue.callbackUrl = '%SUBMISSION%';
return returnValue;
}
@ -44,6 +45,8 @@ export const testLearningObject01: RequiredEntityData<LearningObject> = {
description: 'debute',
contentType: DwengoContentType.TEXT_MARKDOWN,
keywords: [],
uuid: v4(),
targetAges: [16, 17, 18],
teacherExclusive: false,
skosConcepts: [],
educationalGoals: [],
@ -235,16 +238,16 @@ export const testLearningObjectPnNotebooks: RequiredEntityData<LearningObject> =
{
name: "dwengo.png",
mimeType: "image/png",
content: loadTestAsset("/content/learning-object-resources/pn-werkingnotebooks/dwengo.png")
content: loadTestAsset("/content/learning-object-resources/pn_werkingnotebooks/dwengo.png")
},
{
name: "Knop.png",
mimeType: "image/png",
content: loadTestAsset("/content/learning-object-resources/pn-werkingnotebooks/Knop.png")
content: loadTestAsset("/content/learning-object-resources/pn_werkingnotebooks/Knop.png")
}
],
available: false,
content: loadTestAsset("/content/learning-object-resources/pn-werkingnotebooks/content.md"),
content: loadTestAsset("/content/learning-object-resources/pn_werkingnotebooks/content.md"),
returnValue: {
callbackUrl: "%SUBMISSION%",
callbackSchema: "[]"