pact-foundation/pact-support

Ignoring unsupported matching rules on arrays

jkrnak opened this issue · 5 comments

I'm using pact-standalone 1.54.4 on provider side to verify and also tried with 1.0 and master of pact-go. (provider is a golang api, consumer is an ember-js app).

Consumer side matcher generation

On the consumer side I'm using ember-cli-pact.
The matcherRules generation is done via:

    specifyMatchingRules({
      response: {
        header: { 'Content-Type': regex(/application\/json/) },
        body: {
          features: arrayElements({
            properties: {
              price: type()
            }
          })
        }
      }
    })

And also I'm passing a mocked response to the mock server to validate the functionality. I'm not pasting the whole pact file here, there are some prices defined in the response but they may be different that on the provider.

Pact file excerpt

      "response": {
        "body": {
          "features": [
            { "properties": { "price": 30000  } },
            { "properties": { "price": 40000  } }
          ],
        },
        "matchingRules": {
          "$.body.features[*].properties.price": {
            "match": "type"
          },
          "$.headers.Content-Type": {
            "match": "regex",
            "regex": "application\\/json"
          }
        }
      }

Provider side

When I'm running the provider validation
pact-provider-verifier ./pacts/api.json --provider-base-url http://localhost:8080
I get the following warning:

WARN: Ignoring unsupported matching rules {"match"=>"type"} for path $['body']['features'][*]['properties']['price']

And then the validation fails because of the different prices

       Description of differences
       --------------------------------------
       * Expected 30000 but got 40000 at $.features[0].properties.price
       * Expected 20000 but got 30000 at $.features[1].properties.price

If you need any more details about the setup, just ping me.

I'm very new to the pact framework, only started exploring it this week. I might be doing something that is not supported, or supported in a different way.

My goal would be to test only a few fields that I'm actually expecting from the API in the response and I'm happy with the type matching.

Thanks!

rev42 commented

Lib used:

    "@pact-foundation/pact": "~6.0.1",
    "@pact-foundation/pact-node": "~6.19.11"

Same occurs on non-array:

json generated file:

"matchingRules": {
        "body": {
          "$.data.url": {
            "matchers": [
              {
                "match": "type"
              }
            ],
            "combine": "AND"
          }
        }
      }

The validation fails because it seems to check exact values instead of value type:

Diff
       --------------------------------------
       Key: - is expected 
            + is actual 
       Matching keys and values are not shown
        {
          "data": {
       -    "url": "http://localhost:8000/signup/complete"
       +    "url": "http://localhost:8000/signup/complete/eyJhbGciOiJI?lang=en"
          },
        }

You're using v3 matching rules, and the Ruby implementation only supports v2.

@bethesque I just stumbled upon this. I have having the same issue. For the time being I started using the gradle plugin to run my verifications. The gradle implementation seems to support v3 rules.

Sorry, I have limited time to work on this at the moment, and it just hasn't made it to the top of the priority list. I know it's very frustrating that it's not implemented yet! If anyone was interested in doing a PR, that would be amazing, but it's hard to find Ruby developers these days :(

You should be able to tell your gradle plugin to use v2 rules.

pact-go and pact-js have now been updated to use the pact-reference project via ffi, and support v3/v4 spec pacts and rules.

Pact-ruby currently does not support them, and progress will be tracked in the above linked ticket.

Switching to v2 pact generation on client implementations that leverage the rust core, will allow interop with the pact-ruby library