test: extra test bij learningObjects
This commit is contained in:
parent
71cf652f28
commit
db582ee46a
1 changed files with 36 additions and 12 deletions
|
@ -1,9 +1,12 @@
|
||||||
import {describe, it, expect, vi} from 'vitest';
|
import {describe, it, expect, vi} from 'vitest';
|
||||||
import {
|
import {
|
||||||
LearningObjectMetadata,
|
LearningObjectMetadata, LearningPath,
|
||||||
} from "../../src/interfaces/learningPath";
|
} from "../../src/interfaces/learningPath";
|
||||||
import {fetchWithLogging} from "../../src/util/apiHelper";
|
import {fetchWithLogging} from "../../src/util/apiHelper";
|
||||||
import {getLearningObjectById, getLearningObjectsFromPath} from "../../src/services/learningObjects";
|
import {
|
||||||
|
getLearningObjectById,
|
||||||
|
getLearningObjectsFromPath
|
||||||
|
} from "../../src/services/learningObjects";
|
||||||
import {fetchLearningPaths} from "../../src/services/learningPaths";
|
import {fetchLearningPaths} from "../../src/services/learningPaths";
|
||||||
|
|
||||||
// Mock API functions
|
// Mock API functions
|
||||||
|
@ -35,9 +38,7 @@ describe('getLearningObjectById', () => {
|
||||||
description: 'A test object',
|
description: 'A test object',
|
||||||
target_ages: [10, 12],
|
target_ages: [10, 12],
|
||||||
content_type: 'markdown',
|
content_type: 'markdown',
|
||||||
content_location: '',
|
content_location: ''
|
||||||
skos_concepts: [],
|
|
||||||
return_value: undefined,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
it('✅ Should return a filtered learning object when API provides data', async () => {
|
it('✅ Should return a filtered learning object when API provides data', async () => {
|
||||||
|
@ -62,9 +63,7 @@ describe('getLearningObjectById', () => {
|
||||||
description: 'A test object',
|
description: 'A test object',
|
||||||
targetAges: [10, 12],
|
targetAges: [10, 12],
|
||||||
contentType: 'markdown',
|
contentType: 'markdown',
|
||||||
contentLocation: '',
|
contentLocation: ''
|
||||||
skosConcepts: [],
|
|
||||||
returnValue: undefined,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -80,19 +79,44 @@ describe('getLearningObjectsFromPath', () => {
|
||||||
const hruid = 'test-path';
|
const hruid = 'test-path';
|
||||||
const language = 'en';
|
const language = 'en';
|
||||||
|
|
||||||
it('⚠️ Should return an empty array if API returns an empty path response', async () => {
|
it('✅ Should not give error or warning', async () => {
|
||||||
|
const mockPathResponse: LearningPath[] = [{
|
||||||
|
_id: 'path-1',
|
||||||
|
hruid,
|
||||||
|
language,
|
||||||
|
title: 'Test Path',
|
||||||
|
description: '',
|
||||||
|
num_nodes: 1,
|
||||||
|
num_nodes_left: 0,
|
||||||
|
nodes: [],
|
||||||
|
keywords: '',
|
||||||
|
target_ages: [],
|
||||||
|
min_age: 10,
|
||||||
|
max_age: 12,
|
||||||
|
__order: 1,
|
||||||
|
}];
|
||||||
|
|
||||||
|
vi.mocked(fetchLearningPaths).mockResolvedValueOnce({
|
||||||
|
success: true,
|
||||||
|
source: 'Test Source',
|
||||||
|
data: mockPathResponse
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await getLearningObjectsFromPath(hruid, language);
|
||||||
|
expect(result).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('⚠️ Should give a warning', async () => {
|
||||||
vi.mocked(fetchLearningPaths).mockResolvedValueOnce({success: false, source: 'Test Source', data: []});
|
vi.mocked(fetchLearningPaths).mockResolvedValueOnce({success: false, source: 'Test Source', data: []});
|
||||||
|
|
||||||
const result = await getLearningObjectsFromPath(hruid, language);
|
const result = await getLearningObjectsFromPath(hruid, language);
|
||||||
|
|
||||||
expect(result).toEqual([]);
|
expect(result).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('❌ Should return an empty array and log an error if fetchLearningPaths fails', async () => {
|
it('❌ Should give an error', async () => {
|
||||||
vi.mocked(fetchLearningPaths).mockRejectedValueOnce(new Error('API Error'));
|
vi.mocked(fetchLearningPaths).mockRejectedValueOnce(new Error('API Error'));
|
||||||
|
|
||||||
const result = await getLearningObjectsFromPath(hruid, language);
|
const result = await getLearningObjectsFromPath(hruid, language);
|
||||||
|
|
||||||
expect(result).toEqual([]);
|
expect(result).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue