Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public async Task<List<IndexerSearchResult>> SearchIndexersAsync(

if (!indexers.Any())
{
_logger.LogWarning("No indexers configured, returning mock results for query: {Query}", query);
return GenerateMockIndexerResults(query);
_logger.LogWarning("No indexers configured or enabled; search returned no results for query: {Query}", query);
return results;
}

var searchTasks = indexers.Select(async indexer =>
Expand Down Expand Up @@ -254,61 +254,4 @@ private static string GetFallbackIndexerName(Indexer indexer)
return "Indexer";
}
}

private List<IndexerSearchResult> GenerateMockIndexerResults(string query)
{
return GenerateMockIndexerResults(query, "Mock Indexer", "Torrent");
}

private List<IndexerSearchResult> GenerateMockIndexerResults(string query, string indexerName, string indexerType)
{
var random = new Random();
var results = new List<IndexerSearchResult>();
var isUsenet = indexerType.Equals("Usenet", StringComparison.OrdinalIgnoreCase);

_logger.LogInformation("Generating {Count} mock {Type} results for indexer {IndexerName}", 5, indexerType, indexerName);

for (int i = 0; i < 5; i++)
{
var result = new IndexerSearchResult
{
Id = Guid.NewGuid().ToString(),
Title = $"{query} - Quality {i + 1}",
Artist = "Various Authors",
Album = $"{query} Series",
Category = "Audiobook",
Size = random.Next(200_000_000, 1_500_000_000),
Seeders = isUsenet ? 0 : random.Next(5, 100),
Leechers = isUsenet ? 0 : random.Next(0, 20),
Source = indexerName,
PublishedDate = DateTime.UtcNow.AddDays(-random.Next(1, 365)).ToString("o"),
Quality = i switch
{
0 => "MP3 64kbps",
1 => "MP3 128kbps",
2 => "MP3 192kbps",
3 => "M4B 128kbps",
_ => "FLAC"
},
Format = i >= 3 ? "M4B" : "MP3",
Language = "English"
};

if (isUsenet)
{
result.NzbUrl = $"https://{indexerName.ToLowerInvariant()}.example.com/api/nzb/{Guid.NewGuid():N}";
result.MagnetLink = string.Empty;
result.TorrentUrl = string.Empty;
}
else
{
result.MagnetLink = $"magnet:?xt=urn:btih:{Guid.NewGuid():N}";
result.NzbUrl = string.Empty;
}

results.Add(result);
}

return results;
}
}
44 changes: 44 additions & 0 deletions tests/Features/Application/Search/IndexerSearchWorkflowTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Listenarr - Audiobook Management System
* Copyright (C) 2024-2026 Listenarr Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

using Listenarr.Tests.Common;

namespace Listenarr.Tests.Features.Application.Search
{
[Trait("Area", "Search")]
[Trait("Name", "IndexerSearchWorkflowTests")]
[Trait("Category", "IndexerSearchWorkflow")]
public class IndexerSearchWorkflowTests : BaseTests
{
[Fact]
[Trait("Method", "SearchIndexersAsync")]
[Trait("Scenario", "NoIndexersConfiguredReturnsEmptyNotMockResults")]
public async Task SearchIndexers_NoIndexersConfigured_ReturnsEmptyWithoutSyntheticResults()
{
// Given
var workflow = _provider.GetRequiredService<IndexerSearchWorkflow>();
Assert.Empty(await _indexerRepository.GetEnabledAsync(isAutomaticSearch: false));

// When
var results = await workflow.SearchIndexersAsync("Dune");

// Then
Assert.Empty(results);
}
}
}