test(backend): Testen voor DatabaseLearningPathProvider.fetchLearningPaths afgewerkt
Hierbij optredende problemen opgelost.
This commit is contained in:
parent
1f9e9ed70a
commit
7018a8822d
10 changed files with 139 additions and 32 deletions
|
@ -6,6 +6,10 @@ import {getLearningObjectRepository, getLearningPathRepository} from "../../../s
|
|||
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 }> {
|
||||
const learningObjectRepo = getLearningObjectRepository();
|
||||
|
@ -18,15 +22,17 @@ async function initExampleData(): Promise<{ learningObject: LearningObject, lear
|
|||
}
|
||||
|
||||
describe("DatabaseLearningPathProvider", () => {
|
||||
let learningObjectRepo: LearningObjectRepository;
|
||||
let example: {learningObject: LearningObject, learningPath: LearningPath};
|
||||
|
||||
beforeAll(async () => {
|
||||
await setupTestApp();
|
||||
example = await initExampleData();
|
||||
learningObjectRepo = getLearningObjectRepository();
|
||||
});
|
||||
|
||||
describe("fetchLearningPaths", () => {
|
||||
it("returns the learning path correctly", () => {
|
||||
it("returns the learning path correctly", async () => {
|
||||
const result = await databaseLearningPathProvider.fetchLearningPaths(
|
||||
[example.learningPath.hruid],
|
||||
example.learningPath.language,
|
||||
|
@ -34,7 +40,26 @@ describe("DatabaseLearningPathProvider", () => {
|
|||
);
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.data?.length).toBe(1);
|
||||
expect(result.data)
|
||||
})
|
||||
|
||||
const learningObjectsOnPath = (await Promise.all(
|
||||
example.learningPath.nodes.map(node =>
|
||||
learningObjectService.getLearningObjectById({
|
||||
hruid: node.learningObjectHruid,
|
||||
version: node.version,
|
||||
language: node.language
|
||||
}))
|
||||
)).filter(it => it !== null);
|
||||
|
||||
expectToBeCorrectLearningPath(result.data![0], example.learningPath, learningObjectsOnPath)
|
||||
});
|
||||
it("returns a non-successful response if a non-existing learning path is queried", async () => {
|
||||
const result = await databaseLearningPathProvider.fetchLearningPaths(
|
||||
[example.learningPath.hruid],
|
||||
Language.Abkhazian, // wrong language
|
||||
"the source"
|
||||
);
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue