2.0.0 • Published 7 years ago

promoter v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

promoter

This is a shim around @google-cloud/pubsub to allow you to use it even when you're not in a google cloud environment, and to let you use your own mock function for publishes in your tests.

If GCLOUD_PROJECT is exported to your environment, you get a real pubsub interface, otherwise you get a mocked one - which is super minimal right now.

usage

'use strict';

const Promoter = require('promoter')();

Promoter.topic('someTopic').get().then(([topic]) => {

  topic.publish({ some: 'stuff' });
});

When used in a test, save a copy of your promoter instance somewhere and you can override the publisher method like so:

'use strict';

const Promoter = require('promoter')();

const publish = (msg) => {
  
  return Promoter.topic('someTopic').get().then(([topic]) => {

    return topic.publish(msg);
  });
};

describe('publish', () => {

  it('can publish stuff', (done) => {

    Promoter.options.publisher = (msg) => {

      expect(msg).to.be.an.object();
      expect(msg.some).to.equal('message');
      done();
    };

    publish({ some: 'message' });
  });
});
2.0.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago