Skip to content

Commit

Permalink
feat: update readmes on provider state injection #1061
Browse files Browse the repository at this point in the history
(cherry picked from commit c509048)
  • Loading branch information
Ronald Holshausen committed Apr 29, 2020
1 parent ab407bc commit 33b67cc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pact-jvm-consumer-groovy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ of where this would be useful is API calls that require an ID which would be aut
provider side, so there is no way to know what the ID would be beforehand.

The DSL method `fromProviderState` allows you to set an expression that will be parsed with the values returned from the provider states.
For the body, you can use the key value instead of an expression.

For example, assume that an API call is made to get the details of a user by ID. A provider state can be defined that
specifies that the user must be exist, but the ID will be created when the user is created. So we can then define an
Expand All @@ -635,7 +636,7 @@ service {
uponReceiving('a request for user harry')
withAttributes(method: 'get', path: fromProviderState('/api/user/${id}', '/api/user/100'))
withBody {
name(~/\w+/, 'harry')
name(fromProviderState('userName', 'harry')) // looks up the value using the userName key
}
}
```
6 changes: 6 additions & 0 deletions pact-jvm-consumer-junit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,9 @@ expression for the path where the ID will be replaced with the value returned fr
```java
.pathFromProviderState("/api/users/${id}", "/api/users/100")
```

You can also just use the key instead of an expression:

```java
.valueFromProviderState('userId', 'userId', 100) // will look value using userId as the key
```
5 changes: 5 additions & 0 deletions pact-jvm-consumer-junit5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,8 @@ expression for the path where the ID will be replaced with the value returned fr
```java
.pathFromProviderState("/api/users/${id}", "/api/users/100")
```
You can also just use the key instead of an expression:

```java
.valueFromProviderState('userId', 'userId', 100) // will look value using userId as the key
```
6 changes: 6 additions & 0 deletions pact-jvm-consumer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,9 @@ expression for the path where the ID will be replaced with the value returned fr
```java
.pathFromProviderState("/api/users/${id}", "/api/users/100")
```

You can also just use the key instead of an expression:

```java
.valueFromProviderState('userId', 'userId', 100) // will look value using userId as the key
```

0 comments on commit 33b67cc

Please sign in to comment.