By Manassarn Manoonchai (Noom)
By Manassarn Manoonchai (Noom)
A specification of what data Consumer request and get from the Provider
When consumer calls GET /api/promotions, the Provider would return JSON with array of promotions
The contract looks just like how we mock HTTP request with Nock
, then what’s the difference?
nock('http://www.example.com') .get('/api/promotions') .reply(200, { promotions: [{ ... }] })
nock('http://www.example.com') .get('/api/promotions') .reply(200, { promotions: [{ ... }] })
When mocking requests, we tend to use it for 3rd party APIs, we don’t care how the endpoint will behave if we send data like query strings, since we don’t have any control of them.
But since we are building both of the services calling each other (Consumer & Provider) the Contract works on both sides:
Provider -> "Provider-driven Contract Testing"
Consumer -> "Consumer-driven Contract Testing"
Write unit/integration tests with Pact mocks
Write unit/integration tests with Pact mocks
Interaction
Write unit/integration tests with Pact mocks
Run the contract test
Share the contract
pact_broker
(Free), Pactflow (Paid)Get the contract
Success
means that the contract test on Consumer version X and Provider version Y is passed and is safe to be deployedcan-i-deploy
CLI tool on CI to check the status against consumer & provider version Slides made with Slidev
View the slides @ https://contract-testing-with-pact-and-pactflow.vercel.app