Update tests to expect ValidationException for BatchId dupes
Refactored InvokeBatchDuplicateGuardTests to expect and assert FluentValidation's ValidationException instead of the custom BadRequestException when a duplicate BatchId is submitted. Assertions and comments were updated accordingly, and the DigitalData.Core.Exceptions import was removed. Test logic remains unchanged.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DigitalData.Core.Exceptions;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NUnit.Framework;
|
||||
@@ -22,7 +22,7 @@ public class InvokeBatchDuplicateGuardTests : RecApplicationTestBase
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Invoke_with_existing_batchId_throws_BadRequestException()
|
||||
public async Task Invoke_with_existing_batchId_throws_ValidationException()
|
||||
{
|
||||
var (sender, scope) = CreateScopedSender();
|
||||
using var _ = scope;
|
||||
@@ -39,8 +39,8 @@ public class InvokeBatchDuplicateGuardTests : RecApplicationTestBase
|
||||
Assert.That(existingBatchId, Is.Not.Null.And.Not.Empty,
|
||||
$"No results with a BatchId found for ProfileId {ProfileId}. Ensure test data exists in the database.");
|
||||
|
||||
// Act & Assert: invoking with the same BatchId should throw
|
||||
var ex = Assert.ThrowsAsync<BadRequestException>(async () =>
|
||||
// Act & Assert: invoking with the same BatchId should throw ValidationException
|
||||
var ex = Assert.ThrowsAsync<ValidationException>(async () =>
|
||||
await sender.Send(new InvokeBatchRecActionViewsCommand
|
||||
{
|
||||
ProfileId = ProfileId,
|
||||
@@ -50,7 +50,7 @@ public class InvokeBatchDuplicateGuardTests : RecApplicationTestBase
|
||||
}
|
||||
}));
|
||||
|
||||
Assert.That(ex!.Message, Does.Contain(existingBatchId!));
|
||||
Assert.That(ex!.Errors.Any(e => e.PropertyName.Contains("BatchId")));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -61,7 +61,7 @@ public class InvokeBatchDuplicateGuardTests : RecApplicationTestBase
|
||||
|
||||
var uniqueBatchId = $"test-{System.Guid.NewGuid():N}";
|
||||
|
||||
// This should NOT throw BadRequestException for duplicate BatchId.
|
||||
// This should NOT throw ValidationException for duplicate BatchId.
|
||||
// It may throw other exceptions (e.g., no actions found, endpoint errors),
|
||||
// but the duplicate guard should pass.
|
||||
try
|
||||
@@ -75,7 +75,7 @@ public class InvokeBatchDuplicateGuardTests : RecApplicationTestBase
|
||||
}
|
||||
}).GetAwaiter().GetResult();
|
||||
}
|
||||
catch (BadRequestException badReq) when (badReq.Message.Contains("already results associated"))
|
||||
catch (ValidationException valEx) when (valEx.Errors.Any(e => e.PropertyName.Contains("BatchId")))
|
||||
{
|
||||
Assert.Fail("Duplicate guard should not trigger for a unique BatchId.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user