I have an expected JSON and an actual JSON. The contents of expected and actual could be shuffled. Below are my expected and actual:
Expected
{
"data": {
"company": {
"id": "c360_graph_ft_company_1",
"users": [
{
"id": "c360_graph_ft_user_1",
"fdpAccounts": [
{
"id": "c360_graph_ft_fdpAccount_4",
"accountType": "Saving",
"accountDescription": "For Saving",
"fdpProvider": {
"id": "c360_graph_ft_fdpProvider_4"
}
},
{
"id": "c360_graph_ft_fdpAccount_3",
"accountType": "Checking",
"accountDescription": "For Checking",
"fdpProvider": {
"id": "c360_graph_ft_fdpProvider_3"
}
}
]
},
{
"id": "c360_graph_ft_user_2",
"fdpAccounts": null
}
]
}
}
}
Actual:
{
"data": {
"company": {
"id": "c360_graph_ft_company_1",
"users": [
{
"id": "c360_graph_ft_user_1",
"fdpAccounts": [
{
"id": "c360_graph_ft_fdpAccount_3",
"accountType": "Checking",
"accountDescription": "For Checking",
"fdpProvider": {
"id": "c360_graph_ft_fdpProvider_3"
}
},
{
"id": "c360_graph_ft_fdpAccount_4",
"accountType": "Saving",
"accountDescription": "For Saving",
"fdpProvider": {
"id": "c360_graph_ft_fdpProvider_4"
}
}
]
},
{
"id": "c360_graph_ft_user_2",
"fdpAccounts": null
}
]
}
},
.....some additional fields we dont care about...
}
As we can see the order of fdpAccounts
is swapped
Below is one of the my attempt at validating it. I want it to return as matched but due to order mismatch it keeps failing.
Scenario: Company multiple fdpAccounts call
* def query = read('query/multiple-fdpAccounts.graphql')
* def expectedResult = read('result/multiple-fdpAccounts.json')
Given url downstreamApiUrlBase
And request { query: '#(query)' }
When method post
Then status 200
Then match response contains { "data" : '#notnull'}
Then match response.errors == '#notpresent'
Then match $response.data.company.users[*].fdpAccounts contains only $expectedResult.data.company.users[*].fdpAccounts
I tried going through many SO posts and documentation and tried contains
, contains only
, match each
, match deep
and few other things but didn't seem to work.
Sorry if I am overlooking something obvious.