pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.61k stars 344 forks source link

Support typed and untyped input for ConsumerVersionSelectors #715

Open bethesque opened 3 years ago

bethesque commented 3 years ago

Please add support for the following keys to be used in the consumer version selectors when fetching pacts for verification:

{ "deployedOrReleased": true }

{ "deployed": true }

{ "released": true }

{ "environment": "<env name>" }

{ "consumer": "<name>" } // this may already be supported, please add it if not

These keys can be used in various combinations ( eg. { "environment": "prod", released: true, consumer: "Foo" } ). Please allow any combination of keys, and do not validate them locally, as the validation rules can change over time as support is added for new selectors - just ensure that any errors returned from the API are displayed clearly to the user.

See https://github.com/pact-foundation/pact_broker/blob/master/lib/pact_broker/doc/views/provider-pacts-for-verification.markdown for the usage docs of each selector.

As more selectors will be added over time, it's my preference that the consumer version selectors are not strongly typed, and are just passed through straight from the configuration object to the API, so that we don't have to make code changes to the Pact clients each time we add new selectors. (eg. there will be new selectors coming for branch support very soon). I understand that this is not compatible with the idioms of every Pact client language however, so do whatever you need to do to make the new selectors work elegantly within your language.

Please update https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors/ for your language once the selectors have been released.

TimothyJones commented 3 years ago

Awesome! Thanks for this. Does the ruby core just print errors in text on stderr?

bethesque commented 3 years ago

Yes. I've actually already used these selectors in the CI/CD JS workshop, so I know they work. But Typescript blah blah.

TimothyJones commented 3 years ago

I've just released pact-node 10.13.5 and pact-core 13.1.3 - both with the new types.

it's my preference that the consumer version selectors are not strongly typed,

I'm thinking about this a bit - I reckon we could actually do both. I think with typescript we can say "this is either an object shaped like so, or one with arbitrary keys" - this would mean that typescript users will get intellisense in their editors, but also it would be valid to put unknown keys in too.

Is the value always a string or boolean, or should we allow arbitrary objects as values?

bethesque commented 3 years ago

That sounds ideal Tim.

So far, only strings and booleans for values. I wouldn't rule out having arrays in the future, but I have no plans for it currently.

bethesque commented 3 years ago

While you're in there, we now have { branch: "<name>" } and { mainBranch: true }. Could you add those please.

bethesque commented 2 years ago

What's the status on this @TimothyJones? I'm adding a section in the docs to indicate which languages/versions support this selector.

mefellows commented 2 years ago

Just noting that this is available in both the mainline and beta versions. We haven't made the type adjustment above as Tim suggested, but the type support is there and you can brute force in new options should you want. I'll leave this open to track the suggested improvement above.

mefellows commented 1 year ago

I've updated the title to (I hope) reflect the new intent of this story.