Skip to content

Commit

Permalink
refactor(names): change the name of the producer module to provider (#6)
Browse files Browse the repository at this point in the history
* refactor(names): change the name of the producer module to provider

Change the name of 'ProducerModule' to 'ProviderModule'

BREAKING CHANGE: 'ProducerModule' is now 'ProviderModule';

* docs(readme): add some links to pact and correct some mistakes

* docs(readme): change logo sizes and markup
  • Loading branch information
omermorad authored Feb 2, 2021
1 parent 7fd3929 commit fdf1af1
Show file tree
Hide file tree
Showing 13 changed files with 644 additions and 271 deletions.
58 changes: 25 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,41 @@
[![CircleCI](https://circleci.com/gh/omermorad/nestjs-pact.svg?style=shield)](https://circleci.com/gh/circleci/circleci-docs)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

![alt text](logo.jpg "NestJS + Pact")

<p align="center">
<img src="logo.jpg" alt="NestJS + Pact Logo" width="500" />

<h3 align="center">
NestJS + Pact
</h3>

<p align="center">
<strong>Injectable Pact.js Consumer/Producer for NestJS</strong>
<strong>Injectable Pact.js Consumer/Provider for NestJS</strong>
</p>
</p>

## Table Of Contents

- [About](#about)
- [Installation](#installation)
- [Installation](#end-to-end-example)
- [About](#about)
- [Introduction](#introduction)
- [Getting Started](#getting-started)
- [Contributing](#contributing)
- [License](#license)
- [Acknowledgements](#acknowledgements)


## Installation

```bash
npm i -D nestjs-pact @pact-foundation/pact
```

## End to End Example
If you want to see a fully working end-to-end example with NestJS and Pact I recommend you to
[jump to the NestJS official examples at the PactJS Github repository](https://github.com/pact-foundation/pact-js/tree/master/examples)

## About

This package enables you to consume Pact.js in a way that can be used very easily in NestJS. \
Expand All @@ -34,14 +47,8 @@ Like the nature of Pact, this package is for testing purposes only.
If you are not familiar with Pact, Pact is fast, easy and reliable testing framework for integrating web apps, APIs and microservices.
Read more on [Pact official website](https://pact.io/)

There are two main modules suggested; one for the `Producer` role (`Verifier`), and one for the `Consumer` role (creating Pact files and publish), each loaded separately.
Of course you can also use both modules and play the role of `Consumer` and `Producer` at the same time.

## Installation

```bash
npm i -D nestjs-pact
```
There are two main modules suggested; one for the `Provider` role (`Verifier`), and one for the `Consumer` role (creating Pact files and publish), each loaded separately.
Of course you can also use both modules and play the role of `Consumer` and `Provider` at the same time.

## Introduction

Expand Down Expand Up @@ -100,7 +107,7 @@ describe('Pact', () => {

provider = pactFactory.createContractBetween({
consumer: 'Consumer Service Name',
provider: 'Producer Service Name',
provider: 'Provider Service Name',
});

await provider.setup();
Expand All @@ -122,8 +129,6 @@ describe('Pact', () => {
});
```

If you are not sure how to write the test itself, [the great end-to-end example from Pact's Github](https://github.com/pact-foundation/pact-js/tree/master/examples/e2e) would surely help!

Now let's look how we can publish the pacts created from the test file to a Pact broker!

**test/pact/publish-pacts.ts**
Expand Down Expand Up @@ -167,13 +172,13 @@ Run the file and you are good to go :)

Note: in your `tsconfig.json` file make sure you set `allowJs` to `true` in order to run the file

### Producer
### Provider

The usage in the `Producer` service is quite easy; In your `/test` folder (or wherever you put your tests)
create a simple test module with NestJS `Test.createTestingModule` method and import the `PactProducerModule` module
The usage in the `Provider` service is quite easy; In your `/test` folder (or wherever you put your tests)
create a simple test module with NestJS `Test.createTestingModule` method and import the `PactProviderModule` module
from `nestjs-pact`.

You can use `register` or `registerAsync` method, make sure you stick to `PactProducerOptions` interface options. \
You can use `register` or `registerAsync` method, make sure you stick to `PactProviderOptions` interface options. \
After creating the Nest application from the testing module, pass the app instance to the `verify` method,
it will generate a random (available) port, spin up the application and run the verifier against the application url.

Expand All @@ -184,7 +189,7 @@ Here is a quick and simple example:
```typescript
import { Test } from '@nestjs/testing';
import { INestApplication, Logger, LoggerService } from '@nestjs/common';
import { PactProducerModule, PactVerifierService } from 'nestjs-pact';
import { PactProviderModule, PactVerifierService } from 'nestjs-pact';
import { AppModule } from '@app/app.module';

describe('Pact Verification', () => {
Expand All @@ -194,7 +199,7 @@ describe('Pact Verification', () => {

beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [AppModule, PactProducerModule.register({ ... })],
imports: [AppModule, PactProviderModule.register({ ... })],
}).compile();

verifierService = moduleRef.get(PactVerifierService);
Expand All @@ -218,19 +223,6 @@ describe('Pact Verification', () => {
});
```

## Contributing

If you want to contribute to the project, I will be more than happy :) \
Take a few minutes to review the project code, and start get your hands dirty.

It is important to note the following steps beforehand:

1. Fork the repository
2. Create your branch in the form of `<bug|feature>/<semver-path>/<description>` (`git checkout -b feature/minor/add-something`)
3. Commit the changes to your branch
4. Push your changes to your remote branch
5. Open a pull request

## License

Distributed under the MIT License. See `LICENSE` for more information.
Expand Down
Loading

0 comments on commit fdf1af1

Please sign in to comment.