46 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| "use strict";
 | |
| Object.defineProperty(exports, "__esModule", { value: true });
 | |
| const channelBase_1 = require("../channels/channelBase");
 | |
| const clientBase_1 = require("../clients/clientBase");
 | |
| var exec = require('child_process').exec;
 | |
| var expect = require('chai').expect;
 | |
| var sinon = require('sinon');
 | |
| var WebSocketClient = require('websocket').client;
 | |
| var app = require('../config/app');
 | |
| var name = 'test channel';
 | |
| var wsClient = new WebSocketClient();
 | |
| var channel;
 | |
| var data = { 'client': 'test', 'client_type': 'site', 'user_id': 125, 'user_type': 'user', 'channel': name };
 | |
| var client = new clientBase_1.default(data, wsClient);
 | |
| describe('ChannelBase', function () {
 | |
|     it('should create a class of ChannelBase', function () {
 | |
|         channel = new channelBase_1.default(name);
 | |
|         expect(channel.id).to.be.equal(name);
 | |
|     });
 | |
|     it('should add a client to channel', function () {
 | |
|         var result = channel.addClient(client);
 | |
|         expect(result.status).to.be.equal('success');
 | |
|     });
 | |
|     it('should find a client when trying to add said client to channel', function () {
 | |
|         var result = channel.addClient(client);
 | |
|         expect(result.status).to.be.equal('notice');
 | |
|     });
 | |
|     it('should find a client', function () {
 | |
|         var exist = channel.clientExists(client.id);
 | |
|         var result = exist ? true : false;
 | |
|         expect(result).to.be.equal(true);
 | |
|     });
 | |
|     it('should not broadcast a message to self', function () {
 | |
|         var result = channel.broadcastMessage(client, 'test message');
 | |
|         expect(result.status).to.be.equal('success');
 | |
|     });
 | |
|     it('should be able to remove client from channel', function () {
 | |
|         var result = channel.removeClient(client.id);
 | |
|         expect(result).to.be.equal(true);
 | |
|     });
 | |
|     it('should not be able to remove client that doesnn\'t exist from channel', function () {
 | |
|         var result = channel.removeClient(126);
 | |
|         expect(result).to.be.equal(false);
 | |
|     });
 | |
| });
 | |
| //# sourceMappingURL=channelBase.spec.js.map
 | 
