- Notifications
You must be signed in to change notification settings - Fork2
This is a sample project to demonstrate consumer driven contract testing using the PACT framework and TypeScript.
License
amalsgit/typescript_pact_contract_test
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a sample project to demonstrate consumer driven contract testing using the PACT framework and TypeScript.
This repo consists of aprovider service and aconsumer service. The interactions between these 2 services will be tested used PACT.
Theprovider service which is responsible for CRUD-ing & maintaining a movie database and theconsumer service makes use of the APIs exposed by theprovider to do further operations.
├── README.md├── consumer # consumer service│ ├── jest.config.js # Jest test configurations│ ├── logs # Logs generated by pact for debugging issues│ │ └── pact.log│ ├── package.json│ ├── src│ │ ├── actions.ts # Contains application business logic│ └── └── pacts └── movies.contract.test.ts # Contains the consumer contract tests├── contracts│ └── movie_consumer-movie_producer.json # Generated PACT contract└── provider # provider service ├── jest.config.js # Jest test configurations ├── package.json ├── pacts │ └── movies.contract.test.ts # Contains the provider contract tests ├── src │ ├── actions.ts # Contains application business logic │ ├── app.ts # Contains the API endpoints │ ├── data # Sqlite Datastore of the service │ ├── entity # TypeORM entities └── └── server.ts # Server initializerThis project is written with Node version v12.18.4
Install node
https://nodejs.org/en/Install yarn
https://classic.yarnpkg.com/en/docs/install#mac-stableGo to the provider directory
cd provider/Run yarn to get all the required libraries
yarnTo run the provider server run
yarn startThis brings up the application athttp://localhost:3001 You can hithttp://localhost:3001/movies to return a list of movies in the system
Go to the consumer directory
cd consumer/Run yarn to get all the required libraries
yarnThe tests require a PACT broker to be running. To start the broker run the below command from the root project directory
docker-compose upThis brings up the broker application as well a PostgreSQL database to store the contracts and verification results.
The broker app can be accessed athttp://localhost:9292/
Go to the consumer directory
cd consumer/Run
yarn testThe above command runs the contract tests and generates the PACT contract file under thecontracts directory
Go to the provider directory
cd provider/Before running the provider test, you need to bring up the provider server. You can do that by running
yarn startOnce the application is up run the tests using
yarn testThe above command picks up the PACT contract file from thecontracts directory which was generated by the consumer contract tests and run the tests against the provider.
The docker pact-cli can be used to perform multiple functions like running the verifications, accessing the broker and also to verify whether the application can be deployed safely.
A sample command to runcan-i-deploy
docker run --rm pactfoundation/pact-cli broker can-i-deploy --pacticipant "Movie Consumer" --latest --broker-base-url http://host.docker.internal:9292https://hub.docker.com/r/pactfoundation/pact-clihttps://hub.docker.com/r/pactfoundation/pact-brokerhttps://github.com/pact-foundation/pact-js
About
This is a sample project to demonstrate consumer driven contract testing using the PACT framework and TypeScript.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.