contract-tests

1.0.0 • Public • Published

Pact JS End-to-End Example

Using a simple animal dating API, we demonstrate the following Pact features:

This comprises a complete E2E example that can be used as a basis for projects.

The Example Project

[Matching API] -> [Profile API]+(DB)

Provider (Profile API)

Provides Animal profile information, including interests, zoo location and other personal details.

Consumer (Matching API)

Given an animal profile, recommends a suitable partner based on similar interests.

Running the tests

  1. npm install
  2. npm test:consumer - Run consumer tests
  3. npm test:publish - Publish contracts to the broker
  4. npm test:provider - Run provider tests

Running the API

If you want to experiment with the API to get an understanding:

  1. npm run api - Runs the both provider and consumer API

or individually :

  1. npm run provider - Runs the provider API (animal service)
  2. npm run consumer - Runs the consumer API (matching service)

Animal Profile API

The APIs are described below, including a bunch of cURL statements to invoke them. There is also a Postman Collection.

GET /animals

curl -X GET "http://localhost:8081/animals"

GET /animals/:id

curl -X GET "http://localhost:8081/animals/1"

GET /animals/available

curl -X GET http://localhost:8081/animals/available

POST /animals

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"

Matching service

GET /suggestions/:id

curl -X GET http://localhost:8080/suggestions/1

Viewing contracts with the Pact Broker

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

Readme

Keywords

none

Package Sidebar

Install

npm i contract-tests

Weekly Downloads

2

Version

1.0.0

License

none

Last publish

Collaborators

  • scott.roberts