fix: convert all test files from jest to vitest and fix QBittorrentClient import
Some checks failed
CI / Security audit (push) Failing after 19s
Licence Check / Licence compatibility and copyright header verification (push) Successful in 1m1s
Build and Push Docker Image / build (push) Successful in 1m10s
CI / Tests & coverage (push) Failing after 1m21s

- Convert RTorrentClient.test.js to use vi.mock() instead of jest.mock()
- Convert QBittorrentClient.test.js to use vi.mock() instead of jest.mock()
- Convert SABnzbdClient.test.js to use vi.mock() instead of jest.mock()
- Convert TransmissionClient.test.js to use vi.mock() instead of jest.mock()
- Convert downloadClients.test.js to use vi.mock() instead of jest.mock()
- Convert integration/downloadClients.test.js to use vi.mock() instead of jest.mock()
- Fix legacy qbittorrent.test.js to import QBittorrentClient from new location
- Add getRtorrentInstances mock to downloadClients.test.js
- Add RTORRENT_INSTANCES to integration test environment variables
This commit is contained in:
2026-05-19 12:12:44 +01:00
parent e39f15d3d8
commit cc0e34b3d1
7 changed files with 89 additions and 71 deletions

View File

@@ -1,11 +1,12 @@
// Copyright (c) 2026 Gordon Bolton. MIT License.
const TransmissionClient = require('../../../server/clients/TransmissionClient');
const axios = require('axios');
const { vi } = require('vitest');
// Mock axios
jest.mock('axios');
jest.mock('../../../server/utils/logger', () => ({
logToFile: jest.fn()
vi.mock('axios');
vi.mock('../../../server/utils/logger', () => ({
logToFile: vi.fn()
}));
describe('TransmissionClient', () => {
@@ -24,7 +25,7 @@ describe('TransmissionClient', () => {
client = new TransmissionClient(mockConfig);
// Clear all mocks
jest.clearAllMocks();
vi.clearAllMocks();
});
describe('Constructor', () => {
@@ -44,7 +45,7 @@ describe('TransmissionClient', () => {
data: { result: 'success', arguments: {} }
};
client.makeRequest = jest.fn().mockResolvedValue(mockResponse);
client.makeRequest = vi.fn().mockResolvedValue(mockResponse);
const result = await client.testConnection();
@@ -53,7 +54,7 @@ describe('TransmissionClient', () => {
});
it('should handle connection test failure', async () => {
client.makeRequest = jest.fn().mockRejectedValue(new Error('Connection failed'));
client.makeRequest = vi.fn().mockRejectedValue(new Error('Connection failed'));
const result = await client.testConnection();
@@ -308,7 +309,7 @@ describe('TransmissionClient', () => {
}
};
client.makeRequest = jest.fn().mockResolvedValue(mockResponse);
client.makeRequest = vi.fn().mockResolvedValue(mockResponse);
const downloads = await client.getActiveDownloads();
@@ -330,7 +331,7 @@ describe('TransmissionClient', () => {
});
it('should handle API errors gracefully', async () => {
client.makeRequest = jest.fn().mockRejectedValue(new Error('API Error'));
client.makeRequest = vi.fn().mockRejectedValue(new Error('API Error'));
const downloads = await client.getActiveDownloads();
@@ -345,7 +346,7 @@ describe('TransmissionClient', () => {
}
};
client.makeRequest = jest.fn().mockResolvedValue(mockResponse);
client.makeRequest = vi.fn().mockResolvedValue(mockResponse);
const downloads = await client.getActiveDownloads();
@@ -377,7 +378,7 @@ describe('TransmissionClient', () => {
}
};
client.makeRequest = jest.fn()
client.makeRequest = vi.fn()
.mockResolvedValueOnce(mockSessionResponse)
.mockResolvedValueOnce(mockStatsResponse);
@@ -392,7 +393,7 @@ describe('TransmissionClient', () => {
});
it('should handle status request errors', async () => {
client.makeRequest = jest.fn().mockRejectedValue(new Error('Status error'));
client.makeRequest = vi.fn().mockRejectedValue(new Error('Status error'));
const status = await client.getClientStatus();