test: add comprehensive test suite for Ombi integration
- Add tests for Ombi configuration parsing (OMBI_INSTANCES JSON array, legacy fallback) - Add tests for OmbiClient API methods (movie/TV requests, search by TMDB/IMDB/TVDB) - Add tests for OmbiRetriever caching, queue, and search functionality - Add tests for arrRetrieverRegistry initialization and retrieval methods - Add tests for DownloadMatcher.addOmbiMatching integration - Add tests for DownloadAssembler Ombi link generation utilities - Export addOmbiMatching from DownloadMatcher module
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* because misconfigured instances silently return no data rather than crashing.
|
||||
*/
|
||||
|
||||
import { parseInstances, getSonarrInstances, getRadarrInstances } from '../../server/utils/config.js';
|
||||
import { parseInstances, getSonarrInstances, getRadarrInstances, getOmbiInstances } from '../../server/utils/config.js';
|
||||
|
||||
describe('parseInstances', () => {
|
||||
describe('JSON array format', () => {
|
||||
@@ -106,4 +106,87 @@ describe('parseInstances', () => {
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Ombi configuration', () => {
|
||||
it('getOmbiInstances parses OMBI_INSTANCES JSON array', () => {
|
||||
process.env.OMBI_INSTANCES = JSON.stringify([{ name: 'ombi-main', url: 'https://ombi.local', apiKey: 'ombi-key-123' }]);
|
||||
const result = getOmbiInstances();
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0].name).toBe('ombi-main');
|
||||
expect(result[0].url).toBe('https://ombi.local');
|
||||
expect(result[0].apiKey).toBe('ombi-key-123');
|
||||
expect(result[0].id).toBe('ombi-main');
|
||||
delete process.env.OMBI_INSTANCES;
|
||||
});
|
||||
|
||||
it('getOmbiInstances parses multiple Ombi instances', () => {
|
||||
process.env.OMBI_INSTANCES = JSON.stringify([
|
||||
{ name: 'ombi-primary', url: 'https://ombi1.local', apiKey: 'key1' },
|
||||
{ name: 'ombi-backup', url: 'https://ombi2.local', apiKey: 'key2' }
|
||||
]);
|
||||
const result = getOmbiInstances();
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0].name).toBe('ombi-primary');
|
||||
expect(result[1].name).toBe('ombi-backup');
|
||||
delete process.env.OMBI_INSTANCES;
|
||||
});
|
||||
|
||||
it('getOmbiInstances falls back to legacy OMBI_URL and OMBI_API_KEY', () => {
|
||||
delete process.env.OMBI_INSTANCES;
|
||||
process.env.OMBI_URL = 'https://legacy-ombi.local';
|
||||
process.env.OMBI_API_KEY = 'legacy-ombi-key';
|
||||
const result = getOmbiInstances();
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0].id).toBe('default');
|
||||
expect(result[0].name).toBe('Default');
|
||||
expect(result[0].url).toBe('https://legacy-ombi.local');
|
||||
expect(result[0].apiKey).toBe('legacy-ombi-key');
|
||||
delete process.env.OMBI_URL;
|
||||
delete process.env.OMBI_API_KEY;
|
||||
});
|
||||
|
||||
it('getOmbiInstances returns empty array when not configured', () => {
|
||||
delete process.env.OMBI_INSTANCES;
|
||||
delete process.env.OMBI_URL;
|
||||
delete process.env.OMBI_API_KEY;
|
||||
const result = getOmbiInstances();
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it('getOmbiInstances handles multi-line JSON', () => {
|
||||
const json = `[
|
||||
{
|
||||
"name": "ombi-test",
|
||||
"url": "https://ombi.test",
|
||||
"apiKey": "test-key"
|
||||
}
|
||||
]`;
|
||||
process.env.OMBI_INSTANCES = json;
|
||||
const result = getOmbiInstances();
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0].name).toBe('ombi-test');
|
||||
delete process.env.OMBI_INSTANCES;
|
||||
});
|
||||
|
||||
it('getOmbiInstances handles invalid JSON by falling back to legacy', () => {
|
||||
process.env.OMBI_INSTANCES = 'not-valid-json';
|
||||
process.env.OMBI_URL = 'https://fallback-ombi.local';
|
||||
process.env.OMBI_API_KEY = 'fallback-key';
|
||||
const result = getOmbiInstances();
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0].url).toBe('https://fallback-ombi.local');
|
||||
delete process.env.OMBI_INSTANCES;
|
||||
delete process.env.OMBI_URL;
|
||||
delete process.env.OMBI_API_KEY;
|
||||
});
|
||||
|
||||
it('parseInstances validates Ombi instance URLs', () => {
|
||||
process.env.OMBI_INSTANCES = JSON.stringify([{ name: 'bad-url', url: 'not-a-valid-url', apiKey: 'key' }]);
|
||||
const result = getOmbiInstances();
|
||||
// Should still parse but with validation warning
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0].url).toBe('not-a-valid-url');
|
||||
delete process.env.OMBI_INSTANCES;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user