Hi, I'm having some issues with bi-directional con...
# pactflow
s
Hi, I'm having some issues with bi-directional contract testing. I initially posted that here -> https://pact-foundation.slack.com/archives/C9VBGLUM9/p1667571726865759. The 2 issues I encountered were: • issues with Authorization header not being present on negative tests (testing for 401 response codes) - the resolution for that is that Pactflow does not support negative tests so I removed them • the other issue is with the response body.. it seems that the consumer pact wraps the response body and adds some additional fields, which cause the diffing to fail
Copy code
"response": {
        "body": {
          "content": [],
          "contentType": "application/json",
          "encoded": false
        },
        "headers": {
          "Content-Type": [
            "application/json; charset=utf-8"
          ]
        },
        "status": 200
      },
message has been deleted
m
Thanks for the detailed question! I also pasted in the other channel, but for posterity: 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.
s
@Matt (pactflow.io / pact-js / pact-go) I removed the tests for 401s (no auth header) .... the other interactions still fail.... the issue is due to pact adding additional fields to the response body ->
contentType
&
encoded
... while wrapping the original returned body under
content
... the OpenAPI spec says the response body is an array, but the response body in the contract is an object (the array data is put under
content
)
See the 2 messages above (on this thread): what the response looks like in the pact & screenshots with the diffing errors
m
Hi Stefan, apologies I haven’t had a chance to review this today. I’m off for the weekend so won’t get a view until next week. I think to understand why the contract is being serialised not inline with your expectations, we’d need to see the test code that generates it also. If you could share that, it would be great.
👍 1
s
hey @Matt (pactflow.io / pact-js / pact-go), did you get a chance to have a look at this?
@Matt (pactflow.io / pact-js / pact-go) could you help out with this please?
m
Hi Stefan, I have reproduced the problem and have raised an internal ticket to fix (PACT-458). In the mean time, I think the issue is that the specification serialisation is Pact V4 and there is a bug in how we compare a V4 pact to the OAS. For now, I’d suggest explicitly setting the specification version on the test to V2 or V3.
I’m very sorry for the delay in responding, sometimes issues like this can get lost in slack (especially ones that require more effort to debug).
I should have requested you submit a support ticket to support@pactflow.io. If the resolution above doesn’t sort you out, please do submit a ticket to the email above so the team will look into it and it won’t get lost in this noise.
s
thanks, I will try this workaround and get back to you 👍 (and email support if not resolved)
👍 1