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

Bug [V4] PactDslJsonRootValue as request body fails #1841

Open
huehnerlady opened this issue Nov 27, 2024 · 0 comments
Open

Bug [V4] PactDslJsonRootValue as request body fails #1841

huehnerlady opened this issue Nov 27, 2024 · 0 comments

Comments

@huehnerlady
Copy link
Contributor

My issue sounds a bit similar to #883, but this time it is with Pactversion V4.

I have the following pact test

@ExtendWith(value = [PactConsumerTestExt::class])
@Tag("pact")
@PactTestFor(providerName = "Provider")
class WebidStatusPactConsumerTest {

  @Pact(consumer = "Consumer")
  fun test(builder: PactBuilder) =
      builder
          .expectsToReceiveHttpInteraction("test") { httpBuilder ->
            httpBuilder
                .withRequest { httpRequestBuilder ->
                  httpRequestBuilder
                      .path("/test")
                      .method("POST")
                      .headers(mapOf("Content-Type" to "text/plain"))
                      .body(PactDslJsonRootValue.stringType("exampleString"))
                }
                .willRespondWith { httpResponseBuilder ->
                  httpResponseBuilder
                      .status(200)
                }
          }
          .toPact()

  @Test
  @PactTestFor(pactMethod = "test", pactVersion = V4)
  fun test(mockServer: MockServer) {
    shouldNotThrowAny {
      RestTemplate().postForObject<Void>(mockServer.getUrl() + "/test", "exampleString")
    }
  }
}

When this runs, I get the pact error

au.com.dius.pact.consumer.PactMismatchesException: The following mismatched requests occurred:
body - /: Expected body '"exampleString"' to match 'exampleString' using equality but did not match

when I change my request to be "\"exampleString\"" it works (I run into the next issue in my pact, but this is out of scope here)

So it seems there is an additional " expected for some reason?

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

No branches or pull requests

1 participant