README
bridge-node-messaging
Bridge messaging lib
This library intends to create an abstraction and some useful utility over the amqplib.
Testing
For testing facilities you can use module bridge-node-messaging/test
.
In that module you can find an helper amqpMockHelper
function that mocks all amqp interfaces.
This helper initialize amqp mocking with amqpMockHelper.mockAmqpForTest
.
Mocking is based on third library called : bridge-amqplib-mocks
.
Sample use case:
In your test setup file : like Jest setupTestFrameworkScriptFile
.
Not yet tested on other languages/ test frameworks (eg. Js/Jasmine).
// Your base amqp instance with thait compagnon init method
import { amqp, initMessagingForConsumers } from 'src/messaging';
// Test Amqp components, typically producer to test your consumer, etc...
// This is the same configuration purpose of using this library (see main documentation for details)
import { testMessagingConfiguration } from './testMessagingConfiguration';
...
// Init Amqp mocks
amqpMockHelper.mockAmqp(amqp);
// Init Amqp testing utilities
config.messaging!.components = config.messaging!.components.concat(
testMessagingConfiguration.components,
);
beforeAll(() => {
return initMessagingForConsumers();
});
In your test case :
describe('something to test', () => {
...
let amqpTestProducer: any;
beforeAll(() => {
amqpTestProducer = amqp.getProducer('test-producer');
...
});
...
describe('process', () => {
it('expect something', () => {
amqpTestProducer.sendMessage('test.message', PAYLOAD);
return retry(() => expect(...).something(...));
});
});
});
To use amqpMockHelper
in your project you need to import bridge-amqplib-mocks
in your dependencies.