Skip to content

Commit

Permalink
feat: add README
Browse files Browse the repository at this point in the history
  • Loading branch information
iannsantos committed Jun 8, 2020
1 parent 06645cf commit ac9e1b5
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 35 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# PACT - Node

A simple Node project implementing Pact to integration tests.

## Tools

- Express
- Typescript
- Jest
- Pact

## Pact Concept

Pact is a code-first tool for testing HTTP and message integrations using contract tests. Contract tests assert that inter-application messages conform to a shared understanding that is documented in a contract. Without contract testing, the only way to ensure that applications will work correctly together is by using expensive and brittle integration tests.

Do you set your house on fire to test your smoke alarm? No, you test the contract it holds with your ears by using the testing button. Pact provides that testing button for your code, allowing you to safely confirm that your applications will work together without having to deploy the world first.

## Getting started

1. Clone the project on your machine.

```shell
git clone https://github.com/iannsantos/pact-node
```

2. Go to directories `account-api` and `client-api` and execute `yarn install` (or `npm install`) to install necessary packages.
3. Go to directory `infrastructure` with `docker-compose.yml` for up Postgres and Pact Broker containers.

```shell
docker-compose up
```

4. To start with tests, go to `client-api` directory and execute `yarn test ; yarn pact:publish` to generate Pact Contract and publish it on Pact Broker. To view this result, go to `http://localhost`, you should see something like this:

<img src="images/new-pact-contract.png" alt="new pact contract"/>

Also you'll see the Pact contract JSON file on `client-api/pacts`.

5. And to validate the generated contract, go to `account-api` and execute `yarn test`, this will run verifier Pact contract and publish the result on Pact Broker. To see, go again to `http://localhost` and you should see something like this:

<img src="images/validated-pact-contract.png" alt="new pact contract"/>

## Links

- How to Pact works: https://docs.pact.io/how-pact-works#slide-1
- Pact Documentation: https://docs.pact.io/
- Pact Flow: https://pactflow.io/
- Pact Broker: https://github.com/pact-foundation/pact_broker
- POC with Java: https://github.com/vinirib/zup-pact-workshop
26 changes: 0 additions & 26 deletions client-api/infrastructure/docker-compose.yml

This file was deleted.

18 changes: 9 additions & 9 deletions client-api/logs/pact.log
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
I, [2020-06-08T16:27:40.747854 #72346] INFO -- : Registered expected interaction GET /balance/1
D, [2020-06-08T16:27:40.748158 #72346] DEBUG -- : {
I, [2020-06-08T18:23:47.117649 #92963] INFO -- : Registered expected interaction GET /balance/1
D, [2020-06-08T18:23:47.117904 #92963] DEBUG -- : {
"description": "a request for account",
"providerState": "one client with your account",
"request": {
Expand All @@ -19,8 +19,8 @@ D, [2020-06-08T16:27:40.748158 #72346] DEBUG -- : {
},
"metadata": null
}
I, [2020-06-08T16:27:40.750413 #72346] INFO -- : Received request GET /balance/1
D, [2020-06-08T16:27:40.750535 #72346] DEBUG -- : {
I, [2020-06-08T18:23:47.119954 #92963] INFO -- : Received request GET /balance/1
D, [2020-06-08T18:23:47.120081 #92963] DEBUG -- : {
"path": "/balance/1",
"query": "",
"method": "get",
Expand All @@ -32,8 +32,8 @@ D, [2020-06-08T16:27:40.750535 #72346] DEBUG -- : {
"Version": "HTTP/1.1"
}
}
I, [2020-06-08T16:27:40.750789 #72346] INFO -- : Found matching response for GET /balance/1
D, [2020-06-08T16:27:40.750876 #72346] DEBUG -- : {
I, [2020-06-08T18:23:47.120359 #92963] INFO -- : Found matching response for GET /balance/1
D, [2020-06-08T18:23:47.120469 #92963] DEBUG -- : {
"status": 200,
"headers": {
"Content-Type": "application/json; charset=utf-8"
Expand All @@ -44,6 +44,6 @@ D, [2020-06-08T16:27:40.750876 #72346] DEBUG -- : {
"balance": 100
}
}
I, [2020-06-08T16:27:40.756292 #72346] INFO -- : Verifying - interactions matched
I, [2020-06-08T16:27:40.761010 #72346] INFO -- : Cleared interactions
I, [2020-06-08T16:27:40.765737 #72346] INFO -- : Writing pact for AccountApi to /home/iann/dev/pact-node/client-api/pacts/clientapi-accountapi.json
I, [2020-06-08T18:23:47.124950 #92963] INFO -- : Verifying - interactions matched
I, [2020-06-08T18:23:47.127843 #92963] INFO -- : Cleared interactions
I, [2020-06-08T18:23:47.131515 #92963] INFO -- : Writing pact for AccountApi to /home/iann/dev/pact-node/client-api/pacts/clientapi-accountapi.json
Binary file added images/new-pact-contract.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/validated-pact-contract.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ac9e1b5

Please sign in to comment.