Merge branch 'dev' into test/testen-voor-datalaag-#87
This commit is contained in:
commit
79393d6552
161 changed files with 9836 additions and 3751 deletions
79
backend/tests/data/content/attachment-repository.test.ts
Normal file
79
backend/tests/data/content/attachment-repository.test.ts
Normal file
|
@ -0,0 +1,79 @@
|
|||
import { beforeAll, describe, expect, it } from 'vitest';
|
||||
import { setupTestApp } from '../../setup-tests.js';
|
||||
import { getAttachmentRepository, getLearningObjectRepository } from '../../../src/data/repositories.js';
|
||||
import { AttachmentRepository } from '../../../src/data/content/attachment-repository.js';
|
||||
import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository.js';
|
||||
import example from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example.js';
|
||||
import { LearningObject } from '../../../src/entities/content/learning-object.entity.js';
|
||||
import { Attachment } from '../../../src/entities/content/attachment.entity.js';
|
||||
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier.js';
|
||||
|
||||
const NEWER_TEST_SUFFIX = 'nEweR';
|
||||
|
||||
function createTestLearningObjects(learningObjectRepo: LearningObjectRepository): { older: LearningObject; newer: LearningObject } {
|
||||
const olderExample = example.createLearningObject();
|
||||
learningObjectRepo.save(olderExample);
|
||||
|
||||
const newerExample = example.createLearningObject();
|
||||
newerExample.title = 'Newer example';
|
||||
newerExample.version = 100;
|
||||
|
||||
return {
|
||||
older: olderExample,
|
||||
newer: newerExample,
|
||||
};
|
||||
}
|
||||
|
||||
describe('AttachmentRepository', () => {
|
||||
let attachmentRepo: AttachmentRepository;
|
||||
let exampleLearningObjects: { older: LearningObject; newer: LearningObject };
|
||||
let attachmentsOlderLearningObject: Attachment[];
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupTestApp();
|
||||
attachmentRepo = getAttachmentRepository();
|
||||
exampleLearningObjects = createTestLearningObjects(getLearningObjectRepository());
|
||||
});
|
||||
|
||||
it('can add attachments to learning objects without throwing an error', () => {
|
||||
attachmentsOlderLearningObject = Object.values(example.createAttachment).map((fn) => fn(exampleLearningObjects.older));
|
||||
|
||||
for (const attachment of attachmentsOlderLearningObject) {
|
||||
attachmentRepo.save(attachment);
|
||||
}
|
||||
});
|
||||
|
||||
let attachmentOnlyNewer: Attachment;
|
||||
it('allows us to add attachments with the same name to a different learning object without throwing an error', () => {
|
||||
attachmentOnlyNewer = Object.values(example.createAttachment)[0](exampleLearningObjects.newer);
|
||||
attachmentOnlyNewer.content.write(NEWER_TEST_SUFFIX);
|
||||
|
||||
attachmentRepo.save(attachmentOnlyNewer);
|
||||
});
|
||||
|
||||
let olderLearningObjectId: LearningObjectIdentifier;
|
||||
it('returns the correct attachment when queried by learningObjectId and attachment name', async () => {
|
||||
olderLearningObjectId = {
|
||||
hruid: exampleLearningObjects.older.hruid,
|
||||
language: exampleLearningObjects.older.language,
|
||||
version: exampleLearningObjects.older.version,
|
||||
};
|
||||
|
||||
const result = await attachmentRepo.findByLearningObjectIdAndName(olderLearningObjectId, attachmentsOlderLearningObject[0].name);
|
||||
expect(result).toBe(attachmentsOlderLearningObject[0]);
|
||||
});
|
||||
|
||||
it('returns null when queried by learningObjectId and non-existing attachment name', async () => {
|
||||
const result = await attachmentRepo.findByLearningObjectIdAndName(olderLearningObjectId, 'non-existing name');
|
||||
expect(result).toBe(null);
|
||||
});
|
||||
|
||||
it('returns the newer version of the attachment when only queried by hruid, language and attachment name (but not version)', async () => {
|
||||
const result = await attachmentRepo.findByMostRecentVersionOfLearningObjectAndName(
|
||||
exampleLearningObjects.older.hruid,
|
||||
exampleLearningObjects.older.language,
|
||||
attachmentOnlyNewer.name
|
||||
);
|
||||
expect(result).toBe(attachmentOnlyNewer);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,72 @@
|
|||
import { beforeAll, describe, it, expect } from 'vitest';
|
||||
import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository.js';
|
||||
import { setupTestApp } from '../../setup-tests.js';
|
||||
import { getLearningObjectRepository } from '../../../src/data/repositories.js';
|
||||
import example from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example.js';
|
||||
import { LearningObject } from '../../../src/entities/content/learning-object.entity.js';
|
||||
import { expectToBeCorrectEntity } from '../../test-utils/expectations.js';
|
||||
|
||||
describe('LearningObjectRepository', () => {
|
||||
let learningObjectRepository: LearningObjectRepository;
|
||||
|
||||
let exampleLearningObject: LearningObject;
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupTestApp();
|
||||
learningObjectRepository = getLearningObjectRepository();
|
||||
});
|
||||
|
||||
it('should be able to add a learning object to it without an error', async () => {
|
||||
exampleLearningObject = example.createLearningObject();
|
||||
await learningObjectRepository.insert(exampleLearningObject);
|
||||
});
|
||||
|
||||
it('should return the learning object when queried by id', async () => {
|
||||
const result = await learningObjectRepository.findByIdentifier({
|
||||
hruid: exampleLearningObject.hruid,
|
||||
language: exampleLearningObject.language,
|
||||
version: exampleLearningObject.version,
|
||||
});
|
||||
expect(result).toBeInstanceOf(LearningObject);
|
||||
expectToBeCorrectEntity(
|
||||
{
|
||||
name: 'actual',
|
||||
entity: result!,
|
||||
},
|
||||
{
|
||||
name: 'expected',
|
||||
entity: exampleLearningObject,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should return null when non-existing version is queried', async () => {
|
||||
const result = await learningObjectRepository.findByIdentifier({
|
||||
hruid: exampleLearningObject.hruid,
|
||||
language: exampleLearningObject.language,
|
||||
version: 100,
|
||||
});
|
||||
expect(result).toBe(null);
|
||||
});
|
||||
|
||||
let newerExample: LearningObject;
|
||||
|
||||
it('should allow a learning object with the same id except a different version to be added', async () => {
|
||||
newerExample = example.createLearningObject();
|
||||
newerExample.version = 10;
|
||||
newerExample.title += ' (nieuw)';
|
||||
await learningObjectRepository.save(newerExample);
|
||||
});
|
||||
|
||||
it('should return the newest version of the learning object when queried by only hruid and language', async () => {
|
||||
const result = await learningObjectRepository.findLatestByHruidAndLanguage(newerExample.hruid, newerExample.language);
|
||||
expect(result).toBeInstanceOf(LearningObject);
|
||||
expect(result?.version).toBe(10);
|
||||
expect(result?.title).toContain('(nieuw)');
|
||||
});
|
||||
|
||||
it('should return null when queried by non-existing hruid or language', async () => {
|
||||
const result = await learningObjectRepository.findLatestByHruidAndLanguage('something_that_does_not_exist', exampleLearningObject.language);
|
||||
expect(result).toBe(null);
|
||||
});
|
||||
});
|
66
backend/tests/data/content/learning-path-repository.test.ts
Normal file
66
backend/tests/data/content/learning-path-repository.test.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import { beforeAll, describe, expect, it } from 'vitest';
|
||||
import { setupTestApp } from '../../setup-tests.js';
|
||||
import { getLearningPathRepository } from '../../../src/data/repositories.js';
|
||||
import { LearningPathRepository } from '../../../src/data/content/learning-path-repository.js';
|
||||
import example from '../../test-assets/learning-paths/pn-werking-example.js';
|
||||
import { LearningPath } from '../../../src/entities/content/learning-path.entity.js';
|
||||
import { expectToBeCorrectEntity } from '../../test-utils/expectations.js';
|
||||
import { Language } from '../../../src/entities/content/language.js';
|
||||
|
||||
function expectToHaveFoundPrecisely(expected: LearningPath, result: LearningPath[]): void {
|
||||
expect(result).toHaveProperty('length');
|
||||
expect(result.length).toBe(1);
|
||||
expectToBeCorrectEntity({ entity: result[0]! }, { entity: expected });
|
||||
}
|
||||
|
||||
function expectToHaveFoundNothing(result: LearningPath[]): void {
|
||||
expect(result).toHaveProperty('length');
|
||||
expect(result.length).toBe(0);
|
||||
}
|
||||
|
||||
describe('LearningPathRepository', () => {
|
||||
let learningPathRepo: LearningPathRepository;
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupTestApp();
|
||||
learningPathRepo = getLearningPathRepository();
|
||||
});
|
||||
|
||||
let examplePath: LearningPath;
|
||||
|
||||
it('should be able to add a learning path without throwing an error', async () => {
|
||||
examplePath = example.createLearningPath();
|
||||
await learningPathRepo.insert(examplePath);
|
||||
});
|
||||
|
||||
it('should return the added path when it is queried by hruid and language', async () => {
|
||||
const result = await learningPathRepo.findByHruidAndLanguage(examplePath.hruid, examplePath.language);
|
||||
expect(result).toBeInstanceOf(LearningPath);
|
||||
expectToBeCorrectEntity({ entity: result! }, { entity: examplePath });
|
||||
});
|
||||
|
||||
it('should return null to a query on a non-existing hruid or language', async () => {
|
||||
const result = await learningPathRepo.findByHruidAndLanguage('not_existing_hruid', examplePath.language);
|
||||
expect(result).toBe(null);
|
||||
});
|
||||
|
||||
it('should return the learning path when we search for a search term occurring in its title', async () => {
|
||||
const result = await learningPathRepo.findByQueryStringAndLanguage(examplePath.title.slice(4, 9), examplePath.language);
|
||||
expectToHaveFoundPrecisely(examplePath, result);
|
||||
});
|
||||
|
||||
it('should return the learning path when we search for a search term occurring in its description', async () => {
|
||||
const result = await learningPathRepo.findByQueryStringAndLanguage(examplePath.description.slice(8, 15), examplePath.language);
|
||||
expectToHaveFoundPrecisely(examplePath, result);
|
||||
});
|
||||
|
||||
it('should return null when we search for something not occurring in its title or description', async () => {
|
||||
const result = await learningPathRepo.findByQueryStringAndLanguage('something not occurring in the path', examplePath.language);
|
||||
expectToHaveFoundNothing(result);
|
||||
});
|
||||
|
||||
it('should return null when we search for something occurring in its title, but another language', async () => {
|
||||
const result = await learningPathRepo.findByQueryStringAndLanguage(examplePath.description.slice(1, 3), Language.Kalaallisut);
|
||||
expectToHaveFoundNothing(result);
|
||||
});
|
||||
});
|
|
@ -30,22 +30,18 @@ describe('StudentRepository', () => {
|
|||
});
|
||||
|
||||
it('should return the queried student after he was added', async () => {
|
||||
await studentRepository.insert(
|
||||
new Student(username, firstName, lastName)
|
||||
);
|
||||
await studentRepository.insert(new Student(username, firstName, lastName));
|
||||
|
||||
const retrievedStudent =
|
||||
await studentRepository.findByUsername(username);
|
||||
const retrievedStudent = await studentRepository.findByUsername(username);
|
||||
expect(retrievedStudent).toBeTruthy();
|
||||
expect(retrievedStudent?.firstName).toBe(firstName);
|
||||
expect(retrievedStudent?.lastName).toBe(lastName);
|
||||
});
|
||||
|
||||
it('should no longer return the queried student after he was removed again', async () => {
|
||||
await studentRepository.deleteByUsername('Nirvana');
|
||||
await studentRepository.deleteByUsername(username);
|
||||
|
||||
const retrievedStudent =
|
||||
await studentRepository.findByUsername('Nirvana');
|
||||
const retrievedStudent = await studentRepository.findByUsername(username);
|
||||
expect(retrievedStudent).toBeNull();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
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 }> {
|
||||
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 };
|
||||
}
|
||||
|
||||
const EXPECTED_TITLE_FROM_DWENGO_LEARNING_OBJECT = 'Notebook opslaan';
|
||||
|
||||
describe('DatabaseLearningObjectProvider', () => {
|
||||
let exampleLearningObject: LearningObject;
|
||||
let exampleLearningPath: LearningPath;
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupTestApp();
|
||||
const exampleData = await initExampleData();
|
||||
exampleLearningObject = exampleData.learningObject;
|
||||
exampleLearningPath = exampleData.learningPath;
|
||||
});
|
||||
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 () => {
|
||||
const result: FilteredLearningObject | null = await databaseLearningObjectProvider.getLearningObjectById({
|
||||
hruid: exampleLearningObject.hruid,
|
||||
language: exampleLearningObject.language,
|
||||
});
|
||||
expect(result).toBeTruthy();
|
||||
expectToBeCorrectFilteredLearningObject(result!, exampleLearningObject);
|
||||
});
|
||||
|
||||
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,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
describe('getLearningObjectHTML', () => {
|
||||
it('should return the correct rendering of the learning object', async () => {
|
||||
const result = await databaseLearningObjectProvider.getLearningObjectHTML(exampleLearningObject);
|
||||
expect(result).toEqual(example.getHTMLRendering());
|
||||
});
|
||||
it('should return null for a non-existing learning object', async () => {
|
||||
const result = await databaseLearningObjectProvider.getLearningObjectHTML({
|
||||
hruid: 'non_existing_hruid',
|
||||
language: Language.Dutch,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
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)));
|
||||
});
|
||||
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,
|
||||
});
|
||||
})()
|
||||
).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 () => {
|
||||
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(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 () => {
|
||||
await databaseLearningObjectProvider.getLearningObjectsFromPath({
|
||||
hruid: 'non_existing_hruid',
|
||||
language: Language.Dutch,
|
||||
});
|
||||
})()
|
||||
).rejects.toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,126 @@
|
|||
import { beforeAll, describe, expect, it } from 'vitest';
|
||||
import { setupTestApp } from '../../setup-tests';
|
||||
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 { LearningObjectIdentifier, LearningPathIdentifier } from '../../../src/interfaces/learning-content';
|
||||
import { Language } from '../../../src/entities/content/language';
|
||||
import { EnvVars, getEnvVar } from '../../../src/util/envvars';
|
||||
import { LearningPath } from '../../../src/entities/content/learning-path.entity';
|
||||
import learningPathExample from '../../test-assets/learning-paths/pn-werking-example';
|
||||
|
||||
const EXPECTED_DWENGO_LEARNING_OBJECT_TITLE = 'Werken met notebooks';
|
||||
const DWENGO_TEST_LEARNING_OBJECT_ID: LearningObjectIdentifier = {
|
||||
hruid: 'pn_werkingnotebooks',
|
||||
language: Language.Dutch,
|
||||
version: 3,
|
||||
};
|
||||
|
||||
const DWENGO_TEST_LEARNING_PATH_ID: LearningPathIdentifier = {
|
||||
hruid: 'pn_werking',
|
||||
language: Language.Dutch,
|
||||
};
|
||||
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', () => {
|
||||
let exampleLearningObject: LearningObject;
|
||||
let exampleLearningPath: LearningPath;
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupTestApp();
|
||||
const exampleData = await initExampleData();
|
||||
exampleLearningObject = exampleData.learningObject;
|
||||
exampleLearningPath = exampleData.learningPath;
|
||||
});
|
||||
|
||||
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 () => {
|
||||
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 () => {
|
||||
const result = await learningObjectService.getLearningObjectById({
|
||||
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 () => {
|
||||
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();
|
||||
|
||||
const responseFromDwengoApi = 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}`
|
||||
);
|
||||
const responseHtml = await responseFromDwengoApi.text();
|
||||
expect(result).toEqual(responseHtml);
|
||||
}
|
||||
);
|
||||
it('returns null when queried with a non-existing identifier', async () => {
|
||||
const result = await learningObjectService.getLearningObjectHTML({
|
||||
hruid: 'non_existing_hruid',
|
||||
language: Language.Dutch,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLearningObjectsFromPath', () => {
|
||||
it('returns all learning objects when a learning path in the database is queried', async () => {
|
||||
const result = await learningObjectService.getLearningObjectsFromPath(exampleLearningPath);
|
||||
expect(result.map((it) => it.key)).toEqual(exampleLearningPath.nodes.map((it) => it.learningObjectHruid));
|
||||
});
|
||||
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);
|
||||
expect(new Set(result.map((it) => it.key))).toEqual(DWENGO_TEST_LEARNING_PATH_HRUIDS);
|
||||
});
|
||||
it('returns an empty list when queried with a non-existing learning path id', async () => {
|
||||
const result = await learningObjectService.getLearningObjectsFromPath({ hruid: 'non_existing', language: Language.Dutch });
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLearningObjectIdsFromPath', () => {
|
||||
it('returns all learning objects when a learning path in the database is queried', async () => {
|
||||
const result = await learningObjectService.getLearningObjectIdsFromPath(exampleLearningPath);
|
||||
expect(result).toEqual(exampleLearningPath.nodes.map((it) => it.learningObjectHruid));
|
||||
});
|
||||
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);
|
||||
expect(new Set(result)).toEqual(DWENGO_TEST_LEARNING_PATH_HRUIDS);
|
||||
});
|
||||
it('returns an empty list when queried with a non-existing learning path id', async () => {
|
||||
const result = await learningObjectService.getLearningObjectIdsFromPath({ hruid: 'non_existing', language: Language.Dutch });
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,25 @@
|
|||
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 () => {
|
||||
const markdownLearningObject = mdExample.createLearningObject();
|
||||
const result = await processingService.render(markdownLearningObject);
|
||||
expect(result).toEqual(mdExample.getHTMLRendering());
|
||||
});
|
||||
|
||||
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 () => {
|
||||
const essayLearningObject = essayExample.createLearningObject();
|
||||
const result = await processingService.render(essayLearningObject);
|
||||
expect(result).toEqual(essayExample.getHTMLRendering());
|
||||
});
|
||||
});
|
|
@ -0,0 +1,220 @@
|
|||
import { beforeAll, describe, expect, it } from 'vitest';
|
||||
import { LearningObject } from '../../../src/entities/content/learning-object.entity.js';
|
||||
import { setupTestApp } from '../../setup-tests.js';
|
||||
import { LearningPath } from '../../../src/entities/content/learning-path.entity.js';
|
||||
import {
|
||||
getLearningObjectRepository,
|
||||
getLearningPathRepository,
|
||||
getStudentRepository,
|
||||
getSubmissionRepository,
|
||||
} from '../../../src/data/repositories.js';
|
||||
import learningObjectExample from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example.js';
|
||||
import learningPathExample from '../../test-assets/learning-paths/pn-werking-example.js';
|
||||
import databaseLearningPathProvider from '../../../src/services/learning-paths/database-learning-path-provider.js';
|
||||
import { expectToBeCorrectLearningPath } from '../../test-utils/expectations.js';
|
||||
import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository.js';
|
||||
import learningObjectService from '../../../src/services/learning-objects/learning-object-service.js';
|
||||
import { Language } from '../../../src/entities/content/language.js';
|
||||
import {
|
||||
ConditionTestLearningPathAndLearningObjects,
|
||||
createConditionTestLearningPathAndLearningObjects,
|
||||
} from '../../test-assets/learning-paths/test-conditions-example.js';
|
||||
import { Student } from '../../../src/entities/users/student.entity.js';
|
||||
import { LearningObjectNode, LearningPathResponse } from '../../../src/interfaces/learning-content.js';
|
||||
|
||||
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 };
|
||||
}
|
||||
|
||||
async function initPersonalizationTestData(): Promise<{
|
||||
learningContent: ConditionTestLearningPathAndLearningObjects;
|
||||
studentA: Student;
|
||||
studentB: Student;
|
||||
}> {
|
||||
const studentRepo = getStudentRepository();
|
||||
const submissionRepo = getSubmissionRepository();
|
||||
const learningPathRepo = getLearningPathRepository();
|
||||
const learningObjectRepo = getLearningObjectRepository();
|
||||
const learningContent = createConditionTestLearningPathAndLearningObjects();
|
||||
await learningObjectRepo.save(learningContent.branchingObject);
|
||||
await learningObjectRepo.save(learningContent.finalObject);
|
||||
await learningObjectRepo.save(learningContent.extraExerciseObject);
|
||||
await learningPathRepo.save(learningContent.learningPath);
|
||||
|
||||
console.log(await getSubmissionRepository().findAll({}));
|
||||
|
||||
const studentA = studentRepo.create({
|
||||
username: 'student_a',
|
||||
firstName: 'Aron',
|
||||
lastName: 'Student',
|
||||
});
|
||||
await studentRepo.save(studentA);
|
||||
const submissionA = submissionRepo.create({
|
||||
learningObjectHruid: learningContent.branchingObject.hruid,
|
||||
learningObjectLanguage: learningContent.branchingObject.language,
|
||||
learningObjectVersion: learningContent.branchingObject.version,
|
||||
submissionNumber: 0,
|
||||
submitter: studentA,
|
||||
submissionTime: new Date(),
|
||||
content: '[0]',
|
||||
});
|
||||
await submissionRepo.save(submissionA);
|
||||
|
||||
const studentB = studentRepo.create({
|
||||
username: 'student_b',
|
||||
firstName: 'Bill',
|
||||
lastName: 'Student',
|
||||
});
|
||||
await studentRepo.save(studentB);
|
||||
const submissionB = submissionRepo.create({
|
||||
learningObjectHruid: learningContent.branchingObject.hruid,
|
||||
learningObjectLanguage: learningContent.branchingObject.language,
|
||||
learningObjectVersion: learningContent.branchingObject.version,
|
||||
submissionNumber: 1,
|
||||
submitter: studentB,
|
||||
submissionTime: new Date(),
|
||||
content: '[1]',
|
||||
});
|
||||
await submissionRepo.save(submissionB);
|
||||
|
||||
return {
|
||||
learningContent: learningContent,
|
||||
studentA: studentA,
|
||||
studentB: studentB,
|
||||
};
|
||||
}
|
||||
|
||||
function expectBranchingObjectNode(
|
||||
result: LearningPathResponse,
|
||||
persTestData: {
|
||||
learningContent: ConditionTestLearningPathAndLearningObjects;
|
||||
studentA: Student;
|
||||
studentB: Student;
|
||||
}
|
||||
): LearningObjectNode {
|
||||
const branchingObjectMatches = result.data![0].nodes.filter(
|
||||
(it) => it.learningobject_hruid === persTestData.learningContent.branchingObject.hruid
|
||||
);
|
||||
expect(branchingObjectMatches.length).toBe(1);
|
||||
return branchingObjectMatches[0];
|
||||
}
|
||||
|
||||
describe('DatabaseLearningPathProvider', () => {
|
||||
let learningObjectRepo: LearningObjectRepository;
|
||||
let example: { learningObject: LearningObject; learningPath: LearningPath };
|
||||
let persTestData: { learningContent: ConditionTestLearningPathAndLearningObjects; studentA: Student; studentB: Student };
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupTestApp();
|
||||
example = await initExampleData();
|
||||
persTestData = await initPersonalizationTestData();
|
||||
learningObjectRepo = getLearningObjectRepository();
|
||||
});
|
||||
|
||||
describe('fetchLearningPaths', () => {
|
||||
it('returns the learning path correctly', async () => {
|
||||
const result = await databaseLearningPathProvider.fetchLearningPaths(
|
||||
[example.learningPath.hruid],
|
||||
example.learningPath.language,
|
||||
'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);
|
||||
|
||||
expectToBeCorrectLearningPath(result.data![0], example.learningPath, learningObjectsOnPath);
|
||||
});
|
||||
it('returns the correct personalized learning path', async () => {
|
||||
// For student A:
|
||||
let result = await databaseLearningPathProvider.fetchLearningPaths(
|
||||
[persTestData.learningContent.learningPath.hruid],
|
||||
persTestData.learningContent.learningPath.language,
|
||||
'the source',
|
||||
{ type: 'student', student: persTestData.studentA }
|
||||
);
|
||||
expect(result.success).toBeTruthy();
|
||||
expect(result.data?.length).toBe(1);
|
||||
|
||||
// There should be exactly one branching object
|
||||
let branchingObject = expectBranchingObjectNode(result, persTestData);
|
||||
|
||||
expect(branchingObject.transitions.filter((it) => it.next.hruid === persTestData.learningContent.finalObject.hruid).length).toBe(0); // StudentA picked the first option, therefore, there should be no direct path to the final object.
|
||||
expect(branchingObject.transitions.filter((it) => it.next.hruid === persTestData.learningContent.extraExerciseObject.hruid).length).toBe(
|
||||
1
|
||||
); // There should however be a path to the extra exercise object.
|
||||
|
||||
// For student B:
|
||||
result = await databaseLearningPathProvider.fetchLearningPaths(
|
||||
[persTestData.learningContent.learningPath.hruid],
|
||||
persTestData.learningContent.learningPath.language,
|
||||
'the source',
|
||||
{ type: 'student', student: persTestData.studentB }
|
||||
);
|
||||
expect(result.success).toBeTruthy();
|
||||
expect(result.data?.length).toBe(1);
|
||||
|
||||
// There should still be exactly one branching object
|
||||
branchingObject = expectBranchingObjectNode(result, persTestData);
|
||||
|
||||
// However, now the student picks the other option.
|
||||
expect(branchingObject.transitions.filter((it) => it.next.hruid === persTestData.learningContent.finalObject.hruid).length).toBe(1); // StudentB picked the second option, therefore, there should be a direct path to the final object.
|
||||
expect(branchingObject.transitions.filter((it) => it.next.hruid === persTestData.learningContent.extraExerciseObject.hruid).length).toBe(
|
||||
0
|
||||
); // There should not be a path anymore to the extra exercise object.
|
||||
});
|
||||
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'
|
||||
);
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
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
|
||||
);
|
||||
expect(result.length).toBe(1);
|
||||
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 () => {
|
||||
const result = await databaseLearningPathProvider.searchLearningPaths(
|
||||
example.learningPath.description.substring(5, 12),
|
||||
example.learningPath.language
|
||||
);
|
||||
expect(result.length).toBe(1);
|
||||
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 () => {
|
||||
const result = await databaseLearningPathProvider.searchLearningPaths(
|
||||
'substring which does not occur in the title or the description of a learning object',
|
||||
example.learningPath.language
|
||||
);
|
||||
expect(result.length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,81 @@
|
|||
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 }> {
|
||||
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 };
|
||||
}
|
||||
|
||||
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 };
|
||||
beforeAll(async () => {
|
||||
await setupTestApp();
|
||||
example = await initExampleData();
|
||||
});
|
||||
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'
|
||||
);
|
||||
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);
|
||||
});
|
||||
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()
|
||||
);
|
||||
});
|
||||
});
|
||||
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);
|
||||
|
||||
// Should find the one from the database
|
||||
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);
|
||||
|
||||
// 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);
|
||||
});
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,10 @@
|
|||
import { LearningObjectExample } from './learning-object-example';
|
||||
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
|
||||
|
||||
export function createExampleLearningObjectWithAttachments(example: LearningObjectExample): LearningObject {
|
||||
const learningObject = example.createLearningObject();
|
||||
for (const creationFn of Object.values(example.createAttachment)) {
|
||||
learningObject.attachments.push(creationFn(learningObject));
|
||||
}
|
||||
return learningObject;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
import { LearningObjectExample } from '../learning-object-example';
|
||||
import { LearningObject } from '../../../../src/entities/content/learning-object.entity';
|
||||
import { Language } from '../../../../src/entities/content/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: () => {
|
||||
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(),
|
||||
};
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
Dummy content
|
8
backend/tests/test-assets/learning-objects/learning-object-example.d.ts
vendored
Normal file
8
backend/tests/test-assets/learning-objects/learning-object-example.d.ts
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
|
||||
import { Attachment } from '../../../src/entities/content/attachment.entity';
|
||||
|
||||
type LearningObjectExample = {
|
||||
createLearningObject: () => LearningObject;
|
||||
createAttachment: { [key: string]: (owner: LearningObject) => Attachment };
|
||||
getHTMLRendering: () => string;
|
||||
};
|
Binary file not shown.
After Width: | Height: | Size: 7.6 KiB |
|
@ -0,0 +1,26 @@
|
|||
# Werken met notebooks
|
||||
|
||||
Het lesmateriaal van 'Python in wiskunde en STEM' wordt aangeboden in de vorm van interactieve **_notebooks_**. Notebooks zijn _digitale documenten_ die zowel uitvoerbare code bevatten als tekst, afbeeldingen, video, hyperlinks ...
|
||||
|
||||
_Nieuwe begrippen_ worden aangebracht via tekstuele uitleg, video en afbeeldingen.
|
||||
|
||||
Er zijn uitgewerkte _voorbeelden_ met daarnaast ook kleine en grote _opdrachten_. In deze opdrachten zal je aangereikte code kunnen uitvoeren, maar ook zelf code opstellen.
|
||||
|
||||
De code die in de notebooks gebruikt wordt, is Python versie 3. We kozen voor Python omdat dit een heel toegankelijke programmeertaal is, die vaak ook intuïtief is.
|
||||
Python is bovendien bezig aan een opmars en wordt gebruikt door bedrijven, zoals Google, NASA, Netflix, Uber, AstraZeneca, Barco, Instagram en YouTube.
|
||||
|
||||
We kozen voor notebooks omdat daar enkele belangrijke voordelen aan verbonden zijn: leerkrachten moeten geen geavanceerde installaties doen om de notebooks te gebruiken, leerkrachten kunnen verschillende soorten van lesinhouden aanbieden via één platform, de notebooks zijn interactief, leerlingen bouwen de oplossing van een probleem stap voor stap op in de notebook waardoor dat proces zichtbaar is voor de leerkracht ([Jeroen Van der Hooft, 2023](https://libstore.ugent.be/fulltxt/RUG01/003/151/437/RUG01-003151437_2023_0001_AC.pdf)).
|
||||
|
||||
---
|
||||
|
||||
Klik je op onderstaande knop 'Open notebooks', dan word je doorgestuurd naar een andere website waar jouw persoonlijke notebooks ingeladen worden. (Dit kan even duren.)
|
||||
|
||||
Links op het scherm vind je er twee bestanden met extensie _.ipynb_.
|
||||
Dit zijn de twee notebooks waarin je resp. een overzicht krijgt van de opbouw en mogelijkheden en hoe je er mee aan de slag kan. Dubbelklik op de bestandsnaam om een notebook te openen.
|
||||
|
||||
Je ziet er ook een map _images_ met de afbeeldingen die in de notebooks getoond worden.
|
||||
|
||||
In deze eerste twee notebooks leer je hoe de notebooks zijn opgevat en hoe je ermee aan de slag kan.
|
||||
Na het doorlopen van beide notebooks heb je een goed idee van hoe onze Python notebooks zijn opgevat.
|
||||
|
||||
[](https://kiks.ilabt.imec.be/hub/tmplogin?id=0101 'Notebooks Werking')
|
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
|
@ -0,0 +1,72 @@
|
|||
import { LearningObjectExample } from '../learning-object-example';
|
||||
import { Language } from '../../../../src/entities/content/language';
|
||||
import { DwengoContentType } from '../../../../src/services/learning-objects/processing/content-type';
|
||||
import { loadTestAsset } from '../../../test-utils/load-test-asset';
|
||||
import { EducationalGoal, LearningObject, ReturnValue } from '../../../../src/entities/content/learning-object.entity';
|
||||
import { Attachment } from '../../../../src/entities/content/attachment.entity';
|
||||
import { EnvVars, getEnvVar } from '../../../../src/util/envvars';
|
||||
|
||||
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;
|
|
@ -0,0 +1,20 @@
|
|||
<h1>
|
||||
<a name="werken-met-notebooks" class="anchor" href="#werken-met-notebooks">
|
||||
<span class="header-link"></span>
|
||||
</a>
|
||||
Werken met notebooks
|
||||
</h1>
|
||||
<p>Het lesmateriaal van 'Python in wiskunde en STEM' wordt aangeboden in de vorm van interactieve <strong><em>notebooks</em></strong>. Notebooks zijn <em>digitale documenten</em> die zowel uitvoerbare code bevatten als tekst, afbeeldingen, video, hyperlinks ...</p>
|
||||
<p><em>Nieuwe begrippen</em> worden aangebracht via tekstuele uitleg, video en afbeeldingen.</p>
|
||||
<p>Er zijn uitgewerkte <em>voorbeelden</em> met daarnaast ook kleine en grote <em>opdrachten</em>. In deze opdrachten zal je aangereikte code kunnen uitvoeren, maar ook zelf code opstellen.</p>
|
||||
<p>De code die in de notebooks gebruikt wordt, is Python versie 3. We kozen voor Python omdat dit een heel toegankelijke programmeertaal is, die vaak ook intuC/tief is.
|
||||
Python is bovendien bezig aan een opmars en wordt gebruikt door bedrijven, zoals Google, NASA, Netflix, Uber, AstraZeneca, Barco, Instagram en YouTube.</p>
|
||||
<p>We kozen voor notebooks omdat daar enkele belangrijke voordelen aan verbonden zijn: leerkrachten moeten geen geavanceerde installaties doen om de notebooks te gebruiken, leerkrachten kunnen verschillende soorten van lesinhouden aanbieden via C)C)n platform, de notebooks zijn interactief, leerlingen bouwen de oplossing van een probleem stap voor stap op in de notebook waardoor dat proces zichtbaar is voor de leerkracht (<a href="https://libstore.ugent.be/fulltxt/RUG01/003/151/437/RUG01-003151437_2023_0001_AC.pdf" target="_blank" title="">Jeroen Van der Hooft, 2023</a>).</p>
|
||||
<hr>
|
||||
<p>Klik je op onderstaande knop 'Open notebooks', dan word je doorgestuurd naar een andere website waar jouw persoonlijke notebooks ingeladen worden. (Dit kan even duren.)</p>
|
||||
<p>Links op het scherm vind je er twee bestanden met extensie <em>.ipynb</em>.
|
||||
Dit zijn de twee notebooks waarin je resp. een overzicht krijgt van de opbouw en mogelijkheden en hoe je er mee aan de slag kan. Dubbelklik op de bestandsnaam om een notebook te openen.</p>
|
||||
<p>Je ziet er ook een map <em>images</em> met de afbeeldingen die in de notebooks getoond worden.</p>
|
||||
<p>In deze eerste twee notebooks leer je hoe de notebooks zijn opgevat en hoe je ermee aan de slag kan.
|
||||
Na het doorlopen van beide notebooks heb je een goed idee van hoe onze Python notebooks zijn opgevat.</p>
|
||||
<p><a href="https://kiks.ilabt.imec.be/hub/tmplogin?id=0101" target="_blank" title="Notebooks Werking"><img alt="" src="Knop.png"></a></p>
|
|
@ -0,0 +1,2 @@
|
|||
::MC basic::
|
||||
How are you? {}
|
|
@ -0,0 +1,7 @@
|
|||
<div class="learning-object-gift">
|
||||
<div id="gift-q1" class="gift-question">
|
||||
<h2 id="gift-q1-title" class="gift-title">MC basic</h2>
|
||||
<p id="gift-q1-stem" class="gift-stem">How are you?</p>
|
||||
<textarea id="gift-q1-answer" class="gift-essay-answer"></textarea>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,28 @@
|
|||
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 '../../../../src/entities/content/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;
|
|
@ -0,0 +1,5 @@
|
|||
::MC basic::
|
||||
Are you following along well with the class? {
|
||||
~No, it's very difficult to follow along.
|
||||
=Yes, no problem!
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<div class="learning-object-gift">
|
||||
<div id="gift-q1" class="gift-question">
|
||||
<h2 id="gift-q1-title" class="gift-title">MC basic</h2>
|
||||
<p id="gift-q1-stem" class="gift-stem">Are you following along well with the class?</p>
|
||||
<div class="gift-choice-div">
|
||||
<input value="0" name="gift-q1-choices" id="gift-q1-choice-0" type="radio">
|
||||
<label for="gift-q1-choice-0">[object Object]</label>
|
||||
</div>
|
||||
<div class="gift-choice-div">
|
||||
<input value="1" name="gift-q1-choices" id="gift-q1-choice-1" type="radio">
|
||||
<label for="gift-q1-choice-1">[object Object]</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,28 @@
|
|||
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 '../../../../src/entities/content/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_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;
|
3
backend/tests/test-assets/learning-paths/learning-path-example.d.ts
vendored
Normal file
3
backend/tests/test-assets/learning-paths/learning-path-example.d.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
type LearningPathExample = {
|
||||
createLearningPath: () => LearningPath;
|
||||
};
|
|
@ -0,0 +1,31 @@
|
|||
import { Language } from '../../../src/entities/content/language';
|
||||
import { LearningPathTransition } from '../../../src/entities/content/learning-path-transition.entity';
|
||||
import { LearningPathNode } from '../../../src/entities/content/learning-path-node.entity';
|
||||
import { LearningPath } from '../../../src/entities/content/learning-path.entity';
|
||||
|
||||
export function createLearningPathTransition(node: LearningPathNode, transitionNumber: number, condition: string | null, to: LearningPathNode) {
|
||||
const trans = new LearningPathTransition();
|
||||
trans.node = node;
|
||||
trans.transitionNumber = transitionNumber;
|
||||
trans.condition = condition || 'true';
|
||||
trans.next = to;
|
||||
return trans;
|
||||
}
|
||||
|
||||
export function createLearningPathNode(
|
||||
learningPath: LearningPath,
|
||||
nodeNumber: number,
|
||||
learningObjectHruid: string,
|
||||
version: number,
|
||||
language: Language,
|
||||
startNode: boolean
|
||||
) {
|
||||
const node = new LearningPathNode();
|
||||
node.learningPath = learningPath;
|
||||
node.nodeNumber = nodeNumber;
|
||||
node.learningObjectHruid = learningObjectHruid;
|
||||
node.version = version;
|
||||
node.language = language;
|
||||
node.startNode = startNode;
|
||||
return node;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
import { LearningPath } from '../../../src/entities/content/learning-path.entity';
|
||||
import { Language } from '../../../src/entities/content/language';
|
||||
import { EnvVars, getEnvVar } from '../../../src/util/envvars';
|
||||
import { createLearningPathNode, createLearningPathTransition } from './learning-path-utils';
|
||||
import { LearningPathNode } from '../../../src/entities/content/learning-path-node.entity';
|
||||
|
||||
function createNodes(learningPath: LearningPath): LearningPathNode[] {
|
||||
const nodes = [
|
||||
createLearningPathNode(learningPath, 0, 'u_pn_werkingnotebooks', 3, Language.Dutch, true),
|
||||
createLearningPathNode(learningPath, 1, 'pn_werkingnotebooks2', 3, Language.Dutch, false),
|
||||
createLearningPathNode(learningPath, 2, 'pn_werkingnotebooks3', 3, Language.Dutch, false),
|
||||
];
|
||||
nodes[0].transitions.push(createLearningPathTransition(nodes[0], 0, 'true', nodes[1]));
|
||||
nodes[1].transitions.push(createLearningPathTransition(nodes[1], 0, 'true', nodes[2]));
|
||||
return nodes;
|
||||
}
|
||||
|
||||
const example: LearningPathExample = {
|
||||
createLearningPath: () => {
|
||||
const path = new LearningPath();
|
||||
path.language = Language.Dutch;
|
||||
path.hruid = `${getEnvVar(EnvVars.UserContentPrefix)}pn_werking`;
|
||||
path.title = 'Werken met notebooks';
|
||||
path.description = 'Een korte inleiding tot Python notebooks. Hoe ga je gemakkelijk en efficiënt met de notebooks aan de slag?';
|
||||
path.nodes = createNodes(path);
|
||||
return path;
|
||||
},
|
||||
};
|
||||
|
||||
export default example;
|
|
@ -0,0 +1,84 @@
|
|||
import { LearningPath } from '../../../src/entities/content/learning-path.entity';
|
||||
import { Language } from '../../../src/entities/content/language';
|
||||
import testMultipleChoiceExample from '../learning-objects/test-multiple-choice/test-multiple-choice-example';
|
||||
import { dummyLearningObject } from '../learning-objects/dummy/dummy-learning-object-example';
|
||||
import { createLearningPathNode, createLearningPathTransition } from './learning-path-utils';
|
||||
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
|
||||
import { EnvVars, getEnvVar } from '../../../src/util/envvars';
|
||||
|
||||
export type ConditionTestLearningPathAndLearningObjects = {
|
||||
branchingObject: LearningObject;
|
||||
extraExerciseObject: LearningObject;
|
||||
finalObject: LearningObject;
|
||||
learningPath: LearningPath;
|
||||
};
|
||||
|
||||
export function createConditionTestLearningPathAndLearningObjects() {
|
||||
const learningPath = new LearningPath();
|
||||
learningPath.hruid = `${getEnvVar(EnvVars.UserContentPrefix)}test_conditions`;
|
||||
learningPath.language = Language.English;
|
||||
learningPath.title = 'Example learning path with conditional transitions';
|
||||
learningPath.description = 'This learning path was made for the purpose of testing conditional transitions';
|
||||
|
||||
const branchingLearningObject = testMultipleChoiceExample.createLearningObject();
|
||||
const extraExerciseLearningObject = dummyLearningObject(
|
||||
'test_extra_exercise',
|
||||
Language.English,
|
||||
'Extra exercise (for students with difficulties)'
|
||||
).createLearningObject();
|
||||
const finalLearningObject = dummyLearningObject(
|
||||
'test_final_learning_object',
|
||||
Language.English,
|
||||
'Final exercise (for everyone)'
|
||||
).createLearningObject();
|
||||
|
||||
const branchingNode = createLearningPathNode(
|
||||
learningPath,
|
||||
0,
|
||||
branchingLearningObject.hruid,
|
||||
branchingLearningObject.version,
|
||||
branchingLearningObject.language,
|
||||
true
|
||||
);
|
||||
const extraExerciseNode = createLearningPathNode(
|
||||
learningPath,
|
||||
1,
|
||||
extraExerciseLearningObject.hruid,
|
||||
extraExerciseLearningObject.version,
|
||||
extraExerciseLearningObject.language,
|
||||
false
|
||||
);
|
||||
const finalNode = createLearningPathNode(
|
||||
learningPath,
|
||||
2,
|
||||
finalLearningObject.hruid,
|
||||
finalLearningObject.version,
|
||||
finalLearningObject.language,
|
||||
false
|
||||
);
|
||||
|
||||
const transitionToExtraExercise = createLearningPathTransition(
|
||||
branchingNode,
|
||||
0,
|
||||
'$[?(@[0] == 0)]', // The answer to the first question was the first one, which says that it is difficult for the student to follow along.
|
||||
extraExerciseNode
|
||||
);
|
||||
const directTransitionToFinal = createLearningPathTransition(branchingNode, 1, '$[?(@[0] == 1)]', finalNode);
|
||||
const transitionExtraExerciseToFinal = createLearningPathTransition(extraExerciseNode, 0, 'true', finalNode);
|
||||
|
||||
branchingNode.transitions = [transitionToExtraExercise, directTransitionToFinal];
|
||||
extraExerciseNode.transitions = [transitionExtraExerciseToFinal];
|
||||
|
||||
learningPath.nodes = [branchingNode, extraExerciseNode, finalNode];
|
||||
|
||||
return {
|
||||
branchingObject: branchingLearningObject,
|
||||
finalObject: finalLearningObject,
|
||||
extraExerciseObject: extraExerciseLearningObject,
|
||||
learningPath: learningPath,
|
||||
};
|
||||
}
|
||||
|
||||
const example: LearningPathExample = {
|
||||
createLearningPath: () => createConditionTestLearningPathAndLearningObjects().learningPath,
|
||||
};
|
150
backend/tests/test-utils/expectations.ts
Normal file
150
backend/tests/test-utils/expectations.ts
Normal file
|
@ -0,0 +1,150 @@
|
|||
import { AssertionError } from 'node:assert';
|
||||
import { LearningObject } from '../../src/entities/content/learning-object.entity';
|
||||
import { FilteredLearningObject, LearningPath } from '../../src/interfaces/learning-content';
|
||||
import { LearningPath as LearningPathEntity } from '../../src/entities/content/learning-path.entity';
|
||||
import { expect } from 'vitest';
|
||||
|
||||
// Ignored properties because they belang for example to the class, not to the entity itself.
|
||||
const IGNORE_PROPERTIES = ['parent'];
|
||||
|
||||
/**
|
||||
* Checks if the actual entity from the database conforms to the entity that was added previously.
|
||||
* @param actual The actual entity retrieved from the database
|
||||
* @param expected The (previously added) entity we would expect to retrieve
|
||||
*/
|
||||
export function expectToBeCorrectEntity<T extends object>(actual: { entity: T; name?: string }, expected: { entity: T; name?: string }): void {
|
||||
if (!actual.name) {
|
||||
actual.name = 'actual';
|
||||
}
|
||||
if (!expected.name) {
|
||||
expected.name = 'expected';
|
||||
}
|
||||
for (const property in expected.entity) {
|
||||
if (
|
||||
property! in IGNORE_PROPERTIES &&
|
||||
expected.entity[property] !== undefined && // If we don't expect a certain value for a property, we assume it can be filled in by the database however it wants.
|
||||
typeof expected.entity[property] !== 'function' // Functions obviously are not persisted via the database
|
||||
) {
|
||||
if (!actual.entity.hasOwnProperty(property)) {
|
||||
throw new AssertionError({
|
||||
message: `${expected.name} has defined property ${property}, but ${actual.name} is missing it.`,
|
||||
});
|
||||
}
|
||||
if (typeof expected.entity[property] === 'boolean') {
|
||||
// Sometimes, booleans get represented by numbers 0 and 1 in the objects actual from the database.
|
||||
if (Boolean(expected.entity[property]) !== Boolean(actual.entity[property])) {
|
||||
throw new AssertionError({
|
||||
message: `${property} was ${expected.entity[property]} in ${expected.name},
|
||||
but ${actual.entity[property]} (${Boolean(expected.entity[property])}) in ${actual.name}`,
|
||||
});
|
||||
}
|
||||
} else if (typeof expected.entity[property] !== typeof actual.entity[property]) {
|
||||
throw new AssertionError({
|
||||
message: `${property} has type ${typeof expected.entity[property]} in ${expected.name}, but type ${typeof actual.entity[property]} in ${actual.name}.`,
|
||||
});
|
||||
} else if (typeof expected.entity[property] === 'object') {
|
||||
expectToBeCorrectEntity(
|
||||
{
|
||||
name: actual.name + '.' + property,
|
||||
entity: actual.entity[property] as object,
|
||||
},
|
||||
{
|
||||
name: expected.name + '.' + property,
|
||||
entity: expected.entity[property] as object,
|
||||
}
|
||||
);
|
||||
} else {
|
||||
if (expected.entity[property] !== actual.entity[property]) {
|
||||
throw new AssertionError({
|
||||
message: `${property} was ${expected.entity[property]} in ${expected.name}, but ${actual.entity[property]} in ${actual.name}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that filtered is the correct representation of original as FilteredLearningObject.
|
||||
* @param filtered the representation as FilteredLearningObject
|
||||
* @param original the original entity added to the database
|
||||
*/
|
||||
export function expectToBeCorrectFilteredLearningObject(filtered: FilteredLearningObject, original: LearningObject) {
|
||||
expect(filtered.uuid).toEqual(original.uuid);
|
||||
expect(filtered.version).toEqual(original.version);
|
||||
expect(filtered.language).toEqual(original.language);
|
||||
expect(filtered.keywords).toEqual(original.keywords);
|
||||
expect(filtered.key).toEqual(original.hruid);
|
||||
expect(filtered.targetAges).toEqual(original.targetAges);
|
||||
expect(filtered.title).toEqual(original.title);
|
||||
expect(Boolean(filtered.teacherExclusive)).toEqual(Boolean(original.teacherExclusive));
|
||||
expect(filtered.skosConcepts).toEqual(original.skosConcepts);
|
||||
expect(filtered.estimatedTime).toEqual(original.estimatedTime);
|
||||
expect(filtered.educationalGoals).toEqual(original.educationalGoals);
|
||||
expect(filtered.difficulty).toEqual(original.difficulty || 1);
|
||||
expect(filtered.description).toEqual(original.description);
|
||||
expect(filtered.returnValue?.callback_url).toEqual(original.returnValue.callbackUrl);
|
||||
expect(filtered.returnValue?.callback_schema).toEqual(JSON.parse(original.returnValue.callbackSchema));
|
||||
expect(filtered.contentType).toEqual(original.contentType);
|
||||
expect(filtered.contentLocation || null).toEqual(original.contentLocation || null);
|
||||
expect(filtered.htmlUrl).toContain(`/${original.hruid}/html`);
|
||||
expect(filtered.htmlUrl).toContain(`language=${original.language}`);
|
||||
expect(filtered.htmlUrl).toContain(`version=${original.version}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a learning path returned by a LearningPathRetriever, the LearningPathService or an API endpoint
|
||||
* is a correct representation of the given learning path entity.
|
||||
*
|
||||
* @param learningPath The learning path returned by the retriever, service or endpoint
|
||||
* @param expectedEntity The expected entity
|
||||
* @param learningObjectsOnPath The learning objects on LearningPath. Necessary since some information in
|
||||
* the learning path returned from the API endpoint
|
||||
*/
|
||||
export function expectToBeCorrectLearningPath(
|
||||
learningPath: LearningPath,
|
||||
expectedEntity: LearningPathEntity,
|
||||
learningObjectsOnPath: FilteredLearningObject[]
|
||||
) {
|
||||
expect(learningPath.hruid).toEqual(expectedEntity.hruid);
|
||||
expect(learningPath.language).toEqual(expectedEntity.language);
|
||||
expect(learningPath.description).toEqual(expectedEntity.description);
|
||||
expect(learningPath.title).toEqual(expectedEntity.title);
|
||||
|
||||
const keywords = new Set(learningObjectsOnPath.flatMap((it) => it.keywords || []));
|
||||
expect(new Set(learningPath.keywords.split(' '))).toEqual(keywords);
|
||||
|
||||
const targetAges = new Set(learningObjectsOnPath.flatMap((it) => it.targetAges || []));
|
||||
expect(new Set(learningPath.target_ages)).toEqual(targetAges);
|
||||
expect(learningPath.min_age).toEqual(Math.min(...targetAges));
|
||||
expect(learningPath.max_age).toEqual(Math.max(...targetAges));
|
||||
|
||||
expect(learningPath.num_nodes).toEqual(expectedEntity.nodes.length);
|
||||
expect(learningPath.image || null).toEqual(expectedEntity.image);
|
||||
|
||||
const expectedLearningPathNodes = new Map(
|
||||
expectedEntity.nodes.map((node) => [
|
||||
{ learningObjectHruid: node.learningObjectHruid, language: node.language, version: node.version },
|
||||
{ startNode: node.startNode, transitions: node.transitions },
|
||||
])
|
||||
);
|
||||
|
||||
for (const node of learningPath.nodes) {
|
||||
const nodeKey = {
|
||||
learningObjectHruid: node.learningobject_hruid,
|
||||
language: node.language,
|
||||
version: node.version,
|
||||
};
|
||||
expect(expectedLearningPathNodes.keys()).toContainEqual(nodeKey);
|
||||
const expectedNode = [...expectedLearningPathNodes.entries()].filter(
|
||||
([key, _]) => key.learningObjectHruid === nodeKey.learningObjectHruid && key.language === node.language && key.version === node.version
|
||||
)[0][1];
|
||||
expect(node.start_node).toEqual(expectedNode?.startNode);
|
||||
|
||||
expect(new Set(node.transitions.map((it) => it.next.hruid))).toEqual(
|
||||
new Set(expectedNode.transitions.map((it) => it.next.learningObjectHruid))
|
||||
);
|
||||
expect(new Set(node.transitions.map((it) => it.next.language))).toEqual(new Set(expectedNode.transitions.map((it) => it.next.language)));
|
||||
expect(new Set(node.transitions.map((it) => it.next.version))).toEqual(new Set(expectedNode.transitions.map((it) => it.next.version)));
|
||||
}
|
||||
}
|
10
backend/tests/test-utils/load-test-asset.ts
Normal file
10
backend/tests/test-utils/load-test-asset.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import fs from 'fs';
|
||||
import path from 'node:path';
|
||||
|
||||
/**
|
||||
* Load the asset at the given path.
|
||||
* @param relPath Path of the asset relative to the test-assets folder.
|
||||
*/
|
||||
export function loadTestAsset(relPath: string): Buffer {
|
||||
return fs.readFileSync(path.resolve(__dirname, `../test-assets/${relPath}`));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue