Перевести задачи Discovery на NotFoundException
ci / build-test (pull_request) Successful in 2m52s

DiscoveryTasksService (get/patch/delete/start/pause) бросает NotFoundException вместо null; эндпоинты отдают 404 через общий обработчик.
This commit is contained in:
2026-09-13 14:32:27 +03:00
parent 685c5fdf46
commit 8661faea70
3 changed files with 61 additions and 77 deletions
@@ -1,8 +1,9 @@
using Deal.Modules.Discovery.Application.Exceptions;
using Deal.Modules.Discovery.Application.Models;
using Deal.Tests.Unit.Support;
using Deal.Modules.Discovery.Application.Services;
using Deal.SharedKernel.Errors;
using Deal.Tests.Unit.Modules.Settings;
using Deal.Tests.Unit.Support;
namespace Deal.Tests.Unit.Modules.Discovery;
@@ -131,14 +132,13 @@ public sealed class DiscoveryTasksServiceTests
}
[Fact]
public async Task Patch_MissingTask_ReturnsNull()
public async Task Patch_MissingTask_ThrowsNotFound()
{
(DiscoveryTasksService service, _, _) = Create();
DiscoveryTaskDto? patched = await service.PatchAsync(
"dt_missing", new DiscoveryTaskPatch { Name = "Новое" }, CancellationToken.None);
Assert.Null(patched);
await Assert.ThrowsAsync<NotFoundException>(
() => service.PatchAsync(
"dt_missing", new DiscoveryTaskPatch { Name = "Новое" }, CancellationToken.None));
}
[Fact]
@@ -201,13 +201,12 @@ public sealed class DiscoveryTasksServiceTests
}
[Fact]
public async Task Start_MissingTask_ReturnsNull()
public async Task Start_MissingTask_ThrowsNotFound()
{
(DiscoveryTasksService service, _, _) = Create();
DiscoveryTaskDto? task = await service.StartAsync("dt_missing", CancellationToken.None);
Assert.Null(task);
await Assert.ThrowsAsync<NotFoundException>(
() => service.StartAsync("dt_missing", CancellationToken.None));
}
[Fact]
@@ -281,9 +280,8 @@ public sealed class DiscoveryTasksServiceTests
store.SeedCandidate(Candidate("c_2", "dt_2"));
await store.Store.UpsertBlacklistAsync("c_1", "Источник", "причина", CancellationToken.None);
bool deleted = await service.DeleteAsync("dt_1", CancellationToken.None);
await service.DeleteAsync("dt_1", CancellationToken.None);
Assert.True(deleted);
Assert.Single(store.Tasks); // dt_2 осталась
Assert.Equal("dt_2", Assert.Single(store.Tasks).Id);
Assert.Single(store.Candidates); // кандидат dt_2 остался
@@ -292,13 +290,12 @@ public sealed class DiscoveryTasksServiceTests
}
[Fact]
public async Task Delete_MissingTask_ReturnsFalse()
public async Task Delete_MissingTask_ThrowsNotFound()
{
(DiscoveryTasksService service, _, _) = Create();
bool deleted = await service.DeleteAsync("dt_missing", CancellationToken.None);
Assert.False(deleted);
await Assert.ThrowsAsync<NotFoundException>(
() => service.DeleteAsync("dt_missing", CancellationToken.None));
}
[Fact]