An open API service indexing awesome lists of open source software.

https://github.com/pactflow/example-consumer

An example of a consumer that uses Pact+PactFlow to create a consumer driven contract with its provider
https://github.com/pactflow/example-consumer

example

Last synced: 8 months ago
JSON representation

An example of a consumer that uses Pact+PactFlow to create a consumer driven contract with its provider

Awesome Lists containing this project

README

          

# Example Consumer

[![Build](https://github.com/pactflow/example-consumer/actions/workflows/build.yml/badge.svg)](https://github.com/pactflow/example-consumer/actions/workflows/build.yml)

[![Pact Status](https://test.pactflow.io/pacts/provider/pactflow-example-provider/consumer/pactflow-example-consumer/latest/badge.svg?label=provider)](https://test.pactflow.io/pacts/provider/pactflow-example-provider/consumer/pactflow-example-consumer/latest) (latest pact)

[![Can I deploy Status](https://test.pactflow.io/pacticipants/pactflow-example-consumer/branches/master/latest-version/can-i-deploy/to-environment/production/badge)](https://test.pactflow.io/pacticipants/pactflow-example-consumer/branches/master/latest-version/can-i-deploy/to-environment/production/badge)

This is an example of a Node consumer using Pact to create a consumer driven contract, and sharing it via [PactFlow](https://pactflow.io).

It is using a public tenant on PactFlow, which you can access [here](https://test.pactflow.io/) using the credentials `dXfltyFMgNOFZAxr8io9wJ37iUpY42M`/`O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`. The latest version of the Example Consumer/Example Provider pact is published [here](https://test.pactflow.io/pacts/provider/pactflow-example-provider/consumer/pactflow-example-consumer/latest).

The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy.

* Test
* Run tests (including the pact tests that generate the contract)
* Publish pacts, associating the consumer version with the name of the current branch
* Check if we are safe to deploy to prod (ie. has the pact content been successfully verified)
* Deploy (only from master)
* Deploy app (just pretend for the purposes of this example!)
* Record the deployment in the Pact Broker

## Usage

See the [PactFlow CI/CD Workshop](https://github.com/pactflow/ci-cd-workshop).

## Running the application

Start up the [provider](https://github.com/pactflow/example-provider/) (or another [compatible](https://docs.pactflow.io/docs/examples) provider) API by running `npm run start`.

Open a separate terminal for the consumer.

Before starting the consumer, create a `.env` file in the root of the project and set the URL to point to your running provider:

```bash
REACT_APP_API_BASE_URL=http://localhost:8080
```

Then run:

```bash
npm run start
```

### Pre-requisites

**Software**:

* Tools listed at: https://docs.pactflow.io/docs/workshops/ci-cd/set-up-ci/prerequisites/
* A pactflow.io account with an valid [API token](https://docs.pactflow.io/#configuring-your-api-token)

#### Environment variables

To be able to run some of the commands locally, you will need to export the following environment variables into your shell:

* `PACT_BROKER_TOKEN`: a valid [API token](https://docs.pactflow.io/#configuring-your-api-token) for PactFlow
* `PACT_BROKER_BASE_URL`: a fully qualified domain name with protocol to your pact broker e.g. https://testdemo.pactflow.io

### Usage

#### Pact use case

* `make test` - run the pact test locally
* `make fake_ci` - run the CI process locally