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 QBittorrentClient = require('../../../server/clients/QBittorrentClient');
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('QBittorrentClient', () => {
@@ -22,9 +23,9 @@ describe('QBittorrentClient', () => {
};
client = new QBittorrentClient(mockConfig);
// Clear all mocks
jest.clearAllMocks();
vi.clearAllMocks();
});
describe('Constructor', () => {
@@ -89,11 +90,11 @@ describe('QBittorrentClient', () => {
describe('Connection Test', () => {
it('should test connection successfully', async () => {
// Mock login success
client.login = jest.fn().mockResolvedValue(true);
client.login = vi.fn().mockResolvedValue(true);
// Mock version request
const mockResponse = { data: 'v4.3.5' };
client.makeRequest = jest.fn().mockResolvedValue(mockResponse);
client.makeRequest = vi.fn().mockResolvedValue(mockResponse);
const result = await client.testConnection();
@@ -102,7 +103,7 @@ describe('QBittorrentClient', () => {
});
it('should handle connection test failure', async () => {
client.login = jest.fn().mockRejectedValue(new Error('Auth failed'));
client.login = vi.fn().mockRejectedValue(new Error('Auth failed'));
const result = await client.testConnection();
@@ -200,15 +201,15 @@ describe('QBittorrentClient', () => {
const authError = {
response: { status: 403 }
};
// Second login attempt succeeds
client.login = jest.fn()
client.login = vi.fn()
.mockResolvedValueOnce(false)
.mockResolvedValueOnce(true);
// Retry request succeeds
const successResponse = { data: 'success' };
axios.get = jest.fn()
axios.get = vi.fn()
.mockRejectedValueOnce(authError)
.mockResolvedValueOnce(successResponse);