John Williams
07/04/2022, 11:37 PMTimothy Jones
07/05/2022, 1:08 AMTimothy Jones
07/05/2022, 1:12 AMuserTenExists = () => users.add(10, {/* whatever user properties */})
, because then:
• Your tests use the same language as the domain
• Your tests happen to cover some of the repository logic by virtue of needing it for the provider state setup
• Your tests aren't assuming particular DB state (if you insert arbitrary stuff into the DB, how do you know the arbitrary stuff is the right arbitrary stuff?)John Williams
07/05/2022, 1:12 AMTimothy Jones
07/05/2022, 1:13 AMwe still need to set up a provide state end point in the Provider ?Yes, or the other approach above if it happens to be easier for you (I would do the state change endpoint though)
John Williams
07/05/2022, 1:14 AMTimothy Jones
07/05/2022, 1:14 AMTimothy Jones
07/05/2022, 1:14 AMTimothy Jones
07/05/2022, 1:15 AMGET /users/$userIdFromProvider
, and when it runs on the consumer test you can say "for example, 10"John Williams
07/05/2022, 1:16 AMTimothy Jones
07/05/2022, 1:16 AMGET /users/123
John Williams
07/05/2022, 1:16 AMTimothy Jones
07/05/2022, 1:17 AMwrite the state change endpoint in PHP that twill feed back the consumerNo. The provider state change endpoint never sends anything back to the consumer
Timothy Jones
07/05/2022, 1:17 AMJohn Williams
07/05/2022, 1:17 AMJohn Williams
07/05/2022, 1:18 AMJohn Williams
07/05/2022, 1:18 AMJohn Williams
07/05/2022, 1:18 AMTimothy Jones
07/05/2022, 1:19 AMfromProviderState
bit when mocking the consumer requestTimothy Jones
07/05/2022, 1:19 AMso the contract doesnt know the idCorrect
and neither does the provider before handCorrect But, the provider does know after the state change endpoint has been called. And it can return that info in the response
John Williams
07/05/2022, 1:21 AMdef pact_add_expected_user:
# add the user to the db
# return the user id to pact
John Williams
07/05/2022, 1:24 AMTimothy Jones
07/05/2022, 1:24 AMJohn Williams
07/05/2022, 1:24 AMTimothy Jones
07/05/2022, 1:24 AMJohn Williams
07/05/2022, 1:25 AMTimothy Jones
07/05/2022, 1:25 AMJohn Williams
07/05/2022, 1:25 AMTimothy Jones
07/05/2022, 1:25 AMTimothy Jones
07/05/2022, 1:26 AMJohn Williams
07/05/2022, 1:26 AMJohn Williams
07/05/2022, 1:28 AMTimothy Jones
07/05/2022, 1:32 AMJohn Williams
07/05/2022, 1:32 AMJohn Williams
07/05/2022, 1:33 AMTimothy Jones
07/05/2022, 1:35 AM/**
* Respond to the state setup event, optionally returning a map of provider
* values to dynamically inject into the incoming request to test
*/
Timothy Jones
07/05/2022, 1:37 AMexport interface ProviderState {
action: StateAction;
params: JsonMap;
state: string;
}
/**
* Specifies whether the state handler being setup or shutdown
*/
export type StateAction = 'setup' | 'teardown';
Timothy Jones
07/05/2022, 1:38 AMProviderState
objectTimothy Jones
07/05/2022, 1:38 AMTimothy Jones
07/05/2022, 1:39 AMTimothy Jones
07/05/2022, 1:39 AMJohn Williams
07/05/2022, 2:02 AMTimothy Jones
07/05/2022, 2:13 AMMatt (pactflow.io / pact-js / pact-go)
Matt (pactflow.io / pact-js / pact-go)
John Williams
07/05/2022, 3:33 AMJohn Williams
07/05/2022, 3:34 AMJohn Williams
07/05/2022, 3:41 AMTimothy Jones
07/05/2022, 3:53 AMJohn Williams
07/05/2022, 4:37 AM