3.1.1 • Published 6 years ago

bridge-node-messaging v3.1.1

Weekly downloads
2
License
MIT License
Repository
github
Last release
6 years ago

codecov

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.

3.1.1

6 years ago

3.1.0

6 years ago

3.0.5

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago