pact-foundation / pact-reference

Reference implementations for the pact specifications
https://pact.io
MIT License
91 stars 46 forks source link

`eachKey` matcher incorrectly requires given keys in pact to be present #301

Closed mefellows closed 11 months ago

mefellows commented 1 year ago

Given a test like this:

      await pact
        .addInteraction()
        .uponReceiving('a request only checks the keys and ignores the values')
        .withRequest('GET', '/eachKeyMatches')
        .willRespondWith(200, (builder) => {
          builder.jsonBody(
            MatchersV3.eachKeyMatches(
              {
                key1: "a string we don't care about",
                key2: 1,
              },
              [MatchersV3.regex(/[a-z]{3,}[0-9]/, 'key1')]
            )
          );
        })

If the provider returns:

{
    "1": "foo", 
    "not valid": 1
    "key": "value", 
    "key2": "value"
  }

It correctly errors on the keys that don't match the rules:

1) Verifying a pact between myconsumer and myprovider - a request only checks the keys and ignores the values
    1.1) has a matching body
           $.key -> Expected 'key' to match '[a-z]{3,}[0-9]'
           $ -> Actual map is missing the following keys: key1
           $['not valid'] -> Expected 'not valid' to match '[a-z]{3,}[0-9]'
           $[1] -> Expected '1' to match '[a-z]{3,}[0-9]'

But as can be seen, it also fails incorrectly, requiring the two keys specified in the example to be present.

github-actions[bot] commented 1 year ago

👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-1195). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps.

See our documentation for more information.

mefellows commented 11 months ago

I believe this is closed now.