import * as _ from 'lodash'; import * as Promise from 'bluebird'; import * as Responses from './responses'; import { PlatformMiddleware } from '../types/platform'; import { IncomingMessage, Message } from '../types/message'; import { User, BasicUser } from '../types/user'; import Tester from './tester'; import Botler from '../bot'; export default class TestPlatform implements PlatformMiddleware { public testers: { [key: string]: Tester } = {}; private bot: Botler; constructor(bot: Botler) { this.bot = bot; return this; } public start() { return Promise.resolve(this); } public stop() { return Promise.resolve(this); } public send (user: U, message: M): Promise { const test = this.testers[user.id]; test.receive(message); return Promise.resolve(this); } public receive(userId: string, message: IncomingMessage): Promise { const user: BasicUser = { id: userId, platform: 'testing', _platform: this, }; return this.bot.processMessage(user, message); } public newTest(userId: string = `test-${_.random(999999)}`): Tester { const instance = new Tester(this, userId); this.testers[userId] = instance; return instance; } }