<#1132 Using a fromProviderState matcher in a quer...
# pact-js-development
g
#1132 Using a fromProviderState matcher in a query parameter value shouldn't return a json path matcher in the generated pact Issue created by csydvs Software versions Please provide at least OS and version of pact-js • OS: Mac OSX 12.6.5 • Consumer Pact library: Pact JS 12.1.0 • Provider Pact library: pact jvm maven 4.5.6 • Node Version: 18.17.1 Issue Checklist Please confirm the following: • [*] I have upgraded to the latest • [*] I have the read the FAQs in the Readme • [*] I have triple checked, that there are no unhandled promises in my code and have read the section on intermittent test failures • [n/a] I have set my log level to debug and attached a log file showing the complete request/response cycle ☐ For bonus points and virtual high fives, I have created a reproduceable git repository (see below) to illustrate the problem Expected behaviour Using a fromProviderState matcher in a query parameter value shouldn't return a JsonPath matcher. The reality is that I wasn't totally sure whether to open the bug on this side of the pact jvm side (for my provider), but I found this note from the V3 path specification, and if I'm reading it right, I think that it's an error on the pact-js side. But maybe there's something else I'm missing to get these things to match up correctly. So, I think that in the generated pact, I should get something like this:
Copy code
"generators": {
          "query": {
            "fooIdentifier": {
              "expression": "${fooIdentifier}",
              "type": "ProviderState"
            }
          }
        },
        "matchingRules": {
          "query": {
            "fooIdentifier": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "type"
                }
              ]
            }
          }
        },
Instead of
Copy code
"generators": {
          "query": {
            "$.fooIdentifier[0]": {
              "expression": "${fooIdentifier}",
              "type": "ProviderState"
            }
          }
        },
        "matchingRules": {
          "query": {
            "$.fooIdentifier[0]": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "type"
                }
              ]
            }
          }
        },
If I make this change manually to the pact, then pact-jvm injects the provider state like I would expect. Actual behaviour Using json path in the path matchers for query parameters. Steps to reproduce Using
provider = PactV3({ ... })
, have a provider test with something like
Copy code
provider.given('some state')
   .uponReceiving('a request for all the foos'))))
   .withRequest({
      method: 'GET',
      path: '/api/foos',
      query: {
          fooIdentifier: MatchersV3.fromProviderState('${fooIdentifier}', 'abc123')
      })
     .willRespondWith({
          status: 200
     })
And then do the test and generate the state. pact-foundation/pact-js