1

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.

  • if the linked thread does not answer your question, please assume this is not supported by karate. and next time please simplify the examples in your question, you can make it 3-4 lines and use things like `{ a: { b: [{ c: 1 },{ d: 2 }] } }` if you spend some time, no one will take the time to read it otherwise – Peter Thomas Aug 18 '21 at 02:53

0 Answers0