test: alle functies in learningObjects.ts zijn getest en de testen slagen

This commit is contained in:
Joyelle Ndagijimana 2025-03-12 18:30:24 +01:00
parent fca8e7ff7a
commit 71cf652f28
2 changed files with 102 additions and 6 deletions

View file

@ -3,21 +3,19 @@ import { fetchLearningPaths, searchLearningPaths } from '../../src/services/lear
import { fetchWithLogging } from '../../src/util/apiHelper';
import { LearningPathResponse } from '../../src/interfaces/learningPath';
// Function to mock the fetchWithLogging module using vi
// Mock the fetchWithLogging module using vi
vi.mock('../../src/util/apiHelper', () => ({
fetchWithLogging: vi.fn(),
}));
describe('fetchLearningPaths', () => {
// Mock data and response
const mockHruids = ['pn_werking', 'art1'];
const language = 'en';
const source = 'Test Source';
const mockResponse = [{ title: 'Test Path', hruids: mockHruids }];
it('✅ Should return a successful response when HRUIDs are provided', async () => {
// Mock response van fetchWithLogging
const mockResponse = [{ title: 'Test Path', hruids: mockHruids }];
// Mock the function to return mockResponse
vi.mocked(fetchWithLogging).mockResolvedValue(mockResponse);
@ -29,10 +27,10 @@ describe('fetchLearningPaths', () => {
});
it('⚠️ Should return an error when no HRUIDs are provided', async () => {
const result: LearningPathResponse = await fetchLearningPaths([], language, source);
vi.mocked(fetchWithLogging).mockResolvedValue(mockResponse);
const result: LearningPathResponse = await fetchLearningPaths([], language, source);
expect(result.success).toBe(false);
expect(result.data).toBeNull();
expect(result.message).toBe(`No HRUIDs provided for ${source}.`);