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

[Verification] are v3 provider state generators supported yet? #197

Closed
benifietray opened this issue May 19, 2022 · 1 comment · Fixed by #200
Closed

[Verification] are v3 provider state generators supported yet? #197

benifietray opened this issue May 19, 2022 · 1 comment · Fixed by #200

Comments

@benifietray
Copy link

benifietray commented May 19, 2022

Consumer pact using pathFromProviderState (see section "Having values injected from provider state callbacks
" on pact-jvm consumer docs)

.given("a user exists", Map("id" -> "6000"))....
.pathFromProviderState("/api/users/${id}", "/api/users/100")

creates a pact json file with interaction object like

{
      "description": "a request to find a user",
      "providerStates": [
        {
          "name": "a user exists",
          "params": {
            "id": "6000"
          }
        }
      ],
      "request": {
        "generators": {
          "path": {
            "dataType": "STRING",
            "expression": "/api/users/${id}",
            "type": "ProviderState"
          }
        },
        "method": "GET",
        "path": "/api/users/100"
      },
      "response": {
        "body": {
          "id": "6000"
        },
        "status": 200
      }
    }
...

Producer verification state change function

...
.withStateChangeFunction({
      case ProviderState("a user exists", params) =>
        val id = params.getOrElse("id", fail("params missing value id"))
        createUserWithId(id)
      case _ => ()
    }: PartialFunction[ProviderState, Unit])

Expected
Pact verification calls producer with path /api/users/6000

Actual
Pact verification calls producer with path /api/users/

Need help regarding the above scenario. I am not sure if it's a bug, yet to be supported feature or if I am doing something wrong.

I have been able to replicate this on the PactVerifierStateChangeFunctionSuite.scala test by using the following pact json content modified to use generators

Logs from unit test execution

[PACT4S TEST INFO] Request to mock provider server with port 49171 in test suite scalatest/requestresponse/PactVerifierStateChangeFunctionSuite.scala
[PACT4S TEST INFO] Request(method=GET, uri=/anyone-, headers=Headers(Accept-Encoding: gzip, x-gzip, deflate, Host: localhost:49171, Connection: keep-alive, User-Agent: Apache-HttpClient/5.1.1 (Java/11.0.11)))
[PACT4S TEST INFO] Response(status=404, headers=Headers(Content-Type: text/plain; charset=UTF-8, Content-Length: 9))
[PACT4S TEST INFO] Duration: 0 millis
2022-05-19 01:44:07,378 [pool-2-thread-1] DEBUG  a.c.d.pact.provider.ProviderClient - Received response: 404
2022-05-19 01:44:07,379 [pool-2-thread-1] DEBUG  a.c.d.pact.provider.ProviderClient - Response: ProviderResponse(statusCode=404, headers={Date=[Thu, 19 May 2022 00:44:07 GMT], Connection=[keep-alive], Content-Type=[text/plain; charset=UTF-8], Content-Length=[9]}, contentType=text/plain; charset=UTF-8, body=Not found)
    returns a response which
      has status code 200 (FAILED)
      has a matching body (FAILED)
@jbwheatley
Copy link
Owner

jbwheatley commented May 25, 2022

I am trying to look into this! I expect it is a failing of the pact4s implementation.

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 a pull request may close this issue.

2 participants