Using a simple animal dating API, we demonstrate the following Pact features:
- Consumer testing and pact file generation, including advanced features like:
- Sharing Pacts by publishing to and retrieving from a Pact Broker
- Provider side verification
This comprises a complete E2E example that can be used as a basis for projects.
- The Example Project
- Running the tests
- Running the API
- Viewing contracts with the Pact Broker
- Running with Vagrant
[Matching API] -> [Profile API]+(DB)
Provides Animal profile information, including interests, zoo location and other personal details.
Given an animal profile, recommends a suitable partner based on similar interests.
npm installnpm run test:consumer- Run consumer testsnpm run test:publish- Publish contracts to the brokernpm run test:provider- Run provider tests
If you want to experiment with the API to get an understanding:
npm run api- Runs the both provider and consumer API
or individually :
npm run provider- Runs the provider API (animal service)npm run consumer- Runs the consumer API (matching service)
The APIs are described below, including a bunch of cURL statements to invoke them. There is also a Postman Collection.
curl -X GET "http://localhost:8081/animals"
curl -X GET "http://localhost:8081/animals/1"
curl -X GET http://localhost:8081/animals/available
curl -X POST -H "Content-Type: application/json" -d '{
"first_name": "aoeu",
"last_name": "aoeu",
"age": 21,
"gender": "M",
"location": {
"description": "Melbourne Zoo",
"country": "Australia",
"post_code": 3000
},
"eligibility": {
"available": true,
"previously_married": false
},
"interests": [
"walks in the garden/meadow",
"munching on a paddock bomb",
"parkour"
]
}' "http://localhost:8081/animals"
curl -X GET http://localhost:8080/suggestions/1
A test Pact Boker is running at https://test.pact.dius.com.au:
- Username:
dXfltyFMgNOFZAxr8io9wJ37iUpY42M - Password:
O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1
Or use the API:
curl -v -u 'dXfltyFMgNOFZAxr8io9wJ37iUpY42M:O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1' https://test.pact.dius.com.au
We have created a Vagrantfile to be able to test out the project in an isolated and repeatable way.
vagrant up
vagrant ssh
cd /vagrant
npm i
npm run test:consumer
npm run test:provider