style: fix linting issues met Prettier

This commit is contained in:
Lint Action 2025-04-18 23:36:22 +00:00
parent af8c783a26
commit 5168ceaee0
56 changed files with 680 additions and 741 deletions

View file

@ -4,18 +4,12 @@ import { LearningObject } from '../../../src/entities/content/learning-object.en
import databaseLearningObjectProvider from '../../../src/services/learning-objects/database-learning-object-provider';
import { expectToBeCorrectFilteredLearningObject } from '../../test-utils/expectations';
import { Language } from '@dwengo-1/common/util/language';
import {
FilteredLearningObject,
LearningObjectNode,
LearningPathIdentifier
} from '@dwengo-1/common/interfaces/learning-content';
import {
testPartiallyDatabaseAndPartiallyDwengoApiLearningPath
} from "../../test_assets/content/learning-paths.testdata";
import {testLearningObjectPnNotebooks} from "../../test_assets/content/learning-objects.testdata";
import { FilteredLearningObject, LearningObjectNode, LearningPathIdentifier } from '@dwengo-1/common/interfaces/learning-content';
import { testPartiallyDatabaseAndPartiallyDwengoApiLearningPath } from '../../test_assets/content/learning-paths.testdata';
import { testLearningObjectPnNotebooks } from '../../test_assets/content/learning-objects.testdata';
import { LearningPath } from '@dwengo-1/common/dist/interfaces/learning-content';
import {RequiredEntityData} from "@mikro-orm/core";
import {getHtmlRenderingForTestLearningObject} from "../../test-utils/get-html-rendering";
import { RequiredEntityData } from '@mikro-orm/core';
import { getHtmlRenderingForTestLearningObject } from '../../test-utils/get-html-rendering';
const EXPECTED_TITLE_FROM_DWENGO_LEARNING_OBJECT = 'Notebook opslaan';
@ -31,7 +25,7 @@ describe('DatabaseLearningObjectProvider', () => {
exampleLearningPathId = {
hruid: exampleLearningPath.hruid,
language: exampleLearningPath.language as Language
language: exampleLearningPath.language as Language,
};
});
describe('getLearningObjectById', () => {
@ -75,9 +69,7 @@ describe('DatabaseLearningObjectProvider', () => {
describe('getLearningObjectIdsFromPath', () => {
it('should return all learning object IDs from a path', async () => {
const result = await databaseLearningObjectProvider.getLearningObjectIdsFromPath(exampleLearningPathId);
expect(new Set(result)).toEqual(
new Set(exampleLearningPath.nodes.map((it: LearningObjectNode) => it.learningobject_hruid))
);
expect(new Set(result)).toEqual(new Set(exampleLearningPath.nodes.map((it: LearningObjectNode) => it.learningobject_hruid)));
});
it('should throw an error if queried with a path identifier for which there is no learning path', async () => {
await expect(

View file

@ -3,18 +3,12 @@ import { setupTestApp } from '../../setup-tests';
import { LearningObject } from '../../../src/entities/content/learning-object.entity';
import learningObjectService from '../../../src/services/learning-objects/learning-object-service';
import { envVars, getEnvVar } from '../../../src/util/envVars';
import {
LearningObjectIdentifierDTO,
LearningPath as LearningPathDTO,
LearningPathIdentifier
} from '@dwengo-1/common/interfaces/learning-content';
import { LearningObjectIdentifierDTO, LearningPath as LearningPathDTO, LearningPathIdentifier } from '@dwengo-1/common/interfaces/learning-content';
import { Language } from '@dwengo-1/common/util/language';
import {testLearningObjectPnNotebooks} from "../../test_assets/content/learning-objects.testdata";
import {
testPartiallyDatabaseAndPartiallyDwengoApiLearningPath
} from "../../test_assets/content/learning-paths.testdata";
import {RequiredEntityData} from "@mikro-orm/core";
import {getHtmlRenderingForTestLearningObject} from "../../test-utils/get-html-rendering";
import { testLearningObjectPnNotebooks } from '../../test_assets/content/learning-objects.testdata';
import { testPartiallyDatabaseAndPartiallyDwengoApiLearningPath } from '../../test_assets/content/learning-paths.testdata';
import { RequiredEntityData } from '@mikro-orm/core';
import { getHtmlRenderingForTestLearningObject } from '../../test-utils/get-html-rendering';
const EXPECTED_DWENGO_LEARNING_OBJECT_TITLE = 'Werken met notebooks';
const DWENGO_TEST_LEARNING_OBJECT_ID: LearningObjectIdentifierDTO = {
@ -41,8 +35,8 @@ describe('LearningObjectService', () => {
exampleLearningPathId = {
hruid: exampleLearningPath.hruid,
language: exampleLearningPath.language as Language
}
language: exampleLearningPath.language as Language,
};
});
describe('getLearningObjectById', () => {
@ -99,9 +93,7 @@ describe('LearningObjectService', () => {
describe('getLearningObjectsFromPath', () => {
it('returns all learning objects when a learning path in the database is queried', async () => {
const result = await learningObjectService.getLearningObjectsFromPath(exampleLearningPathId);
expect(result.map(it=> it.key)).toEqual(
exampleLearningPath.nodes.map(it => it.learningobject_hruid)
);
expect(result.map((it) => it.key)).toEqual(exampleLearningPath.nodes.map((it) => it.learningobject_hruid));
});
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);
@ -119,7 +111,7 @@ describe('LearningObjectService', () => {
describe('getLearningObjectIdsFromPath', () => {
it('returns all learning objects when a learning path in the database is queried', async () => {
const result = await learningObjectService.getLearningObjectIdsFromPath(exampleLearningPathId);
expect(result).toEqual(exampleLearningPath.nodes.map(it => it.learningobject_hruid));
expect(result).toEqual(exampleLearningPath.nodes.map((it) => it.learningobject_hruid));
});
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);

View file

@ -1,12 +1,13 @@
import {beforeAll, describe, expect, it} from 'vitest';
import { beforeAll, describe, expect, it } from 'vitest';
import processingService from '../../../../src/services/learning-objects/processing/processing-service';
import {
testLearningObjectEssayQuestion,
testLearningObjectMultipleChoice, testLearningObjectPnNotebooks
} from "../../../test_assets/content/learning-objects.testdata";
import {getHtmlRenderingForTestLearningObject} from "../../../test-utils/get-html-rendering";
import {getLearningObjectRepository} from "../../../../src/data/repositories";
import {setupTestApp} from "../../../setup-tests";
testLearningObjectMultipleChoice,
testLearningObjectPnNotebooks,
} from '../../../test_assets/content/learning-objects.testdata';
import { getHtmlRenderingForTestLearningObject } from '../../../test-utils/get-html-rendering';
import { getLearningObjectRepository } from '../../../../src/data/repositories';
import { setupTestApp } from '../../../setup-tests';
describe('ProcessingService', () => {
beforeAll(async () => {
@ -17,24 +18,18 @@ describe('ProcessingService', () => {
const markdownLearningObject = getLearningObjectRepository().create(testLearningObjectPnNotebooks);
const result = await processingService.render(markdownLearningObject);
// Set newlines so your tests are platform-independent.
expect(result).toEqual(
getHtmlRenderingForTestLearningObject(markdownLearningObject).replace(/\r\n/g, '\n')
);
expect(result).toEqual(getHtmlRenderingForTestLearningObject(markdownLearningObject).replace(/\r\n/g, '\n'));
});
it('renders a multiple choice question correctly', async () => {
const testLearningObject = getLearningObjectRepository().create(testLearningObjectMultipleChoice);
const result = await processingService.render(testLearningObject);
expect(result).toEqual(
getHtmlRenderingForTestLearningObject(testLearningObjectMultipleChoice).replace(/\r\n/g, '\n')
);
expect(result).toEqual(getHtmlRenderingForTestLearningObject(testLearningObjectMultipleChoice).replace(/\r\n/g, '\n'));
});
it('renders an essay question correctly', async () => {
const essayLearningObject = getLearningObjectRepository().create(testLearningObjectEssayQuestion);
const result = await processingService.render(essayLearningObject);
expect(result).toEqual(
getHtmlRenderingForTestLearningObject(essayLearningObject).replace(/\r\n/g, '\n')
);
expect(result).toEqual(getHtmlRenderingForTestLearningObject(essayLearningObject).replace(/\r\n/g, '\n'));
});
});

View file

@ -8,26 +8,20 @@ import databaseLearningPathProvider from '../../../src/services/learning-paths/d
import { expectToBeCorrectLearningPath } from '../../test-utils/expectations.js';
import { Language } from '@dwengo-1/common/util/language';
import { LearningObjectNode, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content';
import {
LearningObjectNode,
LearningPathResponse
} from '@dwengo-1/common/interfaces/learning-content';
import {
testLearningObject01, testLearningObjectEssayQuestion,
testLearningObjectMultipleChoice
} from "../../test_assets/content/learning-objects.testdata";
import {testLearningPathWithConditions} from "../../test_assets/content/learning-paths.testdata";
import {mapToLearningPath} from "../../../src/services/learning-paths/learning-path-service";
import {getTestGroup01, getTestGroup02} from "../../test_assets/assignments/groups.testdata";
testLearningObject01,
testLearningObjectEssayQuestion,
testLearningObjectMultipleChoice,
} from '../../test_assets/content/learning-objects.testdata';
import { testLearningPathWithConditions } from '../../test_assets/content/learning-paths.testdata';
import { mapToLearningPath } from '../../../src/services/learning-paths/learning-path-service';
import { getTestGroup01, getTestGroup02 } from '../../test_assets/assignments/groups.testdata';
import { Group } from '../../../src/entities/assignments/group.entity.js';
import {RequiredEntityData} from "@mikro-orm/core";
import { RequiredEntityData } from '@mikro-orm/core';
function expectBranchingObjectNode(
result: LearningPathResponse
): LearningObjectNode {
const branchingObjectMatches = result.data![0].nodes.filter(
(it) => it.learningobject_hruid === testLearningObjectMultipleChoice.hruid
);
function expectBranchingObjectNode(result: LearningPathResponse): LearningObjectNode {
const branchingObjectMatches = result.data![0].nodes.filter((it) => it.learningobject_hruid === testLearningObjectMultipleChoice.hruid);
expect(branchingObjectMatches.length).toBe(1);
return branchingObjectMatches[0];
}
@ -36,7 +30,7 @@ describe('DatabaseLearningPathProvider', () => {
let testLearningPath: LearningPath;
let branchingLearningObject: RequiredEntityData<LearningObject>;
let extraExerciseLearningObject: RequiredEntityData<LearningObject>;
let finalLearningObject: RequiredEntityData<LearningObject>;
let finalLearningObject: RequiredEntityData<LearningObject>;
let groupA: Group;
let groupB: Group;
@ -55,10 +49,10 @@ describe('DatabaseLearningPathProvider', () => {
learningObjectHruid: branchingLearningObject.hruid,
learningObjectLanguage: branchingLearningObject.language,
learningObjectVersion: branchingLearningObject.version,
content: "[0]",
content: '[0]',
onBehalfOf: groupA,
submissionTime: new Date(),
submitter: groupA.members[0]
submitter: groupA.members[0],
});
await submissionRepo.save(submissionA);
@ -66,21 +60,17 @@ describe('DatabaseLearningPathProvider', () => {
learningObjectHruid: branchingLearningObject.hruid,
learningObjectLanguage: branchingLearningObject.language,
learningObjectVersion: branchingLearningObject.version,
content: "[1]",
content: '[1]',
onBehalfOf: groupB,
submissionTime: new Date(),
submitter: groupB.members[0]
submitter: groupB.members[0],
});
await submissionRepo.save(submissionB);
});
describe('fetchLearningPaths', () => {
it('returns the learning path correctly', async () => {
const result = await databaseLearningPathProvider.fetchLearningPaths(
[testLearningPath.hruid],
testLearningPath.language,
'the source'
);
const result = await databaseLearningPathProvider.fetchLearningPaths([testLearningPath.hruid], testLearningPath.language, 'the source');
expect(result.success).toBe(true);
expect(result.data?.length).toBe(1);
@ -100,24 +90,11 @@ describe('DatabaseLearningPathProvider', () => {
// There should be exactly one branching object
let branchingObject = expectBranchingObjectNode(result);
expect(
branchingObject.transitions.filter(
it => it.next.hruid === finalLearningObject.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 === extraExerciseLearningObject.hruid
).length
).toBe(1); // There should however be a path to the extra exercise object.
expect(branchingObject.transitions.filter((it) => it.next.hruid === finalLearningObject.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 === extraExerciseLearningObject.hruid).length).toBe(1); // There should however be a path to the extra exercise object.
// For student B:
result = await databaseLearningPathProvider.fetchLearningPaths(
[testLearningPath.hruid],
testLearningPath.language,
'the source',
groupB
);
result = await databaseLearningPathProvider.fetchLearningPaths([testLearningPath.hruid], testLearningPath.language, 'the source', groupB);
expect(result.success).toBeTruthy();
expect(result.data?.length).toBe(1);
@ -125,16 +102,8 @@ describe('DatabaseLearningPathProvider', () => {
branchingObject = expectBranchingObjectNode(result);
// However, now the student picks the other option.
expect(
branchingObject.transitions.filter(
(it) => it.next.hruid === finalLearningObject.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 === extraExerciseLearningObject.hruid
).length
).toBe(0); // There should not be a path anymore to the extra exercise object.
expect(branchingObject.transitions.filter((it) => it.next.hruid === finalLearningObject.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 === extraExerciseLearningObject.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(
@ -149,10 +118,7 @@ describe('DatabaseLearningPathProvider', () => {
describe('searchLearningPaths', () => {
it('returns the correct learning path when queried with a substring of its title', async () => {
const result = await databaseLearningPathProvider.searchLearningPaths(
testLearningPath.title.substring(2, 6),
testLearningPath.language
);
const result = await databaseLearningPathProvider.searchLearningPaths(testLearningPath.title.substring(2, 6), testLearningPath.language);
expect(result.length).toBe(1);
expect(result[0].title).toBe(testLearningPath.title);
expect(result[0].description).toBe(testLearningPath.description);

View file

@ -2,10 +2,8 @@ import { beforeAll, describe, expect, it } from 'vitest';
import { setupTestApp } from '../../setup-tests';
import learningPathService from '../../../src/services/learning-paths/learning-path-service';
import { Language } from '@dwengo-1/common/util/language';
import {
testPartiallyDatabaseAndPartiallyDwengoApiLearningPath
} from "../../test_assets/content/learning-paths.testdata";
import {LearningPath as LearningPathDTO} from "@dwengo-1/common/interfaces/learning-content";
import { testPartiallyDatabaseAndPartiallyDwengoApiLearningPath } from '../../test_assets/content/learning-paths.testdata';
import { LearningPath as LearningPathDTO } from '@dwengo-1/common/interfaces/learning-content';
const TEST_DWENGO_LEARNING_PATH_HRUID = 'pn_werking';
const TEST_DWENGO_LEARNING_PATH_TITLE = 'Werken met notebooks';
@ -16,7 +14,7 @@ describe('LearningPathService', () => {
let testLearningPath: LearningPathDTO;
beforeAll(async () => {
await setupTestApp();
testLearningPath = testPartiallyDatabaseAndPartiallyDwengoApiLearningPath
testLearningPath = testPartiallyDatabaseAndPartiallyDwengoApiLearningPath;
});
describe('fetchLearningPaths', () => {
it('should return learning paths both from the database and from the Dwengo API', async () => {