import * as WebSocket from 'ws';
import ClientBase from '../clients/clientBase';
import MHSClient from '../clients/sites/mhsClient';
import ClientManager from '../clientManager';

var expect = require('chai').expect;
var assert = require('chai').assert;
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 clientManager = new ClientManager();

describe('ClientManager', function () {
  it('should add a client', function () {
    var result = clientManager.addClient(data, wsClient);
    expect(result.id).to.be.equal(125);
  });

  it('should get clients of type', function () {
    var result = clientManager.clientsOfType('site');
    assert(result.length > 0, 'returns one client');
  });

  it('should see client exists', function () {
    var exists = clientManager.clientExists(data.user_id);
    var result = exists ? true : false;
    expect(result).to.be.equal(true);
  });

  it('should see client does not exists', function () {
    var exists = clientManager.clientExists(200);
    var result = exists ? true : false;
    expect(result).to.be.equal(false);
  });

  it('should get an existing client', function () {
    var exists = clientManager.getClient(data.user_id);
    var result = exists ? true : false;
    expect(result).to.be.equal(true);
  });

  it('should not get an existing client', function () {
    var exists = clientManager.getClient(200);
    var result = exists ? true : false;
    expect(result).to.be.equal(false);
  });

  it('should add client of type MHSClient', function () {
    var data: any = { 'client': 'mhs', 'client_type':'site', 'user_id': 125, 'user_type': 'user', 'channel': name }
    var result = clientManager.getClientType(data, wsClient);
    expect(result.clientType()).to.be.equal('mhs');
  });
});
