coworkers-test
Helper to easily test coworkers message-handling middlewares as a unit
Installation
npm install --save coworkers-test
Usage
test.js
:
const coworkersTest = const sinon = const app = // BDD style is shown but not required.// Replace the BDD style in this example w/ you test runner's api
app.js
:
const app = moduleexports = app app
API
send(queueName, content, [props], [fields])
Use this to mock-send a message to your coworkers app
content
is the message content (it will cast numbers, strings, objects, and arrays to buffers for you)
props
are optional, and set as message properties to add to your message.
fields
are optional, message fields (like headers
) to add to your message.
Defaults:
// default message.properties headers: {}// default message.fields 'consumerTag': 'amq.ctag-izmxkEleoW2XjvKP3mNNUA' 'deliveryTag': deliveryTag++ // auto-incremented id starting at 1 'redelivered': false 'exchange': '' 'routingKey': queueName
expect([cb])
Allows you to handle any assertion errors (expectAck, etc) and make custom assertions of your own on context
Callback recieves err
(assertion err) and context
. context
will always be passed even in the case of an error.
If expect
is not passed a callback it will return a Promise
. Context methods are sinon
stubs and can be asserted using sinon's assertion api.
expectAck([expectedOpts])
Expect that queue's consumer ack
s the message, will pass it's error to expect
callback.
expectedOpts
allows you to verify that ack
was invoked w/ the appropriate expected opts
expectNack([expectedOpts])
Expect that queue's consumer nack
s the message, will pass it's error to expect
callback.
expectedOpts
allows you to verify that nack
was invoked w/ the appropriate expected opts
expectAckAll([expectedOpts])
Expect that queue's consuemr ackAll
s the message, will pass it's error to expect
callback.
expectedOpts
allows you to verify that ackAll
was invoked w/ the appropriate expected opts
expectNackAll([expectedOpts])
Expect that queue's consumer nackAll
s the message, will pass it's error to expect
callback.
expectedOpts
allows you to verify that nackAll
was invoked w/ the appropriate expected opts
expectReject([expectedOpts])
Expect that queue's consuemr reject
s the message, will pass it's error to expect
callback.
expectedOpts
allows you to verify that reject
was invoked w/ the appropriate expected opts
License
MIT