Add unit tests for Environments, Audit, and Webhooks namespaces (#6)
All checks were successful
CI / build-and-push (push) Successful in 54s
CI / deploy-qa (push) Successful in 12s
CI / smoke-qa (push) Successful in 24s

## 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:
2026-07-05 15:07:26 -07:00
parent cae55e5737
commit 87113ccdcd
64 changed files with 6447 additions and 65 deletions

View File

@@ -0,0 +1,45 @@
using MicCheck.Api.Common.Security.Authorization;
using MicCheck.Api.Projects;
using NUnit.Framework;
namespace MicCheck.Api.Tests.Unit.Projects;
[TestFixture]
public class ProjectResponseTests
{
[Test]
public void WhenMappingAProject_ThenAllFieldsAreCopied()
{
var project = new Project { Id = 1, Name = "My Project", OrganizationId = 5, HideDisabledFlags = true, CreatedAt = DateTimeOffset.UtcNow };
var response = ProjectResponse.From(project);
Assert.That(response.Id, Is.EqualTo(1));
Assert.That(response.Name, Is.EqualTo("My Project"));
Assert.That(response.OrganizationId, Is.EqualTo(5));
Assert.That(response.HideDisabledFlags, Is.True);
}
}
[TestFixture]
public class UserPermissionResponseTests
{
[Test]
public void WhenMappingAUserProjectPermission_ThenPermissionsAreMappedToStrings()
{
var permission = new UserProjectPermission
{
UserId = 1,
ProjectId = 2,
IsAdmin = true,
Permissions = [ProjectPermission.ViewProject, ProjectPermission.EditFeature]
};
var response = UserPermissionResponse.From(permission);
Assert.That(response.UserId, Is.EqualTo(1));
Assert.That(response.ProjectId, Is.EqualTo(2));
Assert.That(response.IsAdmin, Is.True);
Assert.That(response.Permissions, Is.EqualTo(new[] { "ViewProject", "EditFeature" }));
}
}