Files
ReadMeABook/tests/utils/job-logger.test.ts
T
kikootwo 94dbaf073b Add backend unit test framework and modularize settings UI
Introduced a Vitest-based backend unit testing framework with supporting scripts, helpers, and GitHub Actions integration. Refactored the admin settings page to a modular architecture, splitting monolithic logic into feature-specific tabs and hooks for improved maintainability and testability. Updated documentation to reflect the new testing setup and settings architecture, and added new dependencies for testing utilities.
2026-01-28 11:41:59 -05:00

48 lines
1.4 KiB
TypeScript

/**
* Component: Job Logger Utility Tests
* Documentation: documentation/backend/services/jobs.md
*/
import { describe, expect, it, vi } from 'vitest';
const infoMock = vi.fn();
const warnMock = vi.fn();
const errorMock = vi.fn();
const forJobMock = vi.fn(() => ({
info: infoMock,
warn: warnMock,
error: errorMock,
}));
vi.mock('@/lib/utils/logger', () => ({
RMABLogger: {
forJob: forJobMock,
},
}));
describe('JobLogger', () => {
it('logs info, warn, and error messages via RMABLogger', async () => {
const { JobLogger } = await import('@/lib/utils/job-logger');
const logger = new JobLogger('job-1', 'Context');
await logger.info('info message', { foo: 'bar' });
await logger.warn('warn message');
await logger.error('error message', { error: 'boom' });
expect(forJobMock).toHaveBeenCalledWith('job-1', 'Context');
expect(infoMock).toHaveBeenCalledWith('info message', { foo: 'bar' });
expect(warnMock).toHaveBeenCalledWith('warn message', undefined);
expect(errorMock).toHaveBeenCalledWith('error message', { error: 'boom' });
});
it('creates a job logger via helper', async () => {
const { createJobLogger } = await import('@/lib/utils/job-logger');
const logger = createJobLogger('job-2', 'Context2');
await logger.info('message');
expect(forJobMock).toHaveBeenCalledWith('job-2', 'Context2');
expect(infoMock).toHaveBeenCalledWith('message', undefined);
});
});