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

Allow values in a request to be changed by the provider state #57

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tucker-m
Copy link

This is something that we've been using internally for a few weeks, and I wanted to suggest it as feature in Pact. This has been useful for setting object IDs in URLs and authentication tokens in the headers; you might not be able to know those values until after the provider state has been set up. After searching through the various pact-foundation repositories, it looks like other people have run into similar needs.

You can create a "provider parameter" by doing:

Pact.provider_param("/users/:{user_id}/posts", user_id: '1')

When the test is run on the consumer side, the URL will be /users/1/posts.

On the provider side, in your provider state, you can do this:

user = User.create!
provider_param :user_id, user.id

Let's say that user.id wasn't 1, but that it actually got assigned 2. When you run rake pact:verify, the URL will be /users/2/posts.

This is also useful with authentication tokens or UUIDs, where they are randomly generated and you have no way of knowing a valid one without knowing something about the provider state beforehand.

Allow values in the request to be changed by the provider state.
Ensure that strings with a provider param variable at the beginning
still get parsed correctly.
Refactor find_default_values so that it doesn't have as many loops in
one method. Also using three dots instead of two for ranges, so that
one doesn't need to be subtracted from the last index.
@YOU54F
Copy link
Member

YOU54F commented Aug 14, 2024

Will be revisiting this as part of pact-foundation/pact-ruby#319

it relates to the ProviderState Generator in version 4 of the pact-spec

https://github.com/pact-foundation/pact-specification/tree/version-4?tab=readme-ov-file#supported-generators

As shown in use in pact-js consumer facing DSL here

https://github.com/pact-foundation/pact-js/blob/master/docs/matching.md#provider-state-injected-values

Note: I need to test what happens in the rust core with the generator rule written in v2/v3 spec, as to what happens on the verification side.

@YOU54F YOU54F marked this pull request as draft August 14, 2024 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants