Skip to content

Matching rules input / output mismatch #65

@tall-dan

Description

@tall-dan

I am using pact specification version 3, and using multiple files to declare my interactions, as described here.

I've noticed that the matching rules are being lost for all interactions besides the last one to execute during my test suite. I've dug through the source code and the pact specification, and I think I found a discrepancy.

Pact Specification
The Jsonpath section of the specification seems to declare that matchingRules be a top level key for request and response, and that matchingRules should then have keys that dictate what section of the request / response are being matched. It looks like Jsonpath takes over from there.

Code
Pact::InteractionV3Parser.parse_request_with_non_string_body takes care of nested matching rules, and line 45 indexes into request_matching_rules with a key, e.g. body. This is consistent with what the specification describes.

The pact file I'm getting
Looks something like this:

{
  "consumer": {
    "name": "My Consumer"
  },
  "provider": {
    "name": "My Provider"
  },
  "interactions": [
    {
      "description": "An events request",
      "providerState": "an event board exists",
      "request": {
        "method": "POST",
        "path": "/graphql",
        "body": {
          "operationName": null,
          "query": "{\n  eventBoard {\n    title\n     __typename\n  }\n}\n",
          "variables": { }
        }
      },
      "response": {
        "status": 200,
        "body": {
          "data": {
            "eventBoard": {
              "title": {
                "__typename": "TranslatableField",
                "en": "Example Event Board Title"
              },
              "__typename": "EventBoard"
            }
          }
        },
        "matchingRules": {
          "$.body.data.eventBoard.title": {
            "match": "type"
          }
        }
      }
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "3.0.0"
    }
  }
}

Note that the matchingRules that are written here do not conform with the spec. I'm still reading through the code to find out where the contract gets written to the filesystem, but this seems to be the source of my problem. Can anyone confirm that this is a bug, or am I missing something?

Local setup
npm packages:

gems (which come from pact-node)

  • pact-1.38.0
  • pact-message-0.5.0
  • pact-mock_service-2.12.0
  • pact-provider-verifier-1.22.0
  • pact-support-1.9.0
  • pact_broker-client-1.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions