Add a failing test for JsonType assert#61
Open
Kolyunya wants to merge 1 commit intoCodeception:masterfrom
Open
Add a failing test for JsonType assert#61Kolyunya wants to merge 1 commit intoCodeception:masterfrom
Kolyunya wants to merge 1 commit intoCodeception:masterfrom
Conversation
Member
|
Thanks! Currently we don't have an opportunity to dive into context to figure out the issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I believe the
seeResponseMatchesJsonType()assert is broken and I've added a failing test to illustrate this.We are going to test different JSON documents against the same assertion. The assertion is:
It means: "Each of the users (if any) and each of his roles(is any) must have a string property
name. The if any part is crucial here.The first document has non-empty
rolesfor all users and the assertion passes:{ "users": [ { "id": 1, "roles": [ { "name": "admin" } ] } ] }The second document has non-empty
rolesfor some of the users and the assertion passes:{ "users": [ { "id": 1, "roles": [ { "name": "admin" } ] }, { "id": 2, "roles": [] } ] }The last document has all users with an empty
rolesarray and the assertion fails when it should pass:{ "users": [ { "id": 1, "roles": [] } ] }The second example is supplied to justify the fact the last assertion must pass. It shows that the assertion passes for empty arrays.
This issue arose in a real project of mine where I had a paginated resource. On some pages I had some users with roles and the assertion passed. On the other pages, all the users had empty roles array and the assertion unexpectedly failed. The problem here is that I can not see any elegant ways to work around the issue.