https://pact.io logo
#pact-js
Title
# pact-js
m

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

03/02/2022, 12:25 AM
Provider states are usually how you handle different scenario data needs
p

Peter Pinda

03/02/2022, 12:45 AM
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

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

03/02/2022, 12:48 AM
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

Slackbot

03/02/2022, 12:48 AM
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

Peter Pinda

03/02/2022, 1:11 AM
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

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

03/02/2022, 1:22 AM
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

Peter Pinda

03/02/2022, 2:02 AM
@Matt (pactflow.io / pact-js / pact-go) Appreciate you advice, thank you!
m

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

03/02/2022, 2:06 AM
👍