# bus-expectation

> Testing library to expect some messages in a queue or topic in stomp protocol.

Latest version **0.0.25** (published 2016-11-05) · AGPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install bus-expectation
pnpm add bus-expectation
yarn add bus-expectation
bun add bus-expectation
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.25 |
| Published | 2016-11-05 |
| First published | 2016-05-12 |
| Weekly downloads | 0 |
| License | AGPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | eyeos |

## Links

- npm: https://www.npmjs.com/package/bus-expectation
- npm.io page: https://npm.io/package/bus-expectation

## Dependencies (3)

- [deep-equal](https://npm.io/package/deep-equal.md) 1.0.0
- [eyeos-hooks](https://npm.io/package/eyeos-hooks.md) *
- [eyeos-stomp](https://npm.io/package/eyeos-stomp.md) ~0.1.2

## Recent versions

- 0.0.25 (latest) — 2016-11-05
- 0.0.26 — 2016-05-12

## README

Bus-expectation Library
=======================

## Overview

Testing library to expect some messages in a queue or topic in stomp protocol.

Currently, there are two API flavours:

* BusExpectation
* BusSpy

### BusSpy

```javascript
var doSendTestMsg;
var busSpy = new BusSpy();
BusSpy().onDestination('/topic/user_eyeos')
    .timeout(1500)
    .exercise(doSendTestMsg) //do whatever actions will cause expected message
    .expectHeadersMatch({'chucha':'jija'}) //expecting the stomp message to have header chucha === 'jija'
    .expectBodyProperties({
        'nested.a': 1, // expecting message to have {... nested: {a: 1} ...}
        "type": String, // expecting type field to be a String
        "nested": Object,
        "aTxt": busSpy.Defined, //expecting aTxt not to be undefined or null
        "aNull": null //expecting aNull field to be null
    })
    .expectPredicate(function(msg){ //expect with custom function
        var body = JSON.parse(msg.body);
        return body.aNumber + body.anotherNumber === 7;
    })
    .done(done);
    
doSendTestMsg = function (exerciseDone) {
    //exercise functions receive a callback to let know the BusSpy when exercise has finished.
    var client = new stomp.Stomp(settings.stomp);
    client.connect();
    client.on('connected', function() {
        client.send({
            chucha: 'jija',
            destination: '/topic/user_eyeos',
            body: '{"type":"test", "aNumber": 3, "anotherNumber": 4, "aTxt": "hi", "ts": 123456789, "nested": {"a": 1, "b": "a be"}, "aNull": null}'
        }, true);
        exerciseDone();
    });
};
```
See *src/component-tests/busSpy.component.test.js* for a complete list of examples.

### BusExpectation

```javascript
var busExpectation = new BusExpectation();
busExpectation.in('/topic/user_eyeos')
	.expect({
		'type': 'jobs.updated',
		'data.body.action': 'move'
	});
busExpectation.verify(done);
```

See usage in src/component-tests/busExpectation.test.js

### Optionally you can pass connection settings through environtment variables:
```bash
export BUS_EXPECTATION_PORT=61613
export BUS_EXPECTATION_HOST=localhost
export BUS_EXPECTATION_DEBUG=false
export BUS_EXPECTATION_USER=<username>
export BUS_EXPECTATION_PASSWORD=<password>
```

## How to use it

## Quick help

* Install modules

```bash
	$ npm install
```

* Check tests

```bash
    $ ./tests.sh
```

---
_Source: https://npm.io/package/bus-expectation · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
