pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

How to mock different for different interaction #1468

Open charlenew opened 2 years ago

charlenew commented 2 years ago

https://docs.pact.io/implementation_guides/jvm/provider/spring/#example-of-mockmvc-test

I have similar implementation based on this doc, however, I am using json format, how I can mention state in json and when different interaction I want to mock differently. can you provide some example?

{ "provider": { "name": "84657-slot-pact-provider" }, "consumer": { "name": "84657-slot-pact-consumer" }, "interactions": [ { "description": "publish event to provider", "request": { "method": "POST", "path": "/notifications", "headers": { "Content-Type": "application/json", "request-id": "test", "user-id":"q7persona0649256552" }, "body": { "eventCode": "2910" } }, "response": { "status": 200 } }, { "description": "publish bad event to provider", "request": { "method": "POST", "path": "/notifications", "headers": { "Content-Type": "application/json", "user-id" : "testUser" }, "body": {"type": 2910, "retryRequestIndicator": true } }, "response": { "status": 400 } } ], "metadata": { "pactSpecification": { "version": "3.0.0" }, "pact-jvm": { "version": "4.0.7" } } }

joeltheunknown commented 2 years ago

Building off of this question, what's the approach to take to test server/service errors like 500 or 503?