## Summary - Add missing unit test coverage for the Environments, Audit, and Webhooks namespaces (raises them from ~0-62% to 91-100%) - Exclude WebhookBackgroundService/WebhookRetryBackgroundService from coverage (require live DI/DB, disallowed by CLAUDE.md's no-InMemory/WebApplicationFactory rule) ## Test plan - [x] `dotnet test` full suite passes (646/646) - [x] Coverage report confirms Environments ~99.5%, Audit 100%, Webhooks ~91% Reviewed-on: #6
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
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);
|
|
}
|
|
}
|