diff --git a/tests/integration/downloadClients.test.js b/tests/integration/downloadClients.test.js index a76b06d..2167007 100644 --- a/tests/integration/downloadClients.test.js +++ b/tests/integration/downloadClients.test.js @@ -1,11 +1,11 @@ // Copyright (c) 2026 Gordon Bolton. MIT License. -const { +import { initializeClients, getAllDownloads, getDownloadsByClientType, testAllConnections -} = require('../../server/utils/downloadClients'); -const { vi } = require('vitest'); +} from '../../server/utils/downloadClients.js'; +import { vi } from 'vitest'; // Mock environment variables for testing process.env.SABNZBD_INSTANCES = JSON.stringify([ diff --git a/tests/unit/clients/QBittorrentClient.test.js b/tests/unit/clients/QBittorrentClient.test.js index 117853f..6343f34 100644 --- a/tests/unit/clients/QBittorrentClient.test.js +++ b/tests/unit/clients/QBittorrentClient.test.js @@ -1,7 +1,7 @@ // Copyright (c) 2026 Gordon Bolton. MIT License. -const QBittorrentClient = require('../../../server/clients/QBittorrentClient'); -const axios = require('axios'); -const { vi } = require('vitest'); +import QBittorrentClient from '../../../server/clients/QBittorrentClient.js'; +import axios from 'axios'; +import { vi } from 'vitest'; // Mock axios vi.mock('axios'); diff --git a/tests/unit/clients/RTorrentClient.test.js b/tests/unit/clients/RTorrentClient.test.js index 101dae2..a6402b3 100644 --- a/tests/unit/clients/RTorrentClient.test.js +++ b/tests/unit/clients/RTorrentClient.test.js @@ -1,7 +1,7 @@ // Copyright (c) 2026 Gordon Bolton. MIT License. -const RTorrentClient = require('../../../server/clients/RTorrentClient'); -const xmlrpc = require('xmlrpc'); -const { vi } = require('vitest'); +import RTorrentClient from '../../../server/clients/RTorrentClient.js'; +import xmlrpc from 'xmlrpc'; +import { vi } from 'vitest'; vi.mock('xmlrpc', () => ({ createClient: vi.fn() diff --git a/tests/unit/clients/SABnzbdClient.test.js b/tests/unit/clients/SABnzbdClient.test.js index 11a9d3b..abea51a 100644 --- a/tests/unit/clients/SABnzbdClient.test.js +++ b/tests/unit/clients/SABnzbdClient.test.js @@ -1,7 +1,7 @@ // Copyright (c) 2026 Gordon Bolton. MIT License. -const SABnzbdClient = require('../../../server/clients/SABnzbdClient'); -const axios = require('axios'); -const { vi } = require('vitest'); +import SABnzbdClient from '../../../server/clients/SABnzbdClient.js'; +import axios from 'axios'; +import { vi } from 'vitest'; // Mock axios vi.mock('axios'); diff --git a/tests/unit/clients/TransmissionClient.test.js b/tests/unit/clients/TransmissionClient.test.js index b4496d7..ef1ae49 100644 --- a/tests/unit/clients/TransmissionClient.test.js +++ b/tests/unit/clients/TransmissionClient.test.js @@ -1,7 +1,7 @@ // Copyright (c) 2026 Gordon Bolton. MIT License. -const TransmissionClient = require('../../../server/clients/TransmissionClient'); -const axios = require('axios'); -const { vi } = require('vitest'); +import TransmissionClient from '../../../server/clients/TransmissionClient.js'; +import axios from 'axios'; +import { vi } from 'vitest'; // Mock axios vi.mock('axios'); diff --git a/tests/unit/downloadClients.test.js b/tests/unit/downloadClients.test.js index 53e97c1..9de16c0 100644 --- a/tests/unit/downloadClients.test.js +++ b/tests/unit/downloadClients.test.js @@ -1,5 +1,5 @@ // Copyright (c) 2026 Gordon Bolton. MIT License. -const { +import { DownloadClientRegistry, registry, initializeClients, @@ -10,8 +10,8 @@ const { getDownloadsByClientType, testAllConnections, getAllClientStatuses -} = require('../../server/utils/downloadClients'); -const { vi } = require('vitest'); +} from '../../server/utils/downloadClients.js'; +import { vi } from 'vitest'; // Mock config and clients vi.mock('../../server/utils/config', () => ({ diff --git a/tests/unit/qbittorrent.test.js b/tests/unit/qbittorrent.test.js index 86647f5..1e06688 100644 --- a/tests/unit/qbittorrent.test.js +++ b/tests/unit/qbittorrent.test.js @@ -156,7 +156,7 @@ describe('QBittorrentClient sync API', () => { } }); - const torrents = await client.getTorrents(); + const torrents = await client.getActiveDownloads(); expect(torrents).toHaveLength(1); expect(torrents[0].name).toBe('Test1'); expect(torrents[0].instanceId).toBe('test-qbt'); @@ -188,7 +188,7 @@ describe('QBittorrentClient sync API', () => { } }); - const torrents = await client.getTorrents(); + const torrents = await client.getActiveDownloads(); expect(torrents).toHaveLength(1); expect(torrents[0].dlspeed).toBe(200); expect(torrents[0].name).toBe('Test1'); @@ -219,7 +219,7 @@ describe('QBittorrentClient sync API', () => { } }); - const torrents = await client.getTorrents(); + const torrents = await client.getActiveDownloads(); expect(torrents).toHaveLength(1); expect(torrents[0].name).toBe('Test2'); expect(torrents[0].hash).toBe('hash02'); @@ -238,7 +238,7 @@ describe('QBittorrentClient sync API', () => { hash01: { name: 'Test1', state: 'downloading', size: 1000, progress: 0.5, dlspeed: 100, eta: 60, num_seeds: 5, num_leechs: 2, availability: 1.0 } } }); - await client.getTorrents(); + await client.getActiveDownloads(); mockSync(1, { rid: 2, @@ -246,7 +246,7 @@ describe('QBittorrentClient sync API', () => { torrents_removed: ['hash01'] }); - const torrents = await client.getTorrents(); + const torrents = await client.getActiveDownloads(); expect(torrents).toHaveLength(0); }); @@ -267,7 +267,7 @@ describe('QBittorrentClient sync API', () => { { name: 'Fallback', hash: 'fb01', state: 'downloading', size: 1073741824, progress: 0.5, dlspeed: 1048576, eta: 512, num_seeds: 10, num_leechs: 3, availability: 1.0 } ]); - const torrents = await client.getTorrents(); + const torrents = await client.getActiveDownloads(); expect(torrents).toHaveLength(1); expect(torrents[0].name).toBe('Fallback'); expect(client.fallbackThisCycle).toBe(true); @@ -292,7 +292,7 @@ describe('QBittorrentClient sync API', () => { .get('/api/v2/sync/maindata?rid=0') .reply(200, { rid: 1, full_update: true }); - const torrents = await client.getTorrents(); + const torrents = await client.getActiveDownloads(); expect(torrents).toHaveLength(1); expect(torrents[0].name).toBe('DirectLegacy'); expect(syncScope.isDone()).toBe(false); @@ -324,7 +324,7 @@ describe('QBittorrentClient sync API', () => { } }); - const torrents = await client.getTorrents(); + const torrents = await client.getActiveDownloads(); expect(torrents).toHaveLength(1); expect(torrents[0].name).toBe('AfterReauth'); }); @@ -342,7 +342,7 @@ describe('QBittorrentClient sync API', () => { } }); - const torrents = await client.getTorrents(); + const torrents = await client.getActiveDownloads(); expect(torrents[0].completed).toBe(500); }); @@ -363,7 +363,7 @@ describe('QBittorrentClient sync API', () => { // Simulate the reset that getAllTorrents performs client.fallbackThisCycle = false; - const torrents = await client.getTorrents(); + const torrents = await client.getActiveDownloads(); expect(torrents[0].name).toBe('ResetWorks'); expect(client.fallbackThisCycle).toBe(false); });