This project have the implementation of contract tests (click to know more about) with PactFlow and a PactBroker for sharing Pact contracts and verification results.
You should have docker and docker compose instaled
- Clone the project:
git clone https://github.com/Luryy/Pact-Flow-Implementation.git
cd Pact-Flow-Implementation
- Start the environment:
docker-compose -f docker-compose.pact.yml up
* you should change the host number to your postgres container hash
PACT_BROKER_DATABASE_URL: "postgres://pactuser:docker@**930105e84c8a**/pactpostgres"
- Run the contract tests:
yarn test consumer
yarn test publisher
- Publish your test to your pact broker
yarn pact:publish
Using pact broker:
- Access
http://localhost:9292/
- And you could see your published contract and their verified.
If want to change yours contract tests, see next topic structure.
Here is the project structure:
.
├── node_modules
├── src
│ ├── config
│ │ └── pact.ts
│ ├── consumer
│ │ └── Consumer.pact.ts
│ ├── interfaces
│ │ └── Role.ts
│ ├── pact-doc-example
│ │ ├── ConsumerExample.pact.ts
│ │ └── PublisherExample.pact.ts
│ ├── producer
│ │ └── Producer.pact.ts
│ ├── routes
│ │ └── index.ts
│ ├── scripts
│ │ └── pact-publisher.ts
│ ├── app.ts
│ └── server.ts
├── docker-compose.pact.yml
├── jest.config.ts
├── package.json
├── prettier.config.js
├── README.md
├── tsconfig.json
└── yarn.lock
At pact-doc-example folder we have the contract test implementation as Pacj docs recommend.
At consumer folder contain a more sophisticated consumer pact test, you could only duplicate Consumer.pact.ts to do new tests.
If you want to alter the test behavior, you should change withContent
at test to require your expect data and change the api function to verify if this data is correct.
At producer folder contain a more sophisticated provider pact test, you could only duplicate Provider.pact.ts to do new tests. If you want to alter the test behavior, you should change the api function to send the data expected.
To a better understanding you should open the files and see yours responsabilities - try to modificate then and don't forget to read the docs)!.
👤 Lucas Yuri
- Github: Luryy
- LinkedIn: Lucas Yuri
Copyright © 2020 Lucas Yuri. This project is MIT licensed.