pact-js
pact-js copied to clipboard
Print out a template for new provider states
So, pact-js might already do this, so just close this issue if it already does, but this is what Pact Ruby prints out if there are missing provider states. Is it possible for pact-js to do the same?
Could not find one or more provider states.
Have you required the provider states file for this consumer in your pact_helper.rb?
If you have not yet defined these states, here is a template:
Pact.provider_states_for "Pact Broker Client" do
provider_state "version 5556b8149bf8bac76bc30f50a8a2dd4c22c85f30 of pacticipant Foo exists with a test environment available for release" do
set_up do
# Your set up code goes here
end
end
provider_state "an environment with name test and UUID 16926ef3-590f-4e3f-838e-719717aa88c9 exists" do
set_up do
# Your set up code goes here
end
end
provider_state "an version is deployed to environment with UUID 16926ef3-590f-4e3f-838e-719717aa88c9 with target customer-1" do
set_up do
# Your set up code goes here
end
end
provider_state "a currently deployed version exists" do
set_up do
# Your set up code goes here
end
end
end
Hmmm. I like this idea, but I'm not sure that it's very easy to do in a way that will always play well with the user's code in javascript. I suppose we could assume they're doing it the most straightforward way, and anyone who has created their own way of doing things won't need it?
I'm thinking from a "I'm a brand new user and don't know what to do next" perspective. I've been doing some work in the broker that detects what things are present in the data (eg. is there a webhook, are there any verification results at all) and then tells them what to do next (eg. you need to set up a webhook, you need to create a provider build).
eg. This is the output for the new contract publishing endpoint
Updated some-service version 791dbe552 with branch master and tags master
Pact successfully published for some-service version 791dbe552 and provider Other Service.
View the published pact at https://your-broker/pacts/provider/Other%20Service/consumer/some-service/version/791dbe552
Events detected: contract_published (pact content is the same as previous version with tag master and no new tags were applied)
Next steps:
* Configure separate Other Service pact verification build and webhook to trigger it when the pact content changes. See https://docs.pact.io/go/webhooks
If there's a best practice, simplest way to do provider states, then that would be what to show. You can always include a link to more docs that would show how to do advanced cases, but if the user was already doing advanced stuff, they probably wouldn't need the output to tell them what to do anyway.
Right, that makes sense. I like this idea.
A related idea could be “generate the provider states that are in this pact”, but I guess you’d get that on the first run if we had this feature.
I think we could just provide the following:
Could not find one or more provider states.
Have you required the provider states file for this consumer in your test?
If you have not yet defined these states, here is a template to add to the Verifier constructor:
stateHandlers: {
'state X': () => {
// do the thing
},
'state Y': () => {
// do the other thing
},
// ... any existing handlers
}