Hi, I'm doing bi-directional contract testing betw...
# pact-js
s
Hi, I'm doing bi-directional contract testing between
PortalUI
&
ProfileService
. I have the OpenAPI specification for
PortalService
, which includes the following endpoints: • GET /profiles - return 200 or 401 • GET /profiles/{id} - return 200 or 400 or 404 or 401 They are both set to use JWT authentication. For the consumer contract, I'm running the tests shown in the screenshot (I have also attached the generated pact). On contract comparison, I get a few errors. For both endpoints I get one about
Request Authorization header is missing but is required by spec file
. It is true that the Authorization header is required, but I also want to ensure not specifying it returns a 401. This example on StackOverflow shows how to make security optional in the OpenAPI spec, but that might lead to the API implementation lacking proper security of endpoints (and a tool such as Dredd would likely not catch that, since the spec says it's optional). Any idea how to deal with this issue? For
get /profiles
I get additional
Response Body is Incompatible
errors: • Response body is incompatible with the response body schema in the spec file: should be array • Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - content • Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - contentType • Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - encoded The
response
in the contract looks like this:
Copy code
"response": {
  "body": {
    "content": [],
    "contentType": "application/json",
    "encoded": false
  },
  "headers": {
    "Content-Type": [
      "application/json; charset=utf-8"
    ]
  },
  "status": 200
}
Response body is incompatible with the response body schema in the spec file: should NOT have additional properties - encoded
Mismatched Pact Path:
[root].interactions[1].response.body
Mismatched Provider Path:
[root].paths./profiles.get.responses.200.content.application/json; charset=utf-8.schema.additionalProperties
Initially I had
additionalProperties
set to
false
in the schema for
Profile
, but even after removing that, deleting the pacts & re-publishing, it still points to that under `Mismatched Provider Path`:
Copy code
Profile:
  type: object
  required:
    - id
    - username
    - picture
  additionalProperties: false
  properties:
    id:
      type: string
    username:
      type: string
    picture:
      type: string
for the sake of completion, here is a screenshot of the
Response Body Is Incompatible
errors
t
Please post this in #pactflow
👍 1
This is not a pact feature
m
Tim’s right, if you could for next time that would be great
👍 1
It will help get the right eyes on it.
But for now, given your detailed (thank you) question, I’ll try and respond here. At the moment, we don’t support testing negative scenarios in this way because - as you’ve discovered - we validate the request and response bodies, and the request bodies won’t be valid. We have a backlog item to consider ways to address this use case - perhaps by ignoring the request bodies for tests that have negative status expectations. I’d suggest for now not including these in your consumer tests, or at least not having them written / persisted in your pact tests (one idea could be to simply post-process the pact file and remove entries that have negative status codes. This way, at least you have some confidence your API client can handle the status codes.
👍 1
s
thanks guys! sorry I didn't realize this was just pactflow specific .. will do a better assessment next time 👍
🙌 1
👍 1
m
No probs - easy to do!
t
No worries at all!