# @workcast-org/event-bridge-test-helper

> ## Requirements

Latest version **1.0.1** (published 2022-03-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @workcast-org/event-bridge-test-helper
pnpm add @workcast-org/event-bridge-test-helper
yarn add @workcast-org/event-bridge-test-helper
bun add @workcast-org/event-bridge-test-helper
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-03-25 |
| First published | 2022-03-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | WorkCast |
| Maintainers | adam.mellor, leenattressworkcast |

## Links

- npm: https://www.npmjs.com/package/@workcast-org/event-bridge-test-helper
- npm.io page: https://npm.io/package/@workcast-org/event-bridge-test-helper

## Dependencies (4)

- [@aws-sdk/client-sqs](https://npm.io/package/@aws-sdk/client-sqs.md) ^3.55.0
- [@aws-sdk/client-sts](https://npm.io/package/@aws-sdk/client-sts.md) ^3.55.0
- [@aws-sdk/client-eventbridge](https://npm.io/package/@aws-sdk/client-eventbridge.md) ^3.55.0
- [@aws-sdk/credential-providers](https://npm.io/package/@aws-sdk/credential-providers.md) ^3.55.0

## Recent versions

- 1.0.1 (latest) — 2022-03-25
- 1.0.0 — 2022-03-25

## README

![workcast header](https://info.workcast.com/hs-fs/hubfs/2021%20-%20Logos/workcast_logo_orange-100.png?width=120&name=workcast_logo_orange-100.png)

<h1 align="center">⚡ WorkCast EventBridge Test Helper</h1>
<p>
  <img alt="Version" src="https://img.shields.io/badge/version-1.0.0-blue.svg?cacheSeconds=2592000" />
  <a href="#" target="_blank">
    <img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" />
  </a>
  <a href="https://twitter.com/WorkCast" target="_blank">
    <img alt="Twitter: WorkCast" src="https://img.shields.io/twitter/follow/WorkCast.svg?style=social" />
  </a>
</p>

> The `EventBridge Test Helper` is a helper service that can be included in any javascript tests. The helper allows the tests to set up an architecture in the cloud that allows us to test our stacks from event in to event out.

### 🏠 [WorkCast Homepage](https://info.workcast.com/)

## Requirements

* AWS Account with the ability to:
    * Put Events
    * Create a SQS Queue
    * Create an Rule
    * Create an Event Target

## Installation
NPM:
```
npm install @workcast-org/event-bridge-test-helper
```

Yarn:
```
yarn add @workcast-org/event-bridge-test-helper
```

## Usage
The usage examples include the addition on an env file, this is a json/javascript file that contains the following:
* The stage that we are testing e.g ote. This is used to construct the eventbridge name.
* The region that the service is in that we are testing.

In your tests import the library:
``` javascript
const { eventTestingClient } = require('event-bridge-test-helper');
```

Create a client passing in the required values:
``` javascript
// This prefix allows us to track events made during this test cycle
let correlationPrefix = "integration-tests";
const helperClient = eventTestingClient({
  serviceName: "XXX",
  serviceSource: "com.workcast.XXX",
  correlationPrefix: correlationPrefix,
  busName: `eventbridge-${env.Testing.STAGE_NAME}`, // The event bus name that the service is attached to 
  region: env.Testing.REGION
});
```
For more information on the client inputs, the code is documented

Before and after your test you need to spin up the testing architecture:
``` javascript
before(async () => {
  await helperClient.createTestArchitecture();
});

after(async () => {
  await helperClient.destroyTestArchitecture();
});
```

In the test, construct your event how you expect the rule to fire and call teh fire event function:
``` javascript
await helperClient.fireEvent(request);
```

Immediately following firing the event you can then run the following to check for resultant messages:
``` javascript
const raisedEvents = await helperClient.getMessagesFromSQS();
```
If you have multiple events you can call this multiple times.

It's possible to increase the number of messages received but that can be funky, its better to get them one at a time from the queue

## Author

👤 **WorkCast**

* Website: www.workcast.com
* Twitter: [@WorkCast](https://twitter.com/WorkCast)
* Github: [@The-WorkCast-Corporation](https://github.com/The-WorkCast-Corporation)
* LinkedIn: [@workcast](https://www.linkedin.com/company/workcast/)

## Show your support

Give a ⭐️ if this project helped you!

---
_Source: https://npm.io/package/@workcast-org/event-bridge-test-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
