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

@@ -136,4 +136,51 @@ public class SegmentServiceTests
Assert.That(segments, Has.Count.EqualTo(2));
}
[Test]
public async Task WhenFindingASegmentByIdThatExists_ThenTheSegmentIsReturned()
{
var segment = await _service.CreateAsync(ProjectId, "Segment", [SingleConditionRule()]);
var found = await _service.FindByIdAsync(segment.Id);
Assert.That(found, Is.Not.Null);
Assert.That(found!.Id, Is.EqualTo(segment.Id));
}
[Test]
public async Task WhenFindingASegmentByIdThatDoesNotExist_ThenNullIsReturned()
{
var found = await _service.FindByIdAsync(999);
Assert.That(found, Is.Null);
}
[Test]
public void WhenUpdatingASegmentThatDoesNotExist_ThenKeyNotFoundExceptionIsThrown()
{
Assert.ThrowsAsync<KeyNotFoundException>(() =>
_service.UpdateAsync(999, "Renamed", [SingleConditionRule()]));
}
[Test]
public void WhenDeletingASegmentThatDoesNotExist_ThenNoExceptionIsThrown()
{
Assert.DoesNotThrowAsync(() => _service.DeleteAsync(999));
}
[Test]
public async Task WhenCreatingASegmentWithNestedChildRules_ThenChildRulesArePersistedWithTheParentAsTheirParent()
{
var childRule = new SegmentRuleDefinition(SegmentRuleType.Any, [new SegmentConditionDefinition("country", SegmentConditionOperator.Equal, "US")]);
var parentRule = new SegmentRuleDefinition(SegmentRuleType.All, [new SegmentConditionDefinition("plan", SegmentConditionOperator.Equal, "premium")], [childRule]);
var segment = await _service.CreateAsync(ProjectId, "Nested", [parentRule]);
var persistedRules = _segmentRules.Where(r => r.SegmentId == segment.Id).ToList();
var parent = persistedRules.Single(r => r.ParentRuleId == null);
var child = persistedRules.Single(r => r.ParentRuleId == parent.Id);
Assert.That(child.Conditions.Single().Property, Is.EqualTo("country"));
}
}