<commit_before>"use strict";

var Handler = require('../../muon/infrastructure/handler-class.js');
var assert = require('assert');
var expect = require('expect.js');
require('sexylog');
var bichannel = require('../../muon/infrastructure/channel.js');


describe("Handler class test:", function () {


      this.timeout(4000);


      after(function() {

      });


    it("handler between two channels", function (done) {

            var msg = {count: 0, audit: []};

              var upstream = bichannel.create("upstream");
              var downstream = bichannel.create("downstream");

               class TestHandler extends Handler {

                 outgoingFunction(message, forward, back, route) {
                   message.count++;
                   message.audit.push('testHandler.outgoing()');
                   forward(message);
                 }

                 incomingFunction(message, forward, back, route) {
                   message.count++;
                   message.audit.push('testHandler.incoming()');
                   forward(message);
                 }
               }

               var testHandler = new TestHandler('test');

                upstream.rightHandler(testHandler);
                downstream.leftHandler(testHandler);

                upstream.leftSend(msg);

                upstream.leftConnection().listen(function(message) {
                        console.log('***** upstream message returned:');
                        console.dir(message);
                        assert.equal(message.count, 2);
                        assert.equal(message.audit[0], 'testHandler.outgoing()');
                        assert.equal(message.audit[1], 'testHandler.incoming()');
                        done();
                });


                downstream.rightConnection().listen(function(message){
                    downstream.rightSend(message);
                });

    });

    it("single channel handler routes inbound message to callback and return response outbound", function (done) {

            var msg = {count: 0, audit: [], routingKey: 'server'};

              class TestHandler extends Handler {

                outgoingFunction(message, forward, back, route) {
                  message.count++;
                  message.audit.push('testHandler.outgoing()');
                  forward(message);
                }

                incomingFunction(message, forward, back, route) {
                  message.count++;<commit_msg>added test for function mixup with handler as class<commit_after>"use strict";

var Handler = require('../../muon/infrastructure/handler-class.js');
var assert = require('assert');
var expect = require('expect.js');
require('sexylog');
var bichannel = require('../../muon/infrastructure/channel.js');


describe("Handler class test:", function () {


      this.timeout(4000);


      after(function() {

      });


    it("handler between two channels", function (done) {

            var msg = {count: 0, audit: []};

              var upstream = bichannel.create("upstream");
              var downstream = bichannel.create("downstream");

               class TestHandler extends Handler {

                 outgoingFunction(message, forward, back, route) {
                   message.count++;
                   message.audit.push('testHandler.outgoing()');
                   forward(message);
                 }

                 incomingFunction(message, forward, back, route) {
                   message.count++;
                   message.audit.push('testHandler.incoming()');
                   forward(message);
                 }
               }

               var testHandler = new TestHandler('test');

                upstream.rightHandler(testHandler);
                downstream.leftHandler(testHandler);

                upstream.leftSend(msg);

                upstream.leftConnection().listen(function(message) {
                        console.log('***** upstream message returned:');
                        console.dir(message);
                        assert.equal(message.count, 2);
                        assert.equal(message.audit[0], 'testHandler.outgoing()');
                        assert.equal(message.audit[1], 'testHandler.incoming()');
                        done();
                });


                downstream.rightConnection().listen(function(message){
                    downstream.rightSend(message);
                });

    });

    it("outgoing handler between two channels sends back", function (done) {

            var msg = {count: 0, audit: []};

              var upstream = bichannel.create("upstream");
              var downstream = bichannel.create("downstream");

               class TestHandler extends Handler {

                 outgoingFunction(message, forward, back, route) {
                   message.count++;
                   message.audit.push('testHandler.outgoing()');
                   back(message);
                 }

                 incomingFunction(message, forward, back, route) {
                   message.count++;
                   message.audit.push('testHandler.incoming()');
                   forward(message);
                 }
               }

               var testHandler = new TestHandler('test');

                upstream.rightHandler(testHandler);
                downstream.leftHandler(testHandler);

                upstream.leftSend(msg);

                upstream.leftConnection().listen(function(message) {
                        console.log('***** upstream message returned:');
                        console.dir(message);
                        assert.equal(message.count, 1);
                        assert.equal(message.audit[0], 'testHandler.outgoing()');
                        done();
                });


                //downstream.rightConnection().listen(function(message){
                //    downstream.rightSend(message);
                //});

    });


    it("incoming handler between two channels sends back", function (done) {

            var msg = {count: 0, audit: []};

              var upstream = bichannel.create("upstream");
              var downstream = bichannel.create("downstream");

               class TestHandler extends Handler {

                 outgoingFunction(message, forward, back, route) {
                   message.count++;
                   message.audit.push('testHandler.outgoing()');
                   forward(message);
                 }

                 incomingFunction(message, forward, back, route) {
                   message.count++;
                   message.audit.push('testHandler.incoming()');
                   back(message);
                 }
               }

               var testHandler = new TestHandler('test');

                upstream.rightHandler(testHandler);
                downstream.leftHandler(testHandler);

                upstream.leftSend(msg);

                var downstreamCalls = 0;
                downstream.rightConnection().listen(function(message) {
                    downstreamCalls++;
                    if (downstreamCalls == 1) {
                        downstream.rightSend(message);
                    } else {
                      console.log('***** downstream message returned:');
                      console.dir(message);
                      assert.equal(message.count, 2);
                      assert.equal(message.audit[0], 'testHandler.outgoing()');
                      assert.equal(message.audit[1], 'testHandler.incoming()');
                      done();
                    }

                });

    });

    it("single channel handler routes inbound message to callback and return response outbound", function (done) {

            var msg = {count: 0, audit: [], routingKey: 'server'};

              class TestHandler extends Handler {

                outgoingFunction(message, forward, back, route) {
                  message.count++;
                  message.audit.push('testHandler.outgoing()');
                  forward(message);
                }

                incomingFunction(message, forward, back, route) {
                  message.count++;
{'fraction_non_alphanumeric': 0.11749665164982345, 'fraction_numerical': 0.0032874710824302936, 'mean_word_length': 1.5057962172056132, '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': '2260990', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1781, 'n_words': 362}