pact-foundation / pact-specification

Describes the pact format and verification specifications
MIT License
295 stars 28 forks source link

Feature Request - eachLike(itemDescriptionWithMatchers, exampleArray?) #101

Open hborham opened 2 years ago

hborham commented 2 years ago

Checklist

This checklist is optional, but studies show that people who have followed it checklist are really excellent people and we like them 🤣

Before making a feature request, I have:

Feature description

Please describe what you would like Pact-js to do

Extended support for matching arrays with an optional example parameter, such as:

eachLike(itemDescriptionWithMatchers, exampleArray?)
atLeastOneLike(matcher, exampleArray?)` 

Use case

What is the use case that motivates this feature request? Reuse of pacts for consumer development/testing while utilizing the pact-stub-server Please describe why you would like Pact-js to have this feature.

We have a consumer (react ui) pact we would like to reuse as a stub response within a real network request by loading our pacts into thepactfoundation/pact-stub-server. This benefits us in two specific ways:

  1. We're able to reuse our pacts for a small set of integration tests with the provider apis
  2. We're able to reuse our pacts for local development purposes of react ui and not be connected to a provider backend.

Our goal is to generate a realistic response to reuse during development/testing and also be minimalistic for the provider to verify, eg atLeastOneLike.

Request for matcher(s) to support eachLike(matcher, exampleArray?), atLeastOneLike(matcher, exampleArray?) so that the generated stub response for the consumer definition is:

{
    picklists: [
      {id: 1, name: 'She/Her'},
      {id: 2, name: 'He/Him'},
      {id: 3, name: 'They/Them'},
      {id: 4, name: 'Other'},
    ]
}

and the generated matcher for the provider is:

"matchingRules": {
    "body": {
      "$": {
        "combine": "AND",
        "matchers": [
          {
            "match": "type"
          }
        ]
      },
      "$.picklists": {
        "combine": "AND",
        "matchers": [
          {
            "match": "type",
            "min": 1
          }
        ]
      }
    },
}

Additional discussion here pact-foundation.slack.com/#general

mefellows commented 2 years ago

Thanks for this!

hborham commented 1 year ago

@mefellows would you happen to know if this feature request is a candidate for https://github.com/pact-foundation/pact-js/labels/good%20first%20issue

It would make my life easier, so I was wondering if I could tackle this feature.

mefellows commented 1 year ago

I don't think it is Haz, as this will require a framework-wide change. @uglyog @bethesque any thoughts on this?

Should this migrate to the Pact Spec project?

bethesque commented 1 year ago

This is a pact-spec change.