Merge remote-tracking branch 'origin/feature/own-learning-objects' into feature/own-learning-objects

# Conflicts:
#	backend/src/services/learning-objects/database-learning-object-provider.ts
#	backend/tests/services/learning-objects/database-learning-object-provider.test.ts
#	backend/tests/test-utils/expectations.ts
This commit is contained in:
Gerald Schmittinger 2025-03-11 04:45:09 +01:00
commit 9f28e4ed17
84 changed files with 874 additions and 1048 deletions

View file

@ -1,21 +1,21 @@
import {beforeAll, describe, expect, it} from "vitest";
import {setupTestApp} from "../../setup-tests";
import {getAttachmentRepository, getLearningObjectRepository} from "../../../src/data/repositories";
import {AttachmentRepository} from "../../../src/data/content/attachment-repository";
import {LearningObjectRepository} from "../../../src/data/content/learning-object-repository";
import example from "../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example";
import {LearningObject} from "../../../src/entities/content/learning-object.entity";
import {Attachment} from "../../../src/entities/content/attachment.entity";
import {LearningObjectIdentifier} from "../../../src/entities/content/learning-object-identifier";
import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests';
import { getAttachmentRepository, getLearningObjectRepository } from '../../../src/data/repositories';
import { AttachmentRepository } from '../../../src/data/content/attachment-repository';
import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository';
import example from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example';
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
import { Attachment } from '../../../src/entities/content/attachment.entity';
import { LearningObjectIdentifier } from '../../../src/entities/content/learning-object-identifier';
const NEWER_TEST_SUFFIX = "nEweR";
const NEWER_TEST_SUFFIX = 'nEweR';
function createTestLearningObjects(learningObjectRepo: LearningObjectRepository): {older: LearningObject, newer: LearningObject} {
let olderExample = example.createLearningObject();
function createTestLearningObjects(learningObjectRepo: LearningObjectRepository): { older: LearningObject; newer: LearningObject } {
const olderExample = example.createLearningObject();
learningObjectRepo.save(olderExample);
let newerExample = example.createLearningObject();
newerExample.title = "Newer example";
const newerExample = example.createLearningObject();
newerExample.title = 'Newer example';
newerExample.version = 100;
return {
@ -24,9 +24,9 @@ function createTestLearningObjects(learningObjectRepo: LearningObjectRepository)
};
}
describe("AttachmentRepository", () => {
describe('AttachmentRepository', () => {
let attachmentRepo: AttachmentRepository;
let exampleLearningObjects: {older: LearningObject, newer: LearningObject};
let exampleLearningObjects: { older: LearningObject; newer: LearningObject };
let attachmentsOlderLearningObject: Attachment[];
beforeAll(async () => {
@ -35,18 +35,16 @@ describe("AttachmentRepository", () => {
exampleLearningObjects = createTestLearningObjects(getLearningObjectRepository());
});
it("can add attachments to learning objects without throwing an error", () => {
attachmentsOlderLearningObject = Object
.values(example.createAttachment)
.map(fn => fn(exampleLearningObjects.older));
it('can add attachments to learning objects without throwing an error', () => {
attachmentsOlderLearningObject = Object.values(example.createAttachment).map((fn) => fn(exampleLearningObjects.older));
for (let attachment of attachmentsOlderLearningObject) {
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", () => {
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);
@ -54,29 +52,23 @@ describe("AttachmentRepository", () => {
});
let olderLearningObjectId: LearningObjectIdentifier;
it("returns the correct attachment when queried by learningObjectId and attachment name", async () => {
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
version: exampleLearningObjects.older.version,
};
const result = await attachmentRepo.findByLearningObjectIdAndName(
olderLearningObjectId,
attachmentsOlderLearningObject[0].name
);
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"
);
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 () => {
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,

View file

@ -1,12 +1,12 @@
import {beforeAll, describe, it, expect} from "vitest";
import {LearningObjectRepository} from "../../../src/data/content/learning-object-repository";
import {setupTestApp} from "../../setup-tests";
import {getLearningObjectRepository} from "../../../src/data/repositories";
import example from "../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example.js"
import {LearningObject} from "../../../src/entities/content/learning-object.entity";
import {expectToBeCorrectEntity} from "../../test-utils/expectations";
import { beforeAll, describe, it, expect } from 'vitest';
import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository';
import { setupTestApp } from '../../setup-tests';
import { getLearningObjectRepository } from '../../../src/data/repositories';
import example from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example.js';
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
import { expectToBeCorrectEntity } from '../../test-utils/expectations';
describe("LearningObjectRepository", () => {
describe('LearningObjectRepository', () => {
let learningObjectRepository: LearningObjectRepository;
let exampleLearningObject: LearningObject;
@ -16,55 +16,57 @@ describe("LearningObjectRepository", () => {
learningObjectRepository = getLearningObjectRepository();
});
it("should be able to add a learning object to it without an error", async () => {
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 () => {
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
version: exampleLearningObject.version,
});
expect(result).toBeInstanceOf(LearningObject);
expectToBeCorrectEntity({
name: "actual",
entity: result!
}, {
name: "expected",
entity: exampleLearningObject
});
expectToBeCorrectEntity(
{
name: 'actual',
entity: result!,
},
{
name: 'expected',
entity: exampleLearningObject,
}
);
});
it("should return null when non-existing version is queried", async () => {
it('should return null when non-existing version is queried', async () => {
const result = await learningObjectRepository.findByIdentifier({
hruid: exampleLearningObject.hruid,
language: exampleLearningObject.language,
version: 100
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 () => {
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)";
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 () => {
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)");
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);
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);
});
});

View file

@ -1,24 +1,24 @@
import {beforeAll, describe, expect, it} from "vitest";
import {setupTestApp} from "../../setup-tests";
import {getLearningPathRepository} from "../../../src/data/repositories";
import {LearningPathRepository} from "../../../src/data/content/learning-path-repository";
import example from "../../test-assets/learning-paths/pn-werking-example";
import {LearningPath} from "../../../src/entities/content/learning-path.entity";
import {expectToBeCorrectEntity} from "../../test-utils/expectations";
import {Language} from "../../../src/entities/content/language";
import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests';
import { getLearningPathRepository } from '../../../src/data/repositories';
import { LearningPathRepository } from '../../../src/data/content/learning-path-repository';
import example from '../../test-assets/learning-paths/pn-werking-example';
import { LearningPath } from '../../../src/entities/content/learning-path.entity';
import { expectToBeCorrectEntity } from '../../test-utils/expectations';
import { Language } from '../../../src/entities/content/language';
function expectToHaveFoundPrecisely(expected: LearningPath, result: LearningPath[]): void {
expect(result).toHaveProperty("length");
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).toHaveProperty('length');
expect(result.length).toBe(0);
}
describe("LearningPathRepository", () => {
describe('LearningPathRepository', () => {
let learningPathRepo: LearningPathRepository;
beforeAll(async () => {
@ -28,51 +28,39 @@ describe("LearningPathRepository", () => {
let examplePath: LearningPath;
it("should be able to add a learning path without throwing an error", async () => {
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 () => {
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);
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
);
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
);
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
);
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
);
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);
});
});

View file

@ -23,7 +23,7 @@ async function initExampleData(): Promise<{learningObject: LearningObject, learn
const EXPECTED_TITLE_FROM_DWENGO_LEARNING_OBJECT = "Notebook opslaan";
describe("DatabaseLearningObjectProvider", () => {
describe('DatabaseLearningObjectProvider', () => {
let exampleLearningObject: LearningObject;
let exampleLearningPath: LearningPath;
@ -33,32 +33,32 @@ describe("DatabaseLearningObjectProvider", () => {
exampleLearningObject = exampleData.learningObject;
exampleLearningPath = exampleData.learningPath;
});
describe("getLearningObjectById", () => {
it("should return the learning object when it is queried by its id", async () => {
describe('getLearningObjectById', () => {
it('should return the learning object when it is queried by its id', async () => {
const result: FilteredLearningObject | null = await databaseLearningObjectProvider.getLearningObjectById(exampleLearningObject);
expect(result).toBeTruthy();
expectToBeCorrectFilteredLearningObject(result!, exampleLearningObject);
});
it("should return the learning object when it is queried by only hruid and language (but not version)", async () => {
it('should return the learning object when it is queried by only hruid and language (but not version)', async () => {
const result: FilteredLearningObject | null = await databaseLearningObjectProvider.getLearningObjectById({
hruid: exampleLearningObject.hruid,
language: exampleLearningObject.language
language: exampleLearningObject.language,
});
expect(result).toBeTruthy();
expectToBeCorrectFilteredLearningObject(result!, exampleLearningObject);
});
it("should return null when queried with an id that does not exist", async () => {
it('should return null when queried with an id that does not exist', async () => {
const result: FilteredLearningObject | null = await databaseLearningObjectProvider.getLearningObjectById({
hruid: "non_existing_hruid",
language: Language.Dutch
hruid: 'non_existing_hruid',
language: Language.Dutch,
});
expect(result).toBeNull();
});
});
describe("getLearningObjectHTML", () => {
it("should return the correct rendering of the learning object", async () => {
describe('getLearningObjectHTML', () => {
it('should return the correct rendering of the learning object', async () => {
const result = await databaseLearningObjectProvider.getLearningObjectHTML(exampleLearningObject);
expect(result).toEqual(example.getHTMLRendering());
});

View file

@ -1,30 +1,30 @@
import {beforeAll, describe, expect, it} from "vitest";
import {setupTestApp} from "../../setup-tests";
import {LearningObject} from "../../../src/entities/content/learning-object.entity";
import {getLearningObjectRepository} from "../../../src/data/repositories";
import learningObjectExample from "../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example";
import learningObjectService from "../../../src/services/learning-objects/learning-object-service";
import {LearningObjectIdentifier} from "../../../src/interfaces/learning-content";
import {Language} from "../../../src/entities/content/language";
import {EnvVars, getEnvVar} from "../../../src/util/envvars";
import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests';
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
import { getLearningObjectRepository } from '../../../src/data/repositories';
import learningObjectExample from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example';
import learningObjectService from '../../../src/services/learning-objects/learning-object-service';
import { LearningObjectIdentifier } from '../../../src/interfaces/learning-content';
import { Language } from '../../../src/entities/content/language';
import { EnvVars, getEnvVar } from '../../../src/util/envvars';
const TEST_LEARNING_OBJECT_TITLE = "Test title";
const EXPECTED_DWENGO_LEARNING_OBJECT_TITLE = "Werken met notebooks";
const TEST_LEARNING_OBJECT_TITLE = 'Test title';
const EXPECTED_DWENGO_LEARNING_OBJECT_TITLE = 'Werken met notebooks';
const DWENGO_TEST_LEARNING_OBJECT_ID: LearningObjectIdentifier = {
hruid: "pn_werkingnotebooks",
hruid: 'pn_werkingnotebooks',
language: Language.Dutch,
version: 3
version: 3,
};
async function initExampleData(): Promise<LearningObject> {
const learningObjectRepo = getLearningObjectRepository();
let learningObject = learningObjectExample.createLearningObject();
learningObject.title = TEST_LEARNING_OBJECT_TITLE
const learningObject = learningObjectExample.createLearningObject();
learningObject.title = TEST_LEARNING_OBJECT_TITLE;
await learningObjectRepo.save(learningObject);
return learningObject;
}
describe("LearningObjectService", () => {
describe('LearningObjectService', () => {
let exampleLearningObject: LearningObject;
beforeAll(async () => {
@ -32,47 +32,50 @@ describe("LearningObjectService", () => {
exampleLearningObject = await initExampleData();
});
describe("getLearningObjectById", () => {
it("returns the learning object from the Dwengo API if it does not have the user content prefix", async () => {
describe('getLearningObjectById', () => {
it('returns the learning object from the Dwengo API if it does not have the user content prefix', async () => {
const result = await learningObjectService.getLearningObjectById(DWENGO_TEST_LEARNING_OBJECT_ID);
expect(result).not.toBeNull();
expect(result?.title).toBe(EXPECTED_DWENGO_LEARNING_OBJECT_TITLE);
});
it("returns the learning object from the database if it does have the user content prefix", async () => {
it('returns the learning object from the database if it does have the user content prefix', async () => {
const result = await learningObjectService.getLearningObjectById(exampleLearningObject);
expect(result).not.toBeNull();
expect(result?.title).toBe(exampleLearningObject.title);
});
it("returns null if the hruid does not have the user content prefix and does not exist in the Dwengo repo", async () => {
it('returns null if the hruid does not have the user content prefix and does not exist in the Dwengo repo', async () => {
const result = await learningObjectService.getLearningObjectById({
hruid: "non-existing",
language: Language.Dutch
hruid: 'non-existing',
language: Language.Dutch,
});
expect(result).toBeNull();
});
});
describe("getLearningObjectHTML", () => {
it("returns the expected HTML when queried with the identifier of a learning object saved in the database", async () => {
describe('getLearningObjectHTML', () => {
it('returns the expected HTML when queried with the identifier of a learning object saved in the database', async () => {
const result = await learningObjectService.getLearningObjectHTML(exampleLearningObject);
expect(result).not.toBeNull();
expect(result).toEqual(learningObjectExample.getHTMLRendering());
});
it("returns the same HTML as the Dwengo API when queried with the identifier of a learning object that does " +
"not start with the user content prefix", async () => {
const result = await learningObjectService.getLearningObjectHTML(DWENGO_TEST_LEARNING_OBJECT_ID);
expect(result).not.toBeNull();
it(
'returns the same HTML as the Dwengo API when queried with the identifier of a learning object that does ' +
'not start with the user content prefix',
async () => {
const result = await learningObjectService.getLearningObjectHTML(DWENGO_TEST_LEARNING_OBJECT_ID);
expect(result).not.toBeNull();
const htmlFromDwengoApi = await fetch(
getEnvVar(EnvVars.LearningContentRepoApiBaseUrl)
+ `/learningObject/getRaw?hruid=${DWENGO_TEST_LEARNING_OBJECT_ID.hruid}&language=${DWENGO_TEST_LEARNING_OBJECT_ID.language}&version=${DWENGO_TEST_LEARNING_OBJECT_ID.version}`
).then(it => it.text());
expect(result).toEqual(htmlFromDwengoApi);
});
it("returns null when queried with a non-existing identifier", async () => {
const htmlFromDwengoApi = await fetch(
getEnvVar(EnvVars.LearningContentRepoApiBaseUrl) +
`/learningObject/getRaw?hruid=${DWENGO_TEST_LEARNING_OBJECT_ID.hruid}&language=${DWENGO_TEST_LEARNING_OBJECT_ID.language}&version=${DWENGO_TEST_LEARNING_OBJECT_ID.version}`
).then((it) => it.text());
expect(result).toEqual(htmlFromDwengoApi);
}
);
it('returns null when queried with a non-existing identifier', async () => {
const result = await learningObjectService.getLearningObjectHTML({
hruid: "non_existing_hruid",
language: Language.Dutch
hruid: 'non_existing_hruid',
language: Language.Dutch,
});
expect(result).toBeNull();
});

View file

@ -1,23 +1,23 @@
import {describe, expect, it} from "vitest";
import mdExample from "../../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example";
import multipleChoiceExample from "../../../test-assets/learning-objects/test-multiple-choice/test-multiple-choice-example";
import essayExample from "../../../test-assets/learning-objects/test-essay/test-essay-example";
import processingService from "../../../../src/services/learning-objects/processing/processing-service";
import { describe, expect, it } from 'vitest';
import mdExample from '../../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example';
import multipleChoiceExample from '../../../test-assets/learning-objects/test-multiple-choice/test-multiple-choice-example';
import essayExample from '../../../test-assets/learning-objects/test-essay/test-essay-example';
import processingService from '../../../../src/services/learning-objects/processing/processing-service';
describe("ProcessingService", () => {
it("renders a markdown learning object correctly", async () => {
describe('ProcessingService', () => {
it('renders a markdown learning object correctly', async () => {
const markdownLearningObject = mdExample.createLearningObject();
const result = await processingService.render(markdownLearningObject);
expect(result).toEqual(mdExample.getHTMLRendering());
});
it("renders a multiple choice question correctly", async () => {
it('renders a multiple choice question correctly', async () => {
const multipleChoiceLearningObject = multipleChoiceExample.createLearningObject();
const result = await processingService.render(multipleChoiceLearningObject);
expect(result).toEqual(multipleChoiceExample.getHTMLRendering());
});
it("renders an essay question correctly", async () => {
it('renders an essay question correctly', async () => {
const essayLearningObject = essayExample.createLearningObject();
const result = await processingService.render(essayLearningObject);
expect(result).toEqual(essayExample.getHTMLRendering());

View file

@ -1,29 +1,29 @@
import {beforeAll, describe, expect, it} from "vitest";
import {LearningObject} from "../../../src/entities/content/learning-object.entity";
import {setupTestApp} from "../../setup-tests";
import {LearningPath} from "../../../src/entities/content/learning-path.entity";
import {getLearningObjectRepository, getLearningPathRepository} from "../../../src/data/repositories";
import learningObjectExample from "../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example";
import learningPathExample from "../../test-assets/learning-paths/pn-werking-example"
import databaseLearningPathProvider from "../../../src/services/learning-paths/database-learning-path-provider";
import {expectToBeCorrectLearningPath} from "../../test-utils/expectations";
import {LearningObjectRepository} from "../../../src/data/content/learning-object-repository";
import learningObjectService from "../../../src/services/learning-objects/learning-object-service";
import {Language} from "../../../src/entities/content/language";
import { beforeAll, describe, expect, it } from 'vitest';
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
import { setupTestApp } from '../../setup-tests';
import { LearningPath } from '../../../src/entities/content/learning-path.entity';
import { getLearningObjectRepository, getLearningPathRepository } from '../../../src/data/repositories';
import learningObjectExample from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example';
import learningPathExample from '../../test-assets/learning-paths/pn-werking-example';
import databaseLearningPathProvider from '../../../src/services/learning-paths/database-learning-path-provider';
import { expectToBeCorrectLearningPath } from '../../test-utils/expectations';
import { LearningObjectRepository } from '../../../src/data/content/learning-object-repository';
import learningObjectService from '../../../src/services/learning-objects/learning-object-service';
import { Language } from '../../../src/entities/content/language';
async function initExampleData(): Promise<{ learningObject: LearningObject, learningPath: LearningPath }> {
async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> {
const learningObjectRepo = getLearningObjectRepository();
const learningPathRepo = getLearningPathRepository();
let learningObject = learningObjectExample.createLearningObject();
let learningPath = learningPathExample.createLearningPath();
const learningObject = learningObjectExample.createLearningObject();
const learningPath = learningPathExample.createLearningPath();
await learningObjectRepo.save(learningObject);
await learningPathRepo.save(learningPath);
return { learningObject, learningPath };
}
describe("DatabaseLearningPathProvider", () => {
describe('DatabaseLearningPathProvider', () => {
let learningObjectRepo: LearningObjectRepository;
let example: {learningObject: LearningObject, learningPath: LearningPath};
let example: { learningObject: LearningObject; learningPath: LearningPath };
beforeAll(async () => {
await setupTestApp();
@ -31,40 +31,43 @@ describe("DatabaseLearningPathProvider", () => {
learningObjectRepo = getLearningObjectRepository();
});
describe("fetchLearningPaths", () => {
it("returns the learning path correctly", async () => {
describe('fetchLearningPaths', () => {
it('returns the learning path correctly', async () => {
const result = await databaseLearningPathProvider.fetchLearningPaths(
[example.learningPath.hruid],
example.learningPath.language,
"the source"
'the source'
);
expect(result.success).toBe(true);
expect(result.data?.length).toBe(1);
const learningObjectsOnPath = (await Promise.all(
example.learningPath.nodes.map(node =>
learningObjectService.getLearningObjectById({
hruid: node.learningObjectHruid,
version: node.version,
language: node.language
}))
)).filter(it => it !== null);
const learningObjectsOnPath = (
await Promise.all(
example.learningPath.nodes.map((node) =>
learningObjectService.getLearningObjectById({
hruid: node.learningObjectHruid,
version: node.version,
language: node.language,
})
)
)
).filter((it) => it !== null);
expectToBeCorrectLearningPath(result.data![0], example.learningPath, learningObjectsOnPath)
expectToBeCorrectLearningPath(result.data![0], example.learningPath, learningObjectsOnPath);
});
it("returns a non-successful response if a non-existing learning path is queried", async () => {
it('returns a non-successful response if a non-existing learning path is queried', async () => {
const result = await databaseLearningPathProvider.fetchLearningPaths(
[example.learningPath.hruid],
Language.Abkhazian, // wrong language
"the source"
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 () => {
describe('searchLearningPaths', () => {
it('returns the correct learning path when queried with a substring of its title', async () => {
const result = await databaseLearningPathProvider.searchLearningPaths(
example.learningPath.title.substring(2, 6),
example.learningPath.language
@ -73,7 +76,7 @@ describe("DatabaseLearningPathProvider", () => {
expect(result[0].title).toBe(example.learningPath.title);
expect(result[0].description).toBe(example.learningPath.description);
});
it("returns the correct learning path when queried with a substring of the description", async () => {
it('returns the correct learning path when queried with a substring of the description', async () => {
const result = await databaseLearningPathProvider.searchLearningPaths(
example.learningPath.description.substring(5, 12),
example.learningPath.language
@ -82,9 +85,9 @@ describe("DatabaseLearningPathProvider", () => {
expect(result[0].title).toBe(example.learningPath.title);
expect(result[0].description).toBe(example.learningPath.description);
});
it("returns an empty result when queried with a text which is not a substring of the title or the description of a learning path", async () => {
it('returns an empty result when queried with a text which is not a substring of the title or the description of a learning path', async () => {
const result = await databaseLearningPathProvider.searchLearningPaths(
"substring which does not occur in the title or the description of a learning object",
'substring which does not occur in the title or the description of a learning object',
example.learningPath.language
);
expect(result.length).toBe(0);

View file

@ -1,105 +1,80 @@
import {beforeAll, describe, expect, it} from "vitest";
import {setupTestApp} from "../../setup-tests";
import {LearningObject} from "../../../src/entities/content/learning-object.entity";
import {LearningPath} from "../../../src/entities/content/learning-path.entity";
import {getLearningObjectRepository, getLearningPathRepository} from "../../../src/data/repositories";
import learningObjectExample from "../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example";
import learningPathExample from "../../test-assets/learning-paths/pn-werking-example";
import {Language} from "../../../src/entities/content/language";
import learningPathService from "../../../src/services/learning-paths/learning-path-service";
import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests';
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
import { LearningPath } from '../../../src/entities/content/learning-path.entity';
import { getLearningObjectRepository, getLearningPathRepository } from '../../../src/data/repositories';
import learningObjectExample from '../../test-assets/learning-objects/pn-werkingnotebooks/pn-werkingnotebooks-example';
import learningPathExample from '../../test-assets/learning-paths/pn-werking-example';
import { Language } from '../../../src/entities/content/language';
import learningPathService from '../../../src/services/learning-paths/learning-path-service';
async function initExampleData(): Promise<{ learningObject: LearningObject, learningPath: LearningPath }> {
async function initExampleData(): Promise<{ learningObject: LearningObject; learningPath: LearningPath }> {
const learningObjectRepo = getLearningObjectRepository();
const learningPathRepo = getLearningPathRepository();
let learningObject = learningObjectExample.createLearningObject();
let learningPath = learningPathExample.createLearningPath();
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";
const TEST_DWENGO_LEARNING_PATH_HRUID = 'pn_werking';
const TEST_DWENGO_LEARNING_PATH_TITLE = 'Werken met notebooks';
const TEST_DWENGO_EXCLUSIVE_LEARNING_PATH_SEARCH_QUERY = 'Microscopie';
const TEST_SEARCH_QUERY_EXPECTING_NO_MATCHES = 'su$m8f9usf89ud<p9<U8SDP8UP9';
describe("LearningPathService", () => {
let example: { learningObject: LearningObject, learningPath: LearningPath };
describe('LearningPathService', () => {
let example: { learningObject: LearningObject; learningPath: LearningPath };
beforeAll(async () => {
await setupTestApp();
example = await initExampleData();
});
describe("fetchLearningPaths", () => {
it("should return learning paths both from the database and from the Dwengo API", async () => {
describe('fetchLearningPaths', () => {
it('should return learning paths both from the database and from the Dwengo API', async () => {
const result = await learningPathService.fetchLearningPaths(
[example.learningPath.hruid, TEST_DWENGO_LEARNING_PATH_HRUID],
example.learningPath.language,
"the source"
'the source'
);
expect(result.success).toBeTruthy();
expect(result.data?.filter(it => it.hruid == TEST_DWENGO_LEARNING_PATH_HRUID).length).not.toBe(0);
expect(result.data?.filter(it => it.hruid == example.learningPath.hruid).length).not.toBe(0);
expect(result.data?.filter(it => it.hruid == TEST_DWENGO_LEARNING_PATH_HRUID)[0].title)
.toEqual(TEST_DWENGO_LEARNING_PATH_TITLE);
expect(result.data?.filter(it => it.hruid == example.learningPath.hruid)[0].title)
.toEqual(example.learningPath.title);
expect(result.data?.filter((it) => it.hruid == TEST_DWENGO_LEARNING_PATH_HRUID).length).not.toBe(0);
expect(result.data?.filter((it) => it.hruid == example.learningPath.hruid).length).not.toBe(0);
expect(result.data?.filter((it) => it.hruid == TEST_DWENGO_LEARNING_PATH_HRUID)[0].title).toEqual(TEST_DWENGO_LEARNING_PATH_TITLE);
expect(result.data?.filter((it) => it.hruid == example.learningPath.hruid)[0].title).toEqual(example.learningPath.title);
});
it("should include both the learning objects from the Dwengo API and learning objects from the database in its response", async () => {
const result = await learningPathService.fetchLearningPaths(
[example.learningPath.hruid],
example.learningPath.language,
"the source"
);
it('should include both the learning objects from the Dwengo API and learning objects from the database in its response', async () => {
const result = await learningPathService.fetchLearningPaths([example.learningPath.hruid], example.learningPath.language, 'the source');
expect(result.success).toBeTruthy();
expect(result.data?.length).toBe(1);
// Should include all the nodes, even those pointing to foreign learning objects.
expect(
[...result.data![0].nodes.map(it => it.learningobject_hruid)].sort()
).toEqual(
example.learningPath.nodes.map(it => it.learningObjectHruid).sort()
expect([...result.data![0].nodes.map((it) => it.learningobject_hruid)].sort()).toEqual(
example.learningPath.nodes.map((it) => it.learningObjectHruid).sort()
);
});
});
describe("searchLearningPath", () => {
it("should include both the learning paths from the Dwengo API and those from the database in its response", async () => {
describe('searchLearningPath', () => {
it('should include both the learning paths from the Dwengo API and those from the database in its response', async () => {
// This matches the learning object in the database, but definitely also some learning objects in the Dwengo API.
const result = await learningPathService.searchLearningPaths(
example.learningPath.title.substring(2, 3),
example.learningPath.language
);
const result = await learningPathService.searchLearningPaths(example.learningPath.title.substring(2, 3), example.learningPath.language);
// Should find the one from the database
expect(
result.filter(it =>
it.hruid === example.learningPath.hruid && it.title === example.learningPath.title
).length
).toBe(1);
expect(result.filter((it) => it.hruid === example.learningPath.hruid && it.title === example.learningPath.title).length).toBe(1);
// but should not only find that one.
// But should not only find that one.
expect(result.length).not.toBeLessThan(2);
});
it("should still return results from the Dwengo API even though there are no matches in the database", async () => {
const result = await learningPathService.searchLearningPaths(
TEST_DWENGO_EXCLUSIVE_LEARNING_PATH_SEARCH_QUERY,
Language.Dutch
);
it('should still return results from the Dwengo API even though there are no matches in the database', async () => {
const result = await learningPathService.searchLearningPaths(TEST_DWENGO_EXCLUSIVE_LEARNING_PATH_SEARCH_QUERY, Language.Dutch);
// Should find something...
expect(result.length).not.toBe(0);
// but not the example learning path.
expect(
result.filter(it =>
it.hruid === example.learningPath.hruid && it.title === example.learningPath.title
).length
).toBe(0);
// 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
);
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);
});
});

View file

@ -1,9 +1,9 @@
import {LearningObjectExample} from "./learning-object-example";
import {LearningObject} from "../../../src/entities/content/learning-object.entity";
import { LearningObjectExample } from './learning-object-example';
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
export function createExampleLearningObjectWithAttachments(example: LearningObjectExample): LearningObject {
let learningObject = example.createLearningObject();
for (let creationFn of Object.values(example.createAttachment)) {
const learningObject = example.createLearningObject();
for (const creationFn of Object.values(example.createAttachment)) {
learningObject.attachments.push(creationFn(learningObject));
}
return learningObject;

View file

@ -1,8 +1,8 @@
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 { 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';
/**
* Create a dummy learning object to be used in tests where multiple learning objects are needed (for example for use
@ -16,12 +16,12 @@ export function dummyLearningObject(hruid: string, language: Language, title: st
learningObject.language = language;
learningObject.version = 1;
learningObject.title = title;
learningObject.description = "Just a dummy learning object for testing purposes";
learningObject.description = 'Just a dummy learning object for testing purposes';
learningObject.contentType = DwengoContentType.TEXT_PLAIN;
learningObject.content = Buffer.from("Dummy content");
learningObject.content = Buffer.from('Dummy content');
return learningObject;
},
createAttachment: {},
getHTMLRendering: () => loadTestAsset("learning-objects/dummy/rendering.html").toString()
}
getHTMLRendering: () => loadTestAsset('learning-objects/dummy/rendering.html').toString(),
};
}

View file

@ -1,8 +1,8 @@
import {LearningObject} from "../../../src/entities/content/learning-object.entity";
import {Attachment} from "../../../src/entities/content/attachment.entity";
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
createLearningObject: () => LearningObject;
createAttachment: { [key: string]: (owner: LearningObject) => Attachment };
getHTMLRendering: () => string;
};

View file

@ -4,7 +4,7 @@ Het lesmateriaal van 'Python in wiskunde en STEM' wordt aangeboden in de vorm va
_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.
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.
@ -12,14 +12,15 @@ Python is bovendien bezig aan een opmars en wordt gebruikt door bedrijven, zoals
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.)
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.
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.
[![](Knop.png "Knop")](https://kiks.ilabt.imec.be/hub/tmplogin?id=0101 "Notebooks Werking")
[![](Knop.png 'Knop')](https://kiks.ilabt.imec.be/hub/tmplogin?id=0101 'Notebooks Werking')

View file

@ -1,30 +1,30 @@
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";
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 ASSETS_PREFIX = 'learning-objects/pn-werkingnotebooks/';
const example: LearningObjectExample = {
createLearningObject: ()=> {
let learningObject = new LearningObject();
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"]
learningObject.title = 'Werken met notebooks';
learningObject.description = 'Leren werken met notebooks';
learningObject.keywords = ['Python', 'KIKS', 'Wiskunde', 'STEM', 'AI'];
let educationalGoal1 = new EducationalGoal();
educationalGoal1.source = "Source";
educationalGoal1.id = "id";
const educationalGoal1 = new EducationalGoal();
educationalGoal1.source = 'Source';
educationalGoal1.id = 'id';
let educationalGoal2 = new EducationalGoal();
educationalGoal2.source = "Source2";
educationalGoal2.id = "id2";
const educationalGoal2 = new EducationalGoal();
educationalGoal2.source = 'Source2';
educationalGoal2.id = 'id2';
learningObject.educationalGoals = [educationalGoal1, educationalGoal2];
learningObject.admins = [];
@ -33,40 +33,40 @@ const example: LearningObjectExample = {
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'
'http://ilearn.ilabt.imec.be/vocab/curr1/s-computers-en-systemen',
];
learningObject.copyright = "dwengo";
learningObject.license = "dwengo";
learningObject.copyright = 'dwengo';
learningObject.license = 'dwengo';
learningObject.estimatedTime = 10;
let returnValue = new ReturnValue();
returnValue.callbackUrl = "callback_url_example";
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
return learningObject;
},
createAttachment: {
dwengoLogo: (learningObject) => {
let att = new Attachment();
const att = new Attachment();
att.learningObject = learningObject;
att.name = "dwengo.png";
att.mimeType = "image/png";
att.content = loadTestAsset(`${ASSETS_PREFIX}/dwengo.png`)
att.name = 'dwengo.png';
att.mimeType = 'image/png';
att.content = loadTestAsset(`${ASSETS_PREFIX}/dwengo.png`);
return att;
},
knop: (learningObject) => {
let att = new Attachment();
const att = new Attachment();
att.learningObject = learningObject;
att.name = "Knop.png";
att.mimeType = "image/png";
att.content = loadTestAsset(`${ASSETS_PREFIX}/Knop.png`)
att.name = 'Knop.png';
att.mimeType = 'image/png';
att.content = loadTestAsset(`${ASSETS_PREFIX}/Knop.png`);
return att;
}
},
},
getHTMLRendering: () => loadTestAsset(`${ASSETS_PREFIX}/rendering.html`).toString()
}
getHTMLRendering: () => loadTestAsset(`${ASSETS_PREFIX}/rendering.html`).toString(),
};
export default example;

View file

@ -4,17 +4,44 @@
</a>
Werken met notebooks
</h1>
<p>Het lesmateriaal van &#39;Python in wiskunde en STEM&#39; 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>
Het lesmateriaal van &#39;Python in wiskunde en STEM&#39; 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 &#39;Open notebooks&#39;, 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>
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 &#39;Open notebooks&#39;, 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>
<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>

View file

@ -1,9 +1,9 @@
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";
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: () => {
@ -11,14 +11,14 @@ const example: LearningObjectExample = {
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.title = 'Essay question for testing';
learningObject.description = 'This essay question was only created for testing purposes.';
learningObject.contentType = DwengoContentType.GIFT;
learningObject.content = loadTestAsset("learning-objects/test-essay/content.txt");
learningObject.content = loadTestAsset('learning-objects/test-essay/content.txt');
return learningObject;
},
createAttachment: {},
getHTMLRendering: () => loadTestAsset("learning-objects/test-essay/rendering.html").toString()
getHTMLRendering: () => loadTestAsset('learning-objects/test-essay/rendering.html').toString(),
};
export default example;

View file

@ -3,11 +3,11 @@
<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">
<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">
<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>

View file

@ -1,9 +1,9 @@
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";
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: () => {
@ -11,14 +11,14 @@ const example: LearningObjectExample = {
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.title = 'Multiple choice question for testing';
learningObject.description = 'This multiple choice question was only created for testing purposes.';
learningObject.contentType = DwengoContentType.GIFT;
learningObject.content = loadTestAsset("learning-objects/test-multiple-choice/content.txt");
learningObject.content = loadTestAsset('learning-objects/test-multiple-choice/content.txt');
return learningObject;
},
createAttachment: {},
getHTMLRendering: () => loadTestAsset("learning-objects/test-multiple-choice/rendering.html").toString()
getHTMLRendering: () => loadTestAsset('learning-objects/test-multiple-choice/rendering.html').toString(),
};
export default example;

View file

@ -1,3 +1,3 @@
type LearningPathExample = {
createLearningPath: () => LearningPath
createLearningPath: () => LearningPath;
};

View file

@ -1,13 +1,13 @@
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";
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) {
let trans = new LearningPathTransition();
const trans = new LearningPathTransition();
trans.node = node;
trans.transitionNumber = transitionNumber;
trans.condition = condition || "true";
trans.condition = condition || 'true';
trans.next = to;
return trans;
}
@ -20,7 +20,7 @@ export function createLearningPathNode(
language: Language,
startNode: boolean
) {
let node = new LearningPathNode();
const node = new LearningPathNode();
node.learningPath = learningPath;
node.nodeNumber = nodeNumber;
node.learningObjectHruid = learningObjectHruid;

View file

@ -1,17 +1,17 @@
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";
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[] {
let 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),
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]));
nodes[0].transitions.push(createLearningPathTransition(nodes[0], 0, 'true', nodes[1]));
nodes[1].transitions.push(createLearningPathTransition(nodes[1], 0, 'true', nodes[2]));
return nodes;
}
@ -20,11 +20,11 @@ const example: LearningPathExample = {
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.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;

View file

@ -1,23 +1,27 @@
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 { 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';
const example: LearningPathExample = {
createLearningPath: () => {
const learningPath = new LearningPath();
learningPath.hruid = "test_conditions";
learningPath.hruid = '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";
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)"
'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)"
'test_final_learning_object',
Language.English,
'Final exercise (for everyone)'
).createLearningObject();
const branchingNode = createLearningPathNode(
@ -48,21 +52,11 @@ const example: LearningPathExample = {
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.
'$[?(@[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
);
const directTransitionToFinal = createLearningPathTransition(branchingNode, 1, '$[?(@[0] == 1)]', finalNode);
const transitionExtraExerciseToFinal = createLearningPathTransition(extraExerciseNode, 0, 'true', finalNode);
branchingNode.transitions = [transitionToExtraExercise, directTransitionToFinal];
extraExerciseNode.transitions = [transitionExtraExerciseToFinal];
@ -70,5 +64,5 @@ const example: LearningPathExample = {
learningPath.nodes = [branchingNode, extraExerciseNode, finalNode];
return learningPath;
}
},
};

View file

@ -1,63 +1,62 @@
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";
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"];
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 {
export function expectToBeCorrectEntity<T extends object>(actual: { entity: T; name?: string }, expected: { entity: T; name?: string }): void {
if (!actual.name) {
actual.name = "actual";
actual.name = 'actual';
}
if (!expected.name) {
expected.name = "expected";
expected.name = 'expected';
}
for (let property in expected.entity) {
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
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.`
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 (!!expected.entity[property] !== !!actual.entity[property]) {
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]} (${!!expected.entity[property]}) in ${actual.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}.`
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") {
} 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
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}`
message: `${property} was ${expected.entity[property]} in ${expected.name}, but ${actual.entity[property]} in ${actual.name}`,
});
}
}
@ -78,7 +77,7 @@ export function expectToBeCorrectFilteredLearningObject(filtered: FilteredLearni
expect(filtered.key).toEqual(original.hruid);
expect(filtered.targetAges).toEqual(original.targetAges);
expect(filtered.title).toEqual(original.title);
expect(!!filtered.teacherExclusive).toEqual(!!original.teacherExclusive) // !!: Workaround: MikroORM with SQLite returns 0 and 1 instead of booleans.
expect(Boolean(filtered.teacherExclusive)).toEqual(original.teacherExclusive); // !!: Workaround: MikroORM with SQLite returns 0 and 1 instead of booleans.
expect(filtered.skosConcepts).toEqual(original.skosConcepts);
expect(filtered.estimatedTime).toEqual(original.estimatedTime);
expect(filtered.educationalGoals).toEqual(original.educationalGoals);
@ -112,10 +111,10 @@ export function expectToBeCorrectLearningPath(
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 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 || []));
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));
@ -123,42 +122,29 @@ export function expectToBeCorrectLearningPath(
expect(learningPath.num_nodes).toEqual(expectedEntity.nodes.length);
expect(learningPath.image || null).toEqual(expectedEntity.image);
let expectedLearningPathNodes = new Map(
expectedEntity.nodes.map(node => [
{learningObjectHruid: node.learningObjectHruid, language: node.language, version: node.version},
{startNode: node.startNode, transitions: node.transitions}
const expectedLearningPathNodes = new Map(
expectedEntity.nodes.map((node) => [
{ learningObjectHruid: node.learningObjectHruid, language: node.language, version: node.version },
{ startNode: node.startNode, transitions: node.transitions },
])
);
for (let node of learningPath.nodes) {
for (const node of learningPath.nodes) {
const nodeKey = {
learningObjectHruid: node.learningobject_hruid,
language: node.language,
version: node.version
version: node.version,
};
expect(expectedLearningPathNodes.keys()).toContainEqual(nodeKey);
let expectedNode = [...expectedLearningPathNodes.entries()]
.filter(([key, _]) =>
key.learningObjectHruid === nodeKey.learningObjectHruid
&& key.language === node.language
&& key.version === node.version
)[0][1]
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))
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)));
}
}

View file

@ -1,5 +1,5 @@
import fs from "fs";
import path from "node:path";
import fs from 'fs';
import path from 'node:path';
/**
* Load the asset at the given path.