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

@@ -153,4 +153,73 @@ public class EnvironmentServiceTests
Assert.That(cloned.ApiKey, Is.Not.EqualTo(source.ApiKey));
}
[Test]
public void WhenCloningFromANonExistentApiKey_ThenKeyNotFoundExceptionIsThrown()
{
Assert.That(async () => await _service.CloneAsync("missing-key", "Staging"), Throws.TypeOf<KeyNotFoundException>());
}
[Test]
public async Task WhenListingByProject_ThenOnlyEnvironmentsForThatProjectAreReturned()
{
await _service.CreateAsync(ProjectId, "Env1");
await _service.CreateAsync(999, "OtherProjectEnv");
var result = await _service.ListByProjectAsync(ProjectId);
Assert.That(result, Has.Count.EqualTo(1));
Assert.That(result[0].Name, Is.EqualTo("Env1"));
}
[Test]
public async Task WhenFindingByApiKeyThatDoesNotExist_ThenNullIsReturned()
{
var result = await _service.FindByApiKeyAsync("missing-key");
Assert.That(result, Is.Null);
}
[Test]
public async Task WhenFindingByApiKeyThatExists_ThenTheEnvironmentIsReturned()
{
var created = await _service.CreateAsync(ProjectId, "Production");
var result = await _service.FindByApiKeyAsync(created.ApiKey);
Assert.That(result, Is.Not.Null);
Assert.That(result!.Id, Is.EqualTo(created.Id));
}
[Test]
public async Task WhenUpdatingAnEnvironment_ThenNameIsChanged()
{
var created = await _service.CreateAsync(ProjectId, "Original");
var updated = await _service.UpdateAsync(created.ApiKey, "Renamed");
Assert.That(updated.Name, Is.EqualTo("Renamed"));
}
[Test]
public void WhenUpdatingANonExistentEnvironment_ThenKeyNotFoundExceptionIsThrown()
{
Assert.That(async () => await _service.UpdateAsync("missing-key", "Renamed"), Throws.TypeOf<KeyNotFoundException>());
}
[Test]
public async Task WhenDeletingAnExistingEnvironment_ThenItIsRemoved()
{
var created = await _service.CreateAsync(ProjectId, "ToDelete");
await _service.DeleteAsync(created.ApiKey);
Assert.That(_environments, Is.Empty);
}
[Test]
public void WhenDeletingANonExistentEnvironment_ThenNoExceptionIsThrown()
{
Assert.That(async () => await _service.DeleteAsync("missing-key"), Throws.Nothing);
}
}