Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print out a template for new provider states #692

Open
bethesque opened this issue Jun 11, 2021 · 4 comments
Open

Print out a template for new provider states #692

bethesque opened this issue Jun 11, 2021 · 4 comments
Labels
enhancement Indicates new feature requests good first issue Indicates a good issue for first-time contributors help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@bethesque
Copy link
Member

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
@TimothyJones
Copy link
Contributor

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?

@bethesque
Copy link
Member Author

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.

@TimothyJones
Copy link
Contributor

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.

@mefellows
Copy link
Member

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
  }

@mefellows mefellows added help wanted Indicates that a maintainer wants help on an issue or pull request good first issue Indicates a good issue for first-time contributors labels Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests good first issue Indicates a good issue for first-time contributors help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
Status: New Issue
Development

No branches or pull requests

3 participants