Skip to content
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

Request body is missing in generated pact file for requests that include matching on request body #788

Closed
shack05 opened this issue Aug 11, 2022 · 4 comments
Labels

Comments

@shack05
Copy link

shack05 commented Aug 11, 2022

Describe the bug

The request body is missing in generated pact file for requests that include matching on request body.
More specifically, I am using the JsonPartialMatcher.

Expected behavior:

The generated pact file includes the expectations of the request body as specified by the matchers used in the wiremock scenario.

Test to reproduce

server
   .WithConsumer("Consumer1")
   .WithProvider("Provider1");

server
   .Given(Request.Create().UsingPost().WithPath("/foo")
      .WithBody(new JsonPartialMatcher(@"{ ""name"": ""john"" }")))
   .WithTitle("Example1")
   .RespondWith(Response.Create().WithStatusCode(201)));

server.SavePact("...")

I'm not sure what the expected pact should look like, but I imagine request body should be included in some way.
The actual pact file is:

{
   "consumer": {
      "name": "Consumer1"
   },
   "interactions": [
      {
         "providerState": "Example1",
         "request": {
            "method": "POST",
            "path": "/foo",
         },
         "response": {
            "status": "201",
         } 
      }
   ],
   "provider": {
      "name": "Provider1"
   }
}

Other related info

WIremock version - 1.5.3-ci-16331 (from #784).

@shack05 shack05 added the bug label Aug 11, 2022
@StefH
Copy link
Collaborator

StefH commented Aug 12, 2022

The only possible solution would be that I deserialize the value from the matcher (@"{ ""name"": ""john"" }"), so that the pact could be:

{
   "consumer": {
      "name": "Consumer1"
   },
   "interactions": [
      {
         "providerState": "Example1",
         "request": {
            "method": "POST",
            "path": "/foo",
            "body": {
              "name" : "john"
            }
         },
         "response": {
            "status": "201",
         } 
      }
   ],
   "provider": {
      "name": "Provider1"
   }
}

Another option would be that you can add an example body like:

server
   .Given(Request.Create().UsingPost().WithPath("/foo")
      .WithBody(new JsonPartialMatcher(@"{ ""name"": ""john"" }"))).WithExample( ... todo ...) 

@StefH
Copy link
Collaborator

StefH commented Aug 12, 2022

@shack05
Can you try preview version 1.5.3-ci-16359 ?

@shack05
Copy link
Author

shack05 commented Aug 14, 2022

Hi @StefH, thank you, preview 1.5.3-ci-16359 works like a charm.

@StefH
Copy link
Collaborator

StefH commented Aug 15, 2022

@shack05 Thanks for testing.
For now use the preview, in some time I'll release a new official.

@StefH StefH closed this as completed Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants