Skip to content

Fix expected body when using generators #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

karouf
Copy link

@karouf karouf commented Apr 10, 2025

Since v1.66.0, with the introduction of generators, we started to see issues where instead of setting the JSON body of the expected request as a string, Pact started returning the same data but encoded as query parameters.

The consumer Pact is generated using v3 of the Pact spec with the JVM SDK, and specifically stringType from PactDslJsonBody. It produces a Pact file that contains something like

"generators": {
  "body": {
    "$.user.name": {
      "size": 20,
      "type": "RandomString"
    }
  }
}

You can find a reproduction case in a dedicated repository.
Just run bundle exec rake pact:verify:foobar to have a successful verification with v1.65.3.
And run FAIL=1 bundle exec rake pact:verify:foobar to demonstrate the issue with v1.66.0.

After investigating a bit, we narrowed it down to that commit.
In order to demonstrate the issue, I added this test.
My proposed fix is done in Pact::Provider::Request::Replayable because I'm not super familiar with the code base and I wasn't sure if Pact::Provider::Generators.apply_generators should ever return anything else than a string or not. But if it's not the case, the fix could probably go in Pact::Provider::Generators as I suspect there is the same issue with the way path and maybe headers are generated as well.

I'd be happy to fix it another way if you find it better and cover other cases if needed. Just let me know 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant