kiranz / just-api

:boom: Test REST, GraphQL APIs
https://kiranz.github.io/just-api/
MIT License
813 stars 35 forks source link

Error evaluating graphql response for multiple fields similar to rest api response #11

Closed mrcasablr closed 6 years ago

mrcasablr commented 6 years ago

I'm trying to use just-api with graphql. For a graphql query for a single query and response, just-api works

But for graphql multiple field query and response similar to the rest-api example below - https://github.com/kiranz/just-api/blob/master/test/cli/src/suites/jsondata.suite.yml json-api does not work.

Here is my graphql query -

{
  getAddress(id: "xxx-xxx-xxx") {
    zip
    name
    locality
    country
  }
}

and I would like to evaluate the response for all the fields.

just-api throws the following error for multi-response data -


0 skipped, 2 failed, 0 passed (2 tests)
0 skipped, 1 failed, 0 passed (1 suites)
Duration: 2.4s

Failures:

 1) Get list of all properties (/home/mrcasablr/src/just-api/api-example.yml)
ResponseJSONDataMismatchError: JSON path evaluated value did not match with expected value, json path: $.data.getAddress.zip, Actual value: undefined, Expected value: 90047 
 request: POST https://api.example.com:8443/graphql
    at Spec._validateJSONData (/home/mrcasablr/node_modules/just-api/src/spec.js:699:27)
    at Spec.validateResponse (/home/mrcasablr/node_modules/just-api/src/spec.js:333:18)
    at Spec.runAsTest (/home/mrcasablr/node_modules/just-api/src/spec.js:123:24)
    at process._tickCallback (internal/process/next_tick.js:68:7)

 2) validate json response with json data functionality - should fail (/home/mrcasablr/src/just-api/api-example.yml)
ResponseJSONDataMismatchError: JSON path evaluated value did not match with expected value, json path: $.data.getAddress.location, Actual value: undefined, Expected value: "New England" 
 request: POST https://api.example.com:8443/graphql
    at Spec._validateJSONData (/home/mrcasablr/node_modules/just-api/src/spec.js:699:27)
    at Spec.validateResponse (/home/mrcasablr/node_modules/just-api/src/spec.js:333:18)
    at Spec.runAsTest (/home/mrcasablr/node_modules/just-api/src/spec.js:123:24)
    at process._tickCallback (internal/process/next_tick.js:68:7)
kiranz commented 6 years ago

Could you post a sample of the response JSON body?

mrcasablr commented 6 years ago

Here is the sample GraphQL reponse

{
  "data": {
    "getAddress": {
      "zip": 90047,
      "name": "McDonalds",
      "location": "New England",
      "country": "001",
      "id": "xxx-xxx-xxx",
      "isVerified": null
    }
  }
}
mrcasablr commented 6 years ago

I just realised it was a typo on my end in the request. Now its working. Apologies, for the trouble.