Skip to content

Commit

Permalink
chore(docs): improve message pact docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Apr 1, 2018
1 parent ce31f31 commit 5709a20
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ how to get going.
- [Asynchronous API Testing](#asynchronous-api-testing)
- [Consumer](#consumer)
- [Provider (Producer)](#provider-producer)
- [Pact Broker Integration](#pact-broker-integration)
- [Matching](#matching)
- [Match common formats](#match-common-formats)
- [Match based on type](#match-based-on-type)
- [Match based on arrays](#match-based-on-arrays)
- [Match by regular expression](#match-by-regular-expression)
- [Tutorial (60 minutes)](#tutorial-60-minutes)
- [Examples](#examples)
- [HTTP APIs](#http-apis)
- [Asynchronous APIs](#asynchronous-apis)
- [Using Pact in non-Node environments](#using-pact-in-non-node-environments)
- [Using Pact with Karma](#using-pact-with-karma)
- [Using Pact with RequireJS](#using-pact-with-requirejs)
Expand Down Expand Up @@ -437,7 +440,7 @@ The following test creates a contract for a Dog API handler:
1. Creates the MessageConsumer class
1. Setup the expectations for the consumer - here we expect a `dog` object with three fields
1. Pact will send the message to your message handler. If the handler returns a successful promise, the message is saved, otherwise the test fails. There are a few key things to consider:
* The actual request body that Pact will send, will be contained within a [Message](/Users/mfellows/development/public/pact-js/src/dsl/message.ts) object along with other context, so the body must be retrieved via `content` attribute.
* The actual request body that Pact will send, will be contained within a [Message](https://github.com/pact-foundation/pact-js/tree/feat/message-pact/src/dsl/message.ts) object along with other context, so the body must be retrieved via `content` attribute.
* All handlers to be tested must be of the shape `(m: Message) => Promise<any>` - that is, they must accept a `Message` and return a `Promise`. This is how we get around all of the various protocols, and will often require a lightweight adapter function to convert it.
* In this case, we wrap the actual dogApiHandler with a convenience function `synchronousBodyHandler` provided by Pact, which Promisifies the handler and extracts the contents.

Expand Down Expand Up @@ -492,6 +495,10 @@ describe("Message provider tests", () => {
* Similar to the Consumer tests, we map the various interactions that are going to be verified as denoted by their `description` field. In this case, `a request for a dog`, maps to the `createDog` handler. Notice how this matches the original Consumer test.
1. We can now run the verification process. Pact will read all of the interactions specified by its consumer, and invoke each function that is responsible for generating that message.

### Pact Broker Integration

As per HTTP APIs, you can [publish contracts and verification results to a Broker](#publishing-pacts-to-a-broker).

## Matching

Matching makes your tests more expressive making your tests less brittle.
Expand Down Expand Up @@ -654,14 +661,20 @@ Learn everything in Pact JS in 60 minutes: https://github.com/DiUS/pact-workshop

## Examples

### HTTP APIs

* [Complete Example (Node env)](https://github.com/pact-foundation/pact-js/tree/master/examples/e2e)
* [Pact with AVA (Node env)](https://github.com/pact-foundation/pact-js/tree/master/examples/ava)
* [Pact with Jest (Node env)](https://github.com/pact-foundation/pact-js/tree/master/examples/jest)
* [Pact with TypeScript + Mocha](https://github.com/pact-foundation/pact-js/tree/master/examples/typescript)
* [Pact with Mocha](https://github.com/pact-foundation/pact-js/tree/master/examples/mocha)
* [Pact with Karma + Jasmine](https://github.com/pact-foundation/pact-js/tree/master/karma/jasmine)
* [Pact with Karma + Mocha](https://github.com/pact-foundation/pact-js/tree/master/karma/mocha)
* [Asynchronous messages](https://github.com/pact-foundation/pact-js/tree/master/examples/messages)

### Asynchronous APIs

* [Asynchronous messages](https://github.com/pact-foundation/pact-js/tree/feat/message-pact/examples/messages)
* [Serverless](https://github.com/pact-foundation/pact-js/tree/feat/message-pact/examples/serverless)

[![asciicast](https://asciinema.org/a/105793.png)](https://asciinema.org/a/105793)

Expand Down
32 changes: 22 additions & 10 deletions examples/serverless/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![serverless-logo](https://user-images.githubusercontent.com/53900/38163394-57ec9176-353f-11e8-80d1-b9f6d5f1773f.png)

Fictional application running using the [Serverless](https://github.com/serverless/serverless) framework.
Sample contract testing application running using the [Serverless](https://github.com/serverless/serverless) framework.

The very basic architecture is as follows:

Expand Down Expand Up @@ -49,28 +49,40 @@ Or individually:

```
npm run test:consumer
npm run test:publish # publish contracts to the broker
npm run test:provider
```

## Deployment

You can run this stack in AWS. It uses services within the [free tier](https://aws.amazon.com/free/?awsf.default=categories%23alwaysfree) to reduce potential costs.

To use any of the commandsn belowe, ensure you have valid [AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) for your environment.

Serverless
To use any of the commands below, ensure you have valid [AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) for your environment.

### Pact Broker integration

Using the test broker at https://test.pact.dius.com.au (user/pass: `dXfltyFMgNOFZAxr8io9wJ37iUpY42M` / `O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`), we integrate the `can-i-deploy` facility, that ensure it is safe to deploy the consumer or provider before a change.
Using the test broker at https://test.pact.dius.com.au (user/pass: `dXfltyFMgNOFZAxr8io9wJ37iUpY42M` / `O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`), we make use of the [`can-i-deploy` tool](https://github.com/pact-foundation/pact_broker/wiki/Provider-verification-results#querying) (available from the [Pact CLI suite](https://github.com/pact-foundation/pact-ruby-standalone/releases) but also bundled as part of `pact`), that ensures it is safe to deploy the consumer or provider before a releasing a change.

Whenever we verify a contract with Pact, the results are shared with the broker, which is able to determine compatibility between components.
Whenever we create, change or verify a contract with Pact, the results are shared with the broker, which is then able to determine compatibility between components at any point in time.

You can see the current state of verification by running one of:
You can see this in action by running one of the following:

```sh
npm run can-i-deploy # For both
npm run can-i-deploy:consumer # Just consumer
npm run can-i-deploy:provider # Yep, just the provider
```
npm run can-i-deploy:consumer
npm run can-i-deploy:provider

You will see something like:

```sh
Computer says yes \o/

CONSUMER | C.VERSION | PROVIDER | P.VERSION | SUCCESS?
---------------------|-----------|----------------------|-----------|---------
SNSPactEventConsumer | 1.0.1 | SNSPactEventProvider | 1.0.0 | true

All verification results are published and successful
```

### Running deployment
Expand All @@ -81,7 +93,7 @@ npm run deploy

This will first check with `can-i-deploy`. If you want to skip this process, you can simply run:

```
```sh
serverless deploy -f provider
serverless deploy -f consumer
```
Expand Down
Binary file removed examples/serverless/serverless-logo.png
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pact-foundation/pact",
"version": "6.0.0-alpha.2",
"version": "6.0.0-alpha.3",
"description": "Pact for all things Javascript",
"main": "./pact.js",
"types": "./pact.d.ts",
Expand Down

0 comments on commit 5709a20

Please sign in to comment.