added unit testing, and started implementing unit tests...phew

This commit is contained in:
Josh Burman
2019-03-12 22:28:02 -04:00
parent 74aad4a957
commit e8c2539f1b
3489 changed files with 464813 additions and 88 deletions

View File

@ -1,6 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const channelBase_1 = require("./channels/channelBase");
var logger = require('./logger');
class ChannelManager {
constructor() {
this.channels = [];
@ -9,15 +10,18 @@ class ChannelManager {
this.channels.push(channel);
}
createChannel(data) {
var channel = this.channelExists(data.channel);
if (channel) {
console.log('channel already exists');
var channelExists = this.channelExists(data.channel);
var channel;
if (channelExists) {
channel = channelExists;
logger.accessLog.info(`Channel already exists: ${channel.id}`);
}
else {
channel = this.getChannelType(data);
channel ? this.channels.push(channel) : null;
console.log('added channel to channel manager');
channel = this.createByChannelType(data);
this.channels.push(channel);
logger.accessLog.info(`Added channel to channel manager: ${channel.id}`);
}
return channel;
}
channelExists(channel_id) {
for (let channel of this.channels) {
@ -32,20 +36,22 @@ class ChannelManager {
if (channel) {
channel.addClient(client);
client.connectToChannel(channel);
return { 'status': 'success' };
}
else {
console.log(`channel with id ${channel_id} does not exist.`);
logger.accessLog.info(`channel with id ${channel_id} does not exist.`);
return { 'status': 'notice', 'message': `channel with id ${channel_id} does not exist.` };
}
}
getChannelType(data) {
createByChannelType(data) {
try {
var Channel = require(`./channels/${data.client_type}s/${data.client}channel`);
console.log(`attempting to create channel of type ${data.client}, channel id: ${data.channel}...`);
logger.accessLog.info(`attempting to create channel of type ${data.client}, channel id: ${data.channel}...`);
return new Channel(data.channel);
}
catch (e) {
console.log(e);
console.log(`creating base channel`);
logger.errorLog.info(e);
logger.accessLog.info(`creating base channel: ${data.channel}`);
return new channelBase_1.default(data.channel);
}
}