Add unit tests for Audit (59% to 100%) and Webhooks (62% to 91%) namespaces
Covers AuditLogQueryService filtering/paging/actor-name join, AuditLogResponse mapping, AuditLogsController, AuditService.LogAsync and actor-claim resolution, WebhookResponse/WebhookDeliveryLogResponse mapping, CreateWebhookRequestValidator, WebhookQueue, and additional WebhookDispatcher branch coverage (scope routing, disabled webhooks, delivery exceptions). Excludes WebhookBackgroundService and WebhookRetryBackgroundService from coverage: both resolve a DI-scoped concrete MicCheckDbContext via IServiceScopeFactory, which requires a live DI container/DB per CLAUDE.md's no-InMemory/WebApplicationFactory rule. Their query and dispatch logic is covered by WebhookRetryTests/WebhookDispatcherTests.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using MicCheck.Api.Webhooks;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MicCheck.Api.Tests.Unit.Webhooks;
|
||||
|
||||
[TestFixture]
|
||||
public class CreateWebhookRequestValidatorTests
|
||||
{
|
||||
private CreateWebhookRequestValidator _validator = null!;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() => _validator = new CreateWebhookRequestValidator();
|
||||
|
||||
[Test]
|
||||
public void WhenTheRequestIsValid_ThenValidationSucceeds()
|
||||
{
|
||||
var result = _validator.Validate(new CreateWebhookRequest("https://example.com/hook", "secret", true));
|
||||
|
||||
Assert.That(result.IsValid, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenUrlIsEmpty_ThenValidationFails()
|
||||
{
|
||||
var result = _validator.Validate(new CreateWebhookRequest("", null, true));
|
||||
|
||||
Assert.That(result.IsValid, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenUrlExceedsMaximumLength_ThenValidationFails()
|
||||
{
|
||||
var longUrl = "https://example.com/" + new string('a', 500);
|
||||
var result = _validator.Validate(new CreateWebhookRequest(longUrl, null, true));
|
||||
|
||||
Assert.That(result.IsValid, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenUrlIsNotAnAbsoluteUri_ThenValidationFails()
|
||||
{
|
||||
var result = _validator.Validate(new CreateWebhookRequest("not a valid url", null, true));
|
||||
|
||||
Assert.That(result.IsValid, Is.False);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user