https://pact.io logo
#general
Title
# general
j

James P

02/09/2022, 11:02 AM
Hi, I wanted advice on the best approach for using Pact when you require pre-requisite data. For example, I want to test a success response structure for Service A, but in order to trigger that response I would need to hit multiple endpoints on Service B in order to create data to be utilised by Service A to give a success response. What is the approach here? Do you add setup api calls to run before the pact test to generate the required data? or do you do something in the provider like stubbing out a datasource?
m

Matt (pactflow.io / pact-js / pact-go)

02/09/2022, 11:19 AM
Yes, the equivalent in pact is called “provider states”
the consumer says “given User A exists A request to get User a (at path
/users/a
should return a
200
with a
{..}
etc.”
the provider then is responsible for ensuring “User A exists” before the tests run. How that happens is language specific, but basically there is a state hook that fires before the specific test is executed and the provider can do what it needs (seed a database, stub a call etc.)
5 Views