style: fix linting issues met Prettier

This commit is contained in:
Lint Action 2025-03-11 03:09:12 +00:00
parent aa1a85e64e
commit 2a2881ec30
84 changed files with 846 additions and 1013 deletions

View file

@ -1,17 +1,17 @@
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();
const learningObject = learningObjectExample.createLearningObject();
@ -21,9 +21,9 @@ async function initExampleData(): Promise<{ learningObject: LearningObject, lear
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"
'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,14 +1,14 @@
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();
const learningObject = learningObjectExample.createLearningObject();
@ -18,88 +18,63 @@ async function initExampleData(): Promise<{ learningObject: LearningObject, lear
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.
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);
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);
});
});