more tests....got figure out how to send web socket messges in testing platform
This commit is contained in:
@ -26,6 +26,10 @@ class ClientBase {
|
||||
return this.data.client_type;
|
||||
}
|
||||
|
||||
clientType() {
|
||||
return this.data.client;
|
||||
}
|
||||
|
||||
connectToChannel(channel: ChannelBase|MHSChannel) {
|
||||
this.channel = channel;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
module.exports = {
|
||||
version : '0.6.2',
|
||||
version : '0.7.1',
|
||||
whitelist : (process.env.WHITELIST || "http://admin.localhost").split(','),
|
||||
secret : process.env.SECRET || "test",
|
||||
devToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoidGVzdCBkYXRhIiwiYXVkIjoiaW50ZXJuYWwiLCJpc3MiOiJZYXJkc3RpY2sgU29mdHdhcmUiLCJzdWIiOiJCcmFpZCBKV1QifQ.t6LFXWPEVz3aLXwtrucarggqTkGY_2NnZB8ZTMaJ2oI',
|
||||
|
@ -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);
|
||||
// });
|
||||
});
|
||||
|
Reference in New Issue
Block a user