Provider states are usually how you handle differe...
# pact-js
m
Provider states are usually how you handle different scenario data needs
p
Thanks @Matt (pactflow.io / pact-js / pact-go) jumping into my issue... when we run:pact test on provider site, we spin the nextjs app module, create SQLighte db with data.Than Provider gets 2 contracts from PactFlow (based on selectors), first contract finds and deletes record in DB which passes ok, but for second which has same interactions, record is not found because first contact deleted it... If there is a way I can reset a DB between first and second contract I will probably solve my problem... PS: sorry tricky to explain
m
yes, you use provider states to specify “thing exists” or “thing does not exist” which triggers a provider state hook to fire. In htat hook (a JS function) you can manipulate the state of the interaction
see the e2e example in the Pact JS repository for a good example, or the JS workshop step 👇 (howtolearn)
s
Here are a number of useful hands-on labs that teach all of the key concepts: https://docs.pactflow.io/docs/workshops and https://docs.pact.io/implementation_guides/workshops
p
hmm, for now we are using states for 2 users... like:
Copy code
stateHandlers: {
        'Agent login': async () => {
          token = getToken(jwtAgentData);
        },
        'Vendor login': async () => {
          token = getToken(jwtVendorData);
        },
      },
and on the consumer
given('Agent login')
... Is there any way we can pass multiple states...lie
given(['Agent login', 'Clear some data'])
?
m
Have a look at the docks there's a pre hook and post test hook. Personally I would just clear out the state for every provider state anyway so you always have a clean slate to begin with
👍 1
p
@Matt (pactflow.io / pact-js / pact-go) Appreciate you advice, thank you!
m
👍