jbwheatley / pact4s

Apache License 2.0
29 stars 11 forks source link

Use generators and inject auto generated Ids from provider #416

Open pradippatil opened 1 year ago

pradippatil commented 1 year ago

Hello,

I am facing some challenges while using generators with Pact4s on the Provider side for verification. My current issue is that I am using withStateChangeFunction, which is ProviderState => Unit, and I am not able to return anything. I am struggling with how to inject some of the data that gets generated on the Provider side, such as auto-generated ids.

I have included the consumer pact that I want to verify, and I am specifically looking to generate the taskId on the Provider side and inject it into the pact. Here is the relevant portion of the consumer pact:


"providerStates": [
     {
       "name": "task exists"
     }
   ],
    "request": {
      "generators": {
        "path": {
          "dataType": "STRING",
          "expression": "/tasks/${taskId}",
          "type": "ProviderState"
        }
      },
      "method": "GET",
      "path": "/tasks/1234",
}
    .withStateChangeFunction({
      case ProviderState("task exists", _) =>
        createTask() # this is where we would get taskId from Provider 
      case _ => ()
    }: PartialFunction[ProviderState, Unit])

I would appreciate any guidance on how to achieve this. Thank you in advance for your help!

jbwheatley commented 1 year ago

looking into this - doesn't seem like we support it properly

jbwheatley commented 1 year ago

Its unclear to me how these work in pact-jvm. If anyone else is able to investigate how this should be supported in pact4s, that would be great. I don't quite have the bandwidth to look into this issue right now.