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);
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
// Copyright (c) 2026 Gordon Bolton. MIT License.
|
||||
const RTorrentClient = require('../../../server/clients/RTorrentClient');
|
||||
const xmlrpc = require('xmlrpc');
|
||||
const { vi } = require('vitest');
|
||||
|
||||
jest.mock('xmlrpc', () => ({
|
||||
createClient: jest.fn()
|
||||
vi.mock('xmlrpc', () => ({
|
||||
createClient: vi.fn()
|
||||
}));
|
||||
|
||||
jest.mock('../../../server/utils/logger', () => ({
|
||||
logToFile: jest.fn()
|
||||
vi.mock('../../../server/utils/logger', () => ({
|
||||
logToFile: vi.fn()
|
||||
}));
|
||||
|
||||
describe('RTorrentClient', () => {
|
||||
@@ -16,7 +17,7 @@ describe('RTorrentClient', () => {
|
||||
let mockMethodCall;
|
||||
|
||||
beforeEach(() => {
|
||||
mockMethodCall = jest.fn();
|
||||
mockMethodCall = vi.fn();
|
||||
xmlrpc.createClient.mockReturnValue({
|
||||
methodCall: mockMethodCall
|
||||
});
|
||||
@@ -30,7 +31,7 @@ describe('RTorrentClient', () => {
|
||||
};
|
||||
|
||||
client = new RTorrentClient(mockConfig);
|
||||
jest.clearAllMocks();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('Constructor', () => {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// Copyright (c) 2026 Gordon Bolton. MIT License.
|
||||
const SABnzbdClient = require('../../../server/clients/SABnzbdClient');
|
||||
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('SABnzbdClient', () => {
|
||||
@@ -23,7 +24,7 @@ describe('SABnzbdClient', () => {
|
||||
client = new SABnzbdClient(mockConfig);
|
||||
|
||||
// Clear all mocks
|
||||
jest.clearAllMocks();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('Constructor', () => {
|
||||
@@ -42,7 +43,7 @@ describe('SABnzbdClient', () => {
|
||||
data: { version: '3.6.1' }
|
||||
};
|
||||
|
||||
client.makeRequest = jest.fn().mockResolvedValue(mockResponse);
|
||||
client.makeRequest = vi.fn().mockResolvedValue(mockResponse);
|
||||
|
||||
const result = await client.testConnection();
|
||||
|
||||
@@ -51,7 +52,7 @@ describe('SABnzbdClient', () => {
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
@@ -244,7 +245,7 @@ describe('SABnzbdClient', () => {
|
||||
}
|
||||
};
|
||||
|
||||
client.makeRequest = jest.fn()
|
||||
client.makeRequest = vi.fn()
|
||||
.mockResolvedValueOnce(mockQueueResponse)
|
||||
.mockResolvedValueOnce(mockHistoryResponse);
|
||||
|
||||
@@ -258,7 +259,7 @@ describe('SABnzbdClient', () => {
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
@@ -280,7 +281,7 @@ describe('SABnzbdClient', () => {
|
||||
}
|
||||
};
|
||||
|
||||
client.makeRequest = jest.fn().mockResolvedValue(mockResponse);
|
||||
client.makeRequest = vi.fn().mockResolvedValue(mockResponse);
|
||||
|
||||
const status = await client.getClientStatus();
|
||||
|
||||
@@ -294,7 +295,7 @@ describe('SABnzbdClient', () => {
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user