UNPKG

3.19 kBTypeScriptView Raw
1/// <reference types="bluebird" />
2import * as Promise from 'bluebird';
3import { IAddress, IMessage, Session, UniversalBot } from 'botbuilder';
4import { IConfig } from './config';
5import { PossibleExpectedMessageType } from './ExpectedMessage';
6export declare type checkSessionFunction = (s: Session) => void;
7/**
8 * Test builder and runner for botbuilder bots
9 */
10export declare class BotTester {
11 private bot;
12 private defaultAddress;
13 private sessionLoader;
14 private messageService;
15 private testSteps;
16 /**
17 *
18 * @param bot bot that will be tested against
19 * @param options (optional) options to pass to bot. Sets the default address and test timeout
20 */
21 constructor(bot: UniversalBot, options?: IConfig);
22 /**
23 * executes each test step serially
24 */
25 runTest(): Promise<any>;
26 /**
27 * loads a session associated with an address and passes it to a user defined function
28 * @param sessionCheckerFunction function passed in to inspect message
29 * @param address (Optional) address of the session to load. Defaults to bot's default address if not defined
30 */
31 checkSession(sessionCheckerFunction: checkSessionFunction, address?: IAddress): BotTester;
32 /**
33 * sends a message to a bot and compares bot responses against expectedResponsess. Expected responses can be a variable number of args,
34 * each of which can be a single expected response of any PossibleExpectedMessageType or a collection of PossibleExpectedMessageType
35 * that mocks a randomly selected response by the bot
36 * @param msg message to send to bot
37 * @param expectedResponses (Optional) responses the bot-tester framework checks against
38 */
39 sendMessageToBot(msg: IMessage | string, ...expectedResponses: (PossibleExpectedMessageType | PossibleExpectedMessageType[])[]): BotTester;
40 sendMessageToBotIgnoringResponseOrder(msg: IMessage | string, ...expectedResponses: (PossibleExpectedMessageType | PossibleExpectedMessageType[])[]): BotTester;
41 /**
42 * sends a message to the bot. This should be used whenever session.save() is used without sending a reply to the user. This exists due
43 * to a limitation in the current implementation of the botbuilder framework
44 *
45 * @param msg message to send to bot
46 */
47 sendMessageToBotAndExpectSaveWithNoResponse(msg: IMessage | string): BotTester;
48 /**
49 * Works exactly like Promise's .then function, except that the return value is not passed as an arg to the next function (even if its
50 * another .then)
51 * @param fn some function to run
52 */
53 then(fn: Function): BotTester;
54 /**
55 * Waits for the given delay between test steps.
56 * @param delayInMiliseconds time to wait in milliseconds
57 */
58 wait(delayInMilliseconds: number): BotTester;
59 private convertToIMessage(msg);
60 /**
61 * Packages the expected messages into an ExpectedMessage collection to be handed off to the MessageService's sendMessageToBot function
62 * @param message message to be sent to bot
63 * @param expectedResponses expected responses
64 */
65 private sendMessageToBotInternal(message, expectedResponses, ignoreOrder?);
66}