import ChannelBase from '../channels/channelBase';
import ClientBase from '../clients/clientBase';
import MHSClient from '../clients/sites/mhsClient';
import MHSChannel from '../channels/sites/mhsChannel';
import ChannelManager from '../channelManager';

var expect = require('chai').expect;
var sinon = require('sinon');

var name: string = 'test channel';
var data: any = { 'client': 'test', 'client_type':'site', 'user_id': 125, 'user_type': 'user', 'channel': name }
var WebSocketClient = require('websocket').client;
var wsClient = new WebSocketClient();
var client: ClientBase = new ClientBase(data, wsClient);

let channelManager = new ChannelManager();

describe('ChannelManager', function () {
  var channel: ChannelBase;

  it('should create a channel', function () {
    channel = channelManager.createChannel(data);
    expect(channel.id).to.be.equal(name);
  });

  it('should return existing channel when attempting to create a channel', function () {
    channel = channelManager.createChannel(data);
    expect(channel.id).to.be.equal(name);
  });

  it('should return a channel when searching if channel exists', function () {
    var exists = channelManager.channelExists(channel.id);
    var result = exists ? true : false;
    expect(result).to.be.equal(true);
  });

  it('should not return a channel when serachingif channel exists', function () {
    var exists = channelManager.channelExists('no channel');
    var result = exists ? true : false;
    expect(result).to.be.equal(false);
  });

  it('should add a client to channel', function () {
    var result = channelManager.addClientToChannel(client, channel.id);
    expect(result.status).to.be.equal('success');
  });

  it('should not add a client to channel', function () {
    var result = channelManager.addClientToChannel(client, 'no channel');
    expect(result.status).to.be.equal('notice');
  });

  it('should create a channel of type MHSChannel', function () {
    var data2 = { 'channel': 'test channel 2', 'client': 'mhs', 'client_type':'site' };
    var result = channelManager.createByChannelType(data2);
    expect(result.id).to.be.equal('test channel 2');
  });

  it('should remove client from channel', function () {
    var result = channelManager.removeClientFromChannel(client.id , 'test channel');
    expect(result).to.be.equal(true);
  });

  it('should be unable to remove a client that doesn\'t exit from channel', function () {
    var result = channelManager.removeClientFromChannel(126 , 'test channel');
    expect(result).to.be.equal(false);
  });

  it('should be unable to remove a client from a channel that doesn\'t exist', function () {
    var result = channelManager.removeClientFromChannel(client.id , 'test channel 3');
    expect(result).to.be.equal(false);
  });
});
