Files
ReadMeABook/tests/utils/path-mapper.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

51 lines
1.4 KiB
TypeScript

/**
* Component: Path Mapper Tests
* Documentation: documentation/phase3/qbittorrent.md
*/
import { describe, expect, it } from 'vitest';
import { PathMapper } from '@/lib/utils/path-mapper';
describe('PathMapper', () => {
it('returns original path when mapping is disabled', () => {
const result = PathMapper.transform('/remote/path/book', {
enabled: false,
remotePath: '/remote/path',
localPath: '/local/path',
});
expect(result).toBe('/remote/path/book');
});
it('transforms remote path to local path when enabled', () => {
const result = PathMapper.transform('/remote/mnt/d/done/Book', {
enabled: true,
remotePath: '/remote/mnt/d/done',
localPath: '/downloads',
});
expect(result.replace(/\\/g, '/')).toBe('/downloads/Book');
});
it('returns original path when remote prefix does not match', () => {
const result = PathMapper.transform('/other/path/book', {
enabled: true,
remotePath: '/remote/path',
localPath: '/local/path',
});
expect(result).toBe('/other/path/book');
});
it('validates mapping configuration when enabled', () => {
expect(() =>
PathMapper.validate({ enabled: true, remotePath: '', localPath: '/local' })
).toThrow('Remote path cannot be empty');
expect(() =>
PathMapper.validate({ enabled: true, remotePath: '/remote', localPath: '' })
).toThrow('Local path cannot be empty');
});
});