pact-specification icon indicating copy to clipboard operation
pact-specification copied to clipboard

Feature Request - eachLike(itemDescriptionWithMatchers, exampleArray?)

Open hborham opened this issue 2 years ago • 4 comments

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

hborham avatar Sep 30 '22 15:09 hborham

Thanks for this!

mefellows avatar Oct 03 '22 11:10 mefellows

@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.

hborham avatar Dec 05 '22 20:12 hborham

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?

mefellows avatar Dec 05 '22 21:12 mefellows

This is a pact-spec change.

bethesque avatar Dec 13 '22 04:12 bethesque