style: fix linting issues met ESLint

This commit is contained in:
Lint Action 2025-03-11 03:09:08 +00:00
parent a30c4d0d32
commit aa1a85e64e
24 changed files with 76 additions and 90 deletions

View file

@ -11,10 +11,10 @@ import {LearningObjectIdentifier} from "../../../src/entities/content/learning-o
const NEWER_TEST_SUFFIX = "nEweR";
function createTestLearningObjects(learningObjectRepo: LearningObjectRepository): {older: LearningObject, newer: LearningObject} {
let olderExample = example.createLearningObject();
const olderExample = example.createLearningObject();
learningObjectRepo.save(olderExample);
let newerExample = example.createLearningObject();
const newerExample = example.createLearningObject();
newerExample.title = "Newer example";
newerExample.version = 100;
@ -40,7 +40,7 @@ describe("AttachmentRepository", () => {
.values(example.createAttachment)
.map(fn => fn(exampleLearningObjects.older));
for (let attachment of attachmentsOlderLearningObject) {
for (const attachment of attachmentsOlderLearningObject) {
attachmentRepo.save(attachment);
}
});

View file

@ -12,8 +12,8 @@ import {FilteredLearningObject} from "../../../src/interfaces/learning-content";
import {Language} from "../../../src/entities/content/language";
async function initExampleData(): Promise<LearningObject> {
let learningObjectRepo = getLearningObjectRepository();
let exampleLearningObject = createExampleLearningObjectWithAttachments(example);
const learningObjectRepo = getLearningObjectRepository();
const exampleLearningObject = createExampleLearningObjectWithAttachments(example);
await learningObjectRepo.insert(exampleLearningObject);
return exampleLearningObject;
}

View file

@ -18,7 +18,7 @@ const DWENGO_TEST_LEARNING_OBJECT_ID: LearningObjectIdentifier = {
async function initExampleData(): Promise<LearningObject> {
const learningObjectRepo = getLearningObjectRepository();
let learningObject = learningObjectExample.createLearningObject();
const learningObject = learningObjectExample.createLearningObject();
learningObject.title = TEST_LEARNING_OBJECT_TITLE
await learningObjectRepo.save(learningObject);
return learningObject;

View file

@ -14,8 +14,8 @@ import {Language} from "../../../src/entities/content/language";
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 };
@ -55,7 +55,7 @@ describe("DatabaseLearningPathProvider", () => {
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
Language.Abkhazian, // Wrong language
"the source"
);

View file

@ -11,8 +11,8 @@ import learningPathService from "../../../src/services/learning-paths/learning-p
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 };
@ -76,7 +76,7 @@ describe("LearningPathService", () => {
).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 () => {
@ -88,7 +88,7 @@ describe("LearningPathService", () => {
// Should find something...
expect(result.length).not.toBe(0);
// but not the example learning path.
// But not the example learning path.
expect(
result.filter(it =>
it.hruid === example.learningPath.hruid && it.title === example.learningPath.title

View file

@ -2,8 +2,8 @@ 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

@ -10,7 +10,7 @@ const ASSETS_PREFIX = "learning-objects/pn-werkingnotebooks/";
const example: LearningObjectExample = {
createLearningObject: ()=> {
let learningObject = new LearningObject();
const learningObject = new LearningObject();
learningObject.hruid = `${getEnvVar(EnvVars.UserContentPrefix)}pn_werkingnotebooks`;
learningObject.version = 3;
learningObject.language = Language.Dutch;
@ -18,11 +18,11 @@ const example: LearningObjectExample = {
learningObject.description = "Leren werken met notebooks";
learningObject.keywords = ["Python", "KIKS", "Wiskunde", "STEM", "AI"]
let educationalGoal1 = new EducationalGoal();
const educationalGoal1 = new EducationalGoal();
educationalGoal1.source = "Source";
educationalGoal1.id = "id";
let educationalGoal2 = new EducationalGoal();
const educationalGoal2 = new EducationalGoal();
educationalGoal2.source = "Source2";
educationalGoal2.id = "id2";
@ -39,7 +39,7 @@ const example: LearningObjectExample = {
learningObject.license = "dwengo";
learningObject.estimatedTime = 10;
let returnValue = new ReturnValue();
const returnValue = new ReturnValue();
returnValue.callbackUrl = "callback_url_example";
returnValue.callbackSchema = '{"att": "test", "att2": "test2"}';
@ -51,7 +51,7 @@ const example: LearningObjectExample = {
},
createAttachment: {
dwengoLogo: (learningObject) => {
let att = new Attachment();
const att = new Attachment();
att.learningObject = learningObject;
att.name = "dwengo.png";
att.mimeType = "image/png";
@ -59,7 +59,7 @@ const example: LearningObjectExample = {
return att;
},
knop: (learningObject) => {
let att = new Attachment();
const att = new Attachment();
att.learningObject = learningObject;
att.name = "Knop.png";
att.mimeType = "image/png";

View file

@ -4,7 +4,7 @@ import {LearningPathNode} from "../../../src/entities/content/learning-path-node
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";
@ -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

@ -5,7 +5,7 @@ import {createLearningPathNode, createLearningPathTransition} from "./learning-p
import {LearningPathNode} from "../../../src/entities/content/learning-path-node.entity";
function createNodes(learningPath: LearningPath): LearningPathNode[] {
let nodes = [
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),

View file

@ -22,7 +22,7 @@ export function expectToBeCorrectEntity<T extends object>(
if (!expected.name) {
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.
@ -34,10 +34,10 @@ export function expectToBeCorrectEntity<T extends object>(
});
}
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 (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]) {
@ -78,7 +78,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);
@ -123,21 +123,21 @@ export function expectToBeCorrectLearningPath(
expect(learningPath.num_nodes).toEqual(expectedEntity.nodes.length);
expect(learningPath.image || null).toEqual(expectedEntity.image);
let expectedLearningPathNodes = new Map(
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
};
expect(expectedLearningPathNodes.keys()).toContainEqual(nodeKey);
let expectedNode = [...expectedLearningPathNodes.entries()]
const expectedNode = [...expectedLearningPathNodes.entries()]
.filter(([key, _]) =>
key.learningObjectHruid === nodeKey.learningObjectHruid
&& key.language === node.language