mirror of
https://github.com/kikootwo/ReadMeABook.git
synced 2026-06-03 21:00:09 +00:00
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.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user