const expect = require('chai').expect;

const testData = require('./data/telegram-messages');
const eventGenerator = require('./event-generator');

const Mankov = require('../src/index');

const IltaaCommander  = require('./commanders/iltaa-commander');
const MoroResponder   = require('./responders/moro-responder');
const logMonitor      = require('./monitors/log-monitor');


describe('Mankov Core', () => {
  let mankov = null;

  before(() => {
    mankov = new Mankov();
    mankov.createBot('telegram', 'TestBot', { token: 'ASDF-1' });
    // NOTE: all the tests after this attaches commanders/responders/monitors
    // to this mankov instance. Their event handling MIGHT collide at some point
    // so it is something to take care of. Or we could implement clearCommanders()
    // etc functions to core?
  });

  describe('Commanders', () => {
    before(() => {
      mankov.addCommander(new IltaaCommander());
    });


    it('Handles basic /iltaa-command', () => mankov
      .getActions(testData.parsedIltaaMessage)
      .then(actions => {
        // NOTE/TODO: this test will be scrapped when functionality is added

        console.log('actions', actions);

        expect(actions[0]).to.containSubset({
          type: 'SEND_MESSAGE',
          payload: {
            text: 'Game of Iltuz',
            target: testData.parsedIltaaMessage.userId
          }
        });
      })
    );
  });


  describe('Responders', () => {
    before(() => {
      mankov.addResponder(new MoroResponder(100, 'testimoroprefix'));
    });

    it('Responds to message with a keyword', () => mankov
      .getActions(eventGenerator.textEvent('juuh moro nääs'))
      .then(actions => {
        expect(actions).to.be.an.array;
        console.log('teaojreoaijrioea', actions, actions.payload);
        // expect(actions[0]).
      })
    );
  });


  });

  describe('Monitors', () => {
    let monitor = null;

    before(() => {
      monitor = new logMonitor();
      mankov.addMonitor(monitor);
    });

    it('can add a monitor to the core', () => mankov
      .processEvent(testData.parsedIltaaMessage)
      .then(expect(monitor.lastEvent).to.equal(testData.parsedIltaaMessage))
    );

    it.skip('should not crash the core even if there was an error', () => {
      // TODO
    });

  });

  describe('Platforms', () => {

    // Clear platforms before each test
    beforeEach(() => {
      mankov._bots = [];
    });

    it('should give available platforms', () => {
      expect(mankov.getAvailablePlatforms()).to.deep.equal(['telegram', 'irc']);
    });

    it('should be able to create a Telegram bot', (done) => {
      const name = 'TestTGBot';
      const options = { token: '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11' };

      mankov.createBot('telegram', name, options)
      .then((bot) => {

        expect(bot.name).to.equal(name);
        expect(bot.onMessage).to.be.a.function;

        // Platform specific asserts
        expect(bot.client.token).to.equal(options.token);

        done();
      });
    });

    it('should be able to create an IRC bot', (done) => {
      const name = 'TestIRCBot';
      const options = {
        server: 'http://example.com',
        nick: 'Mankov'
      };

      mankov.createBot('irc', name, options)
      .then((bot) => {

        expect(bot.name).to.equal(name);
        expect(bot.onMessage).to.be.a.function;

        // Platform specific asserts
        // ...

        done();
      });
    });

    it('should not allow to create a bot with same name', () => {
      const name = 'TestIRCBot';
      const options = {
        server: 'http://example.com',
        nick: 'Mankov'
      };

      // First time should be ok
      expect(mankov.createBot('irc', name, options)).eventually.resolved;

      expect(mankov.createBot('irc', name, options)).eventually.rejectedWith(
        `Bot with name "${name}" has already been created.`
      );
    });

    it('should reject if platform type was not found', () =>
      expect(mankov.createBot('unknownPlatform', {})).eventually.rejected
    );

  });

});

@@ -31,16 +31,55 @@
 .expect;
+%0Aconst assert = require('chai').assert;
 %0A%0Aconst 
@@ -1092,127 +1092,8 @@
 =%3E %7B
-%0A        // NOTE/TODO: this test will be scrapped when functionality is added%0A%0A        console.log('actions', actions);
 %0A%0A  
@@ -1655,122 +1655,668 @@
     
-console.log('teaojreoaijrioea', actions, actions.payload);%0A        // expect(actions%5B0%5D).%0A      %7D)%0A    );%0A  %7D
+expect(actions).to.have.length(1);%0A%0A        assert(%0A          actions%5B0%5D.payload.text.indexOf('testimoroprefix') %3E= 0,%0A          'prefix should%C2%B4ve been added to end of response action text'%0A        );%0A      %7D)%0A    );%0A  %7D);%0A%0A%0A  describe('Comamnders and Responders', () =%3E %7B%0A    before(() =%3E %7B%0A      // this relies that the IltaaCommander and MoroResponder%0A      // are attached to mankov previously%0A    %7D);%0A%0A    it('Ignores events with no keywords in them', () =%3E mankov%0A      .getActions(eventGenerator.textEvent('no keywords in it'))%0A      .then(actions =%3E %7B%0A        expect(actions).to.be.an.array;%0A        expect(actions.length).to.equal(0);%0A      %7D)%0A    
 );%0A
-%0A%0A
   %7D)
@@ -3087,32 +3087,88 @@
 t', (done) =%3E %7B%0A
+      // TODO: these could be in a dedicated test file?%0A
       const name
@@ -3611,24 +3611,80 @@
 (done) =%3E %7B%0A
+      // TODO: these could be in a dedicated test file?%0A
       const 

Implement dummy test which combines Commanders & Responders