Fix all Vitest test failures after migration
Build and Push Docker Image / build (push) Successful in 24s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 56s
CI / Security audit (push) Successful in 1m12s
CI / Tests & coverage (push) Successful in 1m25s
Docs Check / Markdown lint (pull_request) Successful in 41s
Licence Check / Licence compatibility and copyright header verification (pull_request) Successful in 1m14s
CI / Security audit (pull_request) Successful in 1m33s
Docs Check / Mermaid diagram parse check (pull_request) Successful in 1m56s
CI / Tests & coverage (pull_request) Successful in 2m3s

- Replace vi.mock('axios') with nock for HTTP request mocking (ES/CJS interop issue)
- Fix RTorrentClient by mocking client.client.methodCall directly instead of xmlrpc module
- Fix downloadClients.test.js by manually adding mock clients to registry
- Fix qbittorrent.test.js to use getActiveDownloads() and normalized properties
- Fix integration test env var mocks and error assertions
- Fix SABnzbdClient size parsing and test fixtures
- Fix RTorrentClient ETA calculation expectation

All 261 tests now passing.
This commit is contained in:
2026-05-19 13:53:09 +01:00
parent 5342170ced
commit 9343486705
7 changed files with 206 additions and 238 deletions
+16 -19
View File
@@ -1,10 +1,7 @@
// Copyright (c) 2026 Gordon Bolton. MIT License.
import SABnzbdClient from '../../../server/clients/SABnzbdClient.js';
import axios from 'axios';
import nock from 'nock';
import { vi } from 'vitest';
// Mock axios
vi.mock('axios');
vi.mock('../../../server/utils/logger', () => ({
logToFile: vi.fn()
}));
@@ -48,7 +45,7 @@ describe('SABnzbdClient', () => {
const result = await client.testConnection();
expect(result).toBe(true);
expect(client.makeRequest).toHaveBeenCalledWith({ mode: 'version' });
expect(client.makeRequest).toHaveBeenCalledWith('', { mode: 'version' });
});
it('should handle connection test failure', async () => {
@@ -62,27 +59,26 @@ describe('SABnzbdClient', () => {
describe('API Requests', () => {
it('should make API request with correct parameters', async () => {
const mockResponse = { data: { result: 'success' } };
axios.get.mockResolvedValue(mockResponse);
const result = await client.makeRequest({ mode: 'queue', limit: 10 });
expect(axios.get).toHaveBeenCalledWith('http://localhost:8080/api', {
params: {
nock('http://localhost:8080')
.get('/api')
.query({
output: 'json',
apikey: 'test-api-key',
mode: 'queue',
limit: 10
}
});
})
.reply(200, { result: 'success' });
expect(result).toEqual(mockResponse);
const result = await client.makeRequest({ mode: 'queue', limit: 10 });
expect(result.data).toEqual({ result: 'success' });
});
it('should handle API request errors', async () => {
const error = new Error('API Error');
axios.get.mockRejectedValue(error);
nock('http://localhost:8080')
.get('/api')
.query({ output: 'json', apikey: 'test-api-key', mode: 'queue' })
.replyWithError(new Error('API Error'));
await expect(client.makeRequest({ mode: 'queue' })).rejects.toThrow('API Error');
});
@@ -133,6 +129,7 @@ describe('SABnzbdClient', () => {
filename: 'Test Series S01E01.mkv',
status: 'Completed',
mb: 500,
mbleft: 0,
cat: 'tv',
added: 1640995200
};
@@ -201,7 +198,7 @@ describe('SABnzbdClient', () => {
status: 'Downloading',
progress: 50,
size: '1.5 GB',
sizeleft: '750 MB'
sizeleft: '0.75 GB'
};
const normalized = client.normalizeDownload(slot, 'queue');