fix: convert all test files from jest to vitest and fix QBittorrentClient import
Some checks failed
Some checks failed
- 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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user