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:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user