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,22 +1,25 @@
import ClientBase from '../clients/clientBase';
import MHSClient from '../clients/sites/mhsClient';
var logger = require('../logger');
class ChannelBase {
id: string;
clients: MHSClient[]|ClientBase[] = [];
constructor(id: string) {
this.id = id;
console.log('channel created');
logger.accessLog.info('Channel Created', {channelId: id});
}
addClient(client: MHSClient|ClientBase) {
console.log(client.data)
if (this.clientExists(client.id)) {
console.log('client already exits in channel');
logger.errorLog.info('Client already exits in channel', {channelId: this.id, clientId: client.id});
return {'status': 'notice', 'message': 'client aleady exists in channel'};
} else {
this.clients.push(client);
console.log('added client to channel');
logger.accessLog.info('Added client to channel', {channelId: this.id, clientId: client.id});
return {'status': 'success', 'message': 'client added'};
}
}
@ -34,12 +37,13 @@ class ChannelBase {
for (let client of this.clients) {
if (client != from) {
client.ws.send(message);
console.log(`sent to ${client.id}: %s`, message);
console.log(message);
logger.accessLog.info(`sent to ${client.id}: `, {message: message});
} else {
console.log('client is same as sender');
logger.accessLog.info(`client is same as sender: ${client.id} - `, {message: message});
}
}
return {'status': 'success', 'message': `message broadcast complete`};
}
};

View File

@ -2,17 +2,20 @@ import ClientBase from '../../clients/clientBase';
import MHSClient from '../../clients/sites/mhsClient';
import ChannelBase from '../channelBase';
var logger = require('../../logger');
class MHSChannel extends ChannelBase {
broadcastMessage(from: ClientBase|MHSClient|null, message: string) {
for (let client of this.clients) {
if (client != from && client.data.user_type == 'teacher') {
client.ws.send(message);
console.log(`sent to ${client.id}: %s`, message);
console.log(message);
logger.accessLog.info(`sent to ${client.id}: `, {message: message});
} else {
console.log('client is same as sender and/or not a teacher.');
logger.accessLog.info(`client is same as sender: ${client.id} - `, {message: message});
}
}
return {'status': 'success', 'message': `message broadcast complete`};
}
};