<commit_before>'use strict';
/* Setup */
/*jshint camelcase: false */
var Lab = require('lab');
var Code = require('code');
var lab = exports.lab = Lab.script();

var describe = lab.describe;
var it = lab.it;
var before = lab.before;
var beforeEach = lab.beforeEach;
var after = lab.after;
var afterEach = lab.afterEach;
var expect = Code.expect;

/* Modules */
var simple = require('simple-mock');
var msb = require('..');
var Responder = msb.Responder;
var channelManager = msb.channelManager;

/* Tests */
describe('Responder', function() {
  afterEach(function(done) {
    simple.restore();
    done();
  });

  describe('()', function() {

    it('cannot be initialized without a config', function(done) {

      expect(function() {
        var responder = new Responder(null, {});
      }).to.throw();

      done();
    });

    it('cannot be initialized without an original message', function(done) {

      expect(function() {
        var responder = new Responder({});
      }).to.throw();

      done();
    });

    it('can be initialized', function(done) {

      var responder = Responder({}, { topics: {} });

      done();
    });
  });

  describe('sendAck()', function() {
    var responder;

    beforeEach(function(done) {
      responder = new Responder({}, { topics: { ack: 'ack' } });

      simple.mock(responder, '_sendMessage').returnWith();

      done();
    });

    it('can be called without params', function(done) {
      expect(function() {
        responder.sendAck();
      }).to.not.throw();

      expect(responder.ack.timeoutMs).equals(null);
      expect(responder.ack.responsesRemaining).equals(1);

      expect(responder._sendMessage.called).true();

      var message = responder._sendMessage.lastCall.args[0];
      expect(message.ack).deep.equals(responder.ack);

      done();
    });

    it('can be called with only a timeout', function(done) {
      expect(function() {
        responder.sendAck(333);
      }).to.not.throw();

      expect(responder.ack.timeoutMs).equals(333);
      expect(responder.ack.responsesRemaining).equals(1);

      expect(responder._sendMessage.called).true();

      var message = responder._sendMessage.lastCall.args[0];
      expect(message.ack).deep.equals(responder.ack);

      done();
    });

    it('can be called with only a responses remaining', function(done) {
      expect(function() {
        responder.sendAck(null, 5);
      }).to.not.throw();

      expect(responder.ack.timeoutMs).equals(null);
      expect(responder.ack.responsesRemaining).equals(5);

      expect(responder._sendMessage.called).true();

      var message = responder._sendMessage.lastCall.args[0];
      expect(message.ack).deep.equals(responder.ack);

      done();
    });

    it('can be called with only a cb', function(done) {
      var cb = simple.mock();

      expect(function() {
        responder.sendAck(cb);
      }).to.not.throw();

      expect(responder.ack.timeoutMs).equals(null);
      expect(responder.ack.responsesRemaining).equals(1);

      expect(responder._sendMessage.called).true();
      expect(responder._sendMessage.lastCall.args[1]).equals(cb);

      var message = responder._sendMessage.lastCall.args[0];
      expect(message.ack).deep.equals(responder.ack);

      done();
    });

    it('can be called with timeout, responses remaining and a cb', function(done) {
      var cb = simple.mock();

      expect(function() {
        responder.sendAck(444, 5, cb);
      }).to.not.throw();

      expect(responder.ack.timeoutMs).equals(444);
      expect(responder.ack.responsesRemaining).equals(5);

      expect(responder._sendMessage.called).true();
      expect(responder._sendMessage.lastCall.args[1]).equals(cb);

      var message = responder._sendMessage.lastCall.args[0];
      expect(message.ack).deep.equals(responder.ack);

      done();
    });

    it('can be called with only a timeout and cb', function(done) {
      var cb = simple.mock();

      expect(function() {
        responder.sendAck(); // Setup
        responder.ack.responsesRemaining = 10;
      }).to.not.throw();

      expect(function() {
        responder.sendAck(333, cb);
      }).to.not.throw();

      expect(responder.ack.timeoutMs).equals(333);
      expect(responder.ack.responsesRemaining).equals(1);

      expect(responder._sendMessage.called).true();

      var message = responder._sendMessage.lastCall.args[0];
      expect(message.ack).deep.equals(responder.ack);

      done();
    });
  });

  describe('send()', function() {
    var responder;
    var mockChannel;

    beforeEach(function(done) {
      responder = new Responder({}, { topics: { ack: 'ack' } });

      mockChannel = {};
      simple.mock(mockChannel, 'publish');
      simple.mock(channelManager, 'findOrCreateProducer').returnWith(mockChannel);

      done();
    });
  });

  describe('_sendMessage()', function() {
    var responder;
    var mockChannel;

    beforeEach(function(done) {
      responder = new Responder({}, { topics: { ack: 'ack' } });

      mockChannel = {};
      simple.mock(mockChannel, 'publish');
      simple.mock(channelManager, 'findOrCreateProducer').returnWith(mockChannel);

      done();
    });

    it('can be called with a cb', function(done) {
      var cb = simple.mock();

      expect(function() {
        responder._sendMessage({
          topics: { to: 'example' }
        }, cb);
      }).to.not.throw();
<commit_msg>Restore minor fixes removed with reverted changes<commit_after>'use strict';
/* Setup */
/*jshint camelcase: false */
var Lab = require('lab');
var Code = require('code');
var lab = exports.lab = Lab.script();

var describe = lab.describe;
var it = lab.it;
var before = lab.before;
var beforeEach = lab.beforeEach;
var after = lab.after;
var afterEach = lab.afterEach;
var expect = Code.expect;

/* Modules */
var simple = require('simple-mock');
var msb = require('..');
var Responder = msb.Responder;
var channelManager = msb.channelManager;

/* Tests */
describe('Responder', function() {
  afterEach(function(done) {
    simple.restore();
    done();
  });

  describe('()', function() {

    it('cannot be initialized without a config', function(done) {

      expect(function() {
        var responder = new Responder(null, {});
      }).to.throw();

      done();
    });

    it('cannot be initialized without an original message', function(done) {

      expect(function() {
        var responder = new Responder({});
      }).to.throw();

      done();
    });

    it('can be initialized', function(done) {

      var responder = Responder({}, { topics: {} });

      done();
    });
  });

  describe('sendAck()', function() {
    var responder;

    beforeEach(function(done) {
      responder = new Responder({}, { topics: { response: 'response' } });

      simple.mock(responder, '_sendMessage').returnWith();

      done();
    });

    it('can be called without params', function(done) {
      expect(function() {
        responder.sendAck();
      }).to.not.throw();

      expect(responder.ack.timeoutMs).equals(null);
      expect(responder.ack.responsesRemaining).equals(1);

      expect(responder._sendMessage.called).true();

      var message = responder._sendMessage.lastCall.args[0];
      expect(message.ack).deep.equals(responder.ack);

      done();
    });

    it('can be called with only a timeout', function(done) {
      expect(function() {
        responder.sendAck(333);
      }).to.not.throw();

      expect(responder.ack.timeoutMs).equals(333);
      expect(responder.ack.responsesRemaining).equals(1);

      expect(responder._sendMessage.called).true();

      var message = responder._sendMessage.lastCall.args[0];
      expect(message.ack).deep.equals(responder.ack);

      done();
    });

    it('can be called with only a responses remaining', function(done) {
      expect(function() {
        responder.sendAck(null, 5);
      }).to.not.throw();

      expect(responder.ack.timeoutMs).equals(null);
      expect(responder.ack.responsesRemaining).equals(5);

      expect(responder._sendMessage.called).true();

      var message = responder._sendMessage.lastCall.args[0];
      expect(message.ack).deep.equals(responder.ack);

      done();
    });

    it('can be called with only a cb', function(done) {
      var cb = simple.mock();

      expect(function() {
        responder.sendAck(cb);
      }).to.not.throw();

      expect(responder.ack.timeoutMs).equals(null);
      expect(responder.ack.responsesRemaining).equals(1);

      expect(responder._sendMessage.called).true();
      expect(responder._sendMessage.lastCall.args[1]).equals(cb);

      var message = responder._sendMessage.lastCall.args[0];
      expect(message.ack).deep.equals(responder.ack);

      done();
    });

    it('can be called with timeout, responses remaining and a cb', function(done) {
      var cb = simple.mock();

      expect(function() {
        responder.sendAck(444, 5, cb);
      }).to.not.throw();

      expect(responder.ack.timeoutMs).equals(444);
      expect(responder.ack.responsesRemaining).equals(5);

      expect(responder._sendMessage.called).true();
      expect(responder._sendMessage.lastCall.args[1]).equals(cb);

      var message = responder._sendMessage.lastCall.args[0];
      expect(message.ack).deep.equals(responder.ack);

      done();
    });

    it('can be called with only a timeout and cb', function(done) {
      var cb = simple.mock();

      expect(function() {
        responder.sendAck(); // Setup
        responder.ack.responsesRemaining = 10;
      }).to.not.throw();

      expect(function() {
        responder.sendAck(333, cb);
      }).to.not.throw();

      expect(responder.ack.timeoutMs).equals(333);
      expect(responder.ack.responsesRemaining).equals(1);

      expect(responder._sendMessage.called).true();

      var message = responder._sendMessage.lastCall.args[0];
      expect(message.ack).deep.equals(responder.ack);

      done();
    });
  });

  describe('send()', function() {
    var responder;
    var mockChannel;

    beforeEach(function(done) {
      responder = new Responder({}, { topics: { response: 'response' } });

      simple.mock(responder, '_sendMessage');

      done();
    });
  });

  describe('_sendMessage()', function() {
    var responder;
    var mockChannel;

    beforeEach(function(done) {
      responder = new Responder({}, { topics: { response: 'response' } });

      mockChannel = {};
      simple.mock(mockChannel, 'publish');
      simple.mock(channelManager, 'findOrCreateProducer').returnWith(mockChannel);

      done();
    });

    it('can be called with a cb', function(done) {
      var cb = simple.mock();

      expect(function() {
        responder._sendMessage({
          topics: { to: 'example' }
        }, cb);
      }).to.not.throw();

{'fraction_non_alphanumeric': 0.16201220639911226, 'fraction_numerical': 0.006658035879415572, 'mean_word_length': 2.941326530612245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1167973', 'n_tokens_mistral': 3394, 'n_tokens_neox': 3218, 'n_words': 611}