more tests....got figure out how to send web socket messges in testing platform

This commit is contained in:
Josh Burman
2019-03-13 12:27:43 -04:00
parent bfd652ce20
commit 501a14d713
32 changed files with 300 additions and 4 deletions

View File

@ -0,0 +1,63 @@
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');
});
// it('should remove a client', function () {
// clientManager.removeClient(data.user_id);
// expect(clientManager.clients.length).to.be.equal(0);
// });
});