Add unit tests for Environments, Audit, and Webhooks namespaces (#6)
## 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
This commit was merged in pull request #6.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using MicCheck.Api.Projects;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace MicCheck.Api.Tests.Unit.Projects;
|
||||
|
||||
[TestFixture]
|
||||
public class SetUserPermissionsRequestValidatorTests
|
||||
{
|
||||
private SetUserPermissionsRequestValidator _validator = null!;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() => _validator = new SetUserPermissionsRequestValidator();
|
||||
|
||||
[Test]
|
||||
public void WhenTheRequestIsValid_ThenValidationSucceeds()
|
||||
{
|
||||
var result = _validator.Validate(new SetUserPermissionsRequest(1, true, ["ViewProject", "EditFeature"]));
|
||||
|
||||
Assert.That(result.IsValid, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenUserIdIsZeroOrLess_ThenValidationFails()
|
||||
{
|
||||
var result = _validator.Validate(new SetUserPermissionsRequest(0, true, []));
|
||||
|
||||
Assert.That(result.IsValid, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenAPermissionIsInvalid_ThenValidationFails()
|
||||
{
|
||||
var result = _validator.Validate(new SetUserPermissionsRequest(1, false, ["NotAPermission"]));
|
||||
|
||||
Assert.That(result.IsValid, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhenPermissionsListIsEmpty_ThenValidationSucceeds()
|
||||
{
|
||||
var result = _validator.Validate(new SetUserPermissionsRequest(1, true, []));
|
||||
|
||||
Assert.That(result.IsValid, Is.True);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user