Hello Team, I have a doubt regarding Provider stat...
# general
s
Hello Team, I have a doubt regarding Provider state. As a consumer I want certain specific value to be returned from provider. Say I am consuming a field "RuleId" and I want provider to return "Rule-123". As a provider - I am supposed to hit the real running service and match the response with pact response. But to achieve my scenario, should I use Provider state and mock the response to return "Rule-123" ? Similarly for error scenarios - should I create mock response for each error scenario ? I might be wrong here, but I am confused like if I mock any response, then I am not validating real response but mock response. Kindly help to understand how provider side should be setup to achieve these scenarios mentioned above
t
You should use provider states to mock something deeper in your service (like the data / repository layer), so that your response is really what your provider will return
But to achieve my scenario, should I use Provider state and mock the response to return “Rule-123” ?
This is partly what the matchers are for. You might have a request for a rule with
ruleId: "Rule-123"
. You could alleviate the requirement on mock data with:
Copy code
{
  ruleId: "Rule-123",
  title: Matchers.string("Rule title")
}
This says the
ruleId
must be
Rule-123
, but you’ll accept any string for the title during verification.
Basically you use the matchers to say “I promise you anything that passes this matcher is covered by this test case”.
s
Thanks Timothy for response. "You should use provider states to mock something deeper in your service (like the data / repository layer)" - Can you elaborate a bit on this one? If say "Rule-123" is coming from DB, I should insert that data beforehand in the DB and clear it after the test ? Or I can use Mokito and based on condition reply with appropriate response?