Skip to content

Commit

Permalink
test: merge AssertContains asserts
Browse files Browse the repository at this point in the history
It slightly modifies the behavior of AssertContains as it now checks for
all properties of ExpectedDifference at once instead of splitting the
rule and jsonref checks into two separate asserts. This is more in line
with what we expect from the method.

AssertContainsOnly is replaced by an optional param to AssertContains.
  • Loading branch information
NextFire committed Jul 11, 2024
1 parent cff4ba8 commit 72fc86e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 97 deletions.
18 changes: 9 additions & 9 deletions src/Criteo.OpenApi.Comparator.UTest/OpenApiEnumDirectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,59 @@ public class OpenApiEnumDirectionTests
[TestCase("old_without_refs", "query_add", "#/paths/~1order~1{path}/post/parameters/1/schema/enum")]
[TestCase("old_without_refs", "body_add", "#/paths/~1order~1{path}/post/requestBody/content/application~1json/schema/properties/foo/enum")]
[TestCase("old_with_refs", "request_ref_add", "#/paths/~1order~1{path}/post/parameters/0/schema/enum")]
public void CompareOAS_ShouldReturn_NonBreaking_AddedEnumValueChange(string oldName, string newName, string jsonRef, int expectedDifferencesCount = 1)
public void CompareOAS_ShouldReturn_NonBreaking_AddedEnumValueChange(string oldName, string newName, string jsonRef)
{
var differences = CompareSpecifications(oldName, newName);
differences.AssertContains(new ExpectedDifference
{
Rule = ComparisonRules.AddedEnumValue,
Severity = Severity.Warning,
NewJsonRef = jsonRef
}, expectedDifferencesCount);
});
}


[TestCase("old_without_refs", "response_add", "#/paths/~1order~1{path}/post/responses/200/content/application~1json/schema/properties/bar/enum")]
[TestCase("old_with_refs", "response_ref_add", "#/paths/~1order~1{path}/post/responses/200/content/application~1json/schema/properties/bar/enum")]
[TestCase("old_with_refs", "both_ref_add", "#/paths/~1order~1{path}/post/responses/200/content/application~1json/schema/properties/foo/enum", 2)]
public void CompareOAS_ShouldReturn_Breaking_AddedEnumValueChange(string oldName, string newName, string jsonRef, int expectedDifferencesCount = 1)
[TestCase("old_with_refs", "both_ref_add", "#/paths/~1order~1{path}/post/responses/200/content/application~1json/schema/properties/foo/enum")]
public void CompareOAS_ShouldReturn_Breaking_AddedEnumValueChange(string oldName, string newName, string jsonRef)
{
var differences = CompareSpecifications(oldName, newName);
differences.AssertContains(new ExpectedDifference
{
Rule = ComparisonRules.AddedEnumValue,
Severity = Severity.Error,
NewJsonRef = jsonRef
}, expectedDifferencesCount);
});
}

[TestCase("old_without_refs", "response_remove", "#/paths/~1order~1{path}/post/responses/200/content/application~1json/schema/properties/bar/enum")]
[TestCase("old_with_refs", "response_ref_remove", "#/paths/~1order~1{path}/post/responses/200/content/application~1json/schema/properties/bar/enum")]
public void CompareOAS_ShouldReturn_NonBreaking_RemovedEnumValueChange(string oldName, string newName, string jsonRef, int expectedDifferencesCount = 1)
public void CompareOAS_ShouldReturn_NonBreaking_RemovedEnumValueChange(string oldName, string newName, string jsonRef)
{
var differences = CompareSpecifications(oldName, newName);
differences.AssertContains(new ExpectedDifference
{
Rule = ComparisonRules.RemovedEnumValue,
Severity = Severity.Warning,
NewJsonRef = jsonRef
}, expectedDifferencesCount);
});
}

[TestCase("old_without_refs", "path_remove", "#/paths/~1order~1{path}/post/parameters/0/schema/enum")]
[TestCase("old_without_refs", "query_remove", "#/paths/~1order~1{path}/post/parameters/1/schema/enum")]
[TestCase("old_without_refs", "body_remove", "#/paths/~1order~1{path}/post/requestBody/content/application~1json/schema/properties/foo/enum")]
[TestCase("old_with_refs", "request_ref_remove", "#/paths/~1order~1{path}/post/parameters/0/schema/enum")]
[TestCase("old_with_refs", "both_ref_remove", "#/paths/~1order~1{path}/post/requestBody/content/application~1json/schema/properties/foo/enum")]
public void CompareOAS_ShouldReturn_Breaking_RemovedEnumValueChange(string oldName, string newName, string jsonRef, int expectedDifferencesCount = 1)
public void CompareOAS_ShouldReturn_Breaking_RemovedEnumValueChange(string oldName, string newName, string jsonRef)
{
var differences = CompareSpecifications(oldName, newName);
differences.AssertContains(new ExpectedDifference
{
Rule = ComparisonRules.RemovedEnumValue,
Severity = Severity.Error,
NewJsonRef = jsonRef,
}, expectedDifferencesCount);
});
}

private static IList<ComparisonMessage> CompareSpecifications(string oldName, string newName)
Expand Down
Loading

0 comments on commit 72fc86e

Please sign in to comment.