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

@@ -274,6 +274,51 @@ public class SegmentEvaluatorTests
Assert.That(_evaluator.Evaluate(segment, [], "another-user"), Is.False);
}
[Test]
public void WhenModuloConditionValueIsMalformed_ThenSegmentDoesNotMatch()
{
var segment = BuildSegment(SegmentRuleType.All,
Condition("userId", SegmentConditionOperator.ModuloValueDivisorRemainder, "not-a-modulo-spec"));
var traits = new[] { Trait("userId", "9") };
Assert.That(_evaluator.Evaluate(segment, traits), Is.False);
}
[Test]
public void WhenModuloDivisorIsZero_ThenSegmentDoesNotMatch()
{
var segment = BuildSegment(SegmentRuleType.All,
Condition("userId", SegmentConditionOperator.ModuloValueDivisorRemainder, "0|0"));
var traits = new[] { Trait("userId", "9") };
Assert.That(_evaluator.Evaluate(segment, traits), Is.False);
}
[Test]
public void WhenPercentageSplitValueIsNotANumber_ThenSegmentDoesNotMatch()
{
var segment = BuildSegment(SegmentRuleType.All,
Condition("", SegmentConditionOperator.PercentageSplit, "not-a-number"));
Assert.That(_evaluator.Evaluate(segment, [], "any-user"), Is.False);
}
[Test]
public void WhenARuleHasAChildRuleThatFails_ThenTheParentRuleDoesNotMatchEvenIfItsOwnConditionsPass()
{
var segment = new Segment { Name = "Test", ProjectId = 1, CreatedAt = DateTimeOffset.UtcNow };
var parent = new SegmentRule { Type = SegmentRuleType.All };
parent.Conditions.Add(Condition("plan", SegmentConditionOperator.Equal, "premium"));
var child = new SegmentRule { Type = SegmentRuleType.All };
child.Conditions.Add(Condition("country", SegmentConditionOperator.Equal, "US"));
parent.ChildRules.Add(child);
segment.Rules.Add(parent);
var traits = new[] { Trait("plan", "premium"), Trait("country", "UK") };
Assert.That(_evaluator.Evaluate(segment, traits), Is.False);
}
[Test]
public void WhenRuleTypeIsAny_ThenAtLeastOneConditionMustMatch()
{