11//```javascript
2- import { IAddress , IMessage , Message , Prompts , Session , UniversalBot } from 'botbuilder' ;
2+ import { IAddress , IMessage , Message , Prompts , Session , UniversalBot } from 'botbuilder' ;
33import * as chai from 'chai' ;
44import * as chaiAsPromised from 'chai-as-promised' ;
5- import { BotTester } from './../../../src/BotTester' ;
6- import { TestConnector } from './../../../src/TestConnector' ;
7- import { getAdaptiveCard , getAdaptiveCardAttachment , getAdaptiveCardMessage } from './../../adaptiveCardProvider' ;
5+ import { BotTester } from './../../../src/BotTester' ;
6+ import { TestConnector } from './../../../src/TestConnector' ;
7+ import { getAdaptiveCard , getAdaptiveCardAttachment , getAdaptiveCardMessage } from './../../adaptiveCardProvider' ;
88
99chai . use ( chaiAsPromised ) ;
1010const expect = chai . expect ;
@@ -105,12 +105,12 @@ describe('BotTester', () => {
105105 bot . dialog ( '/' , [ ( session ) => {
106106 new Prompts . text ( session , 'What would you like to set data to?' ) ;
107107 } , ( session , results ) => {
108- session . userData = { data : results . response } ;
108+ session . userData = { data : results . response } ;
109109 session . save ( ) ;
110110 } ] ) ;
111111
112112 return new BotTester ( bot )
113- . sendMessageToBot ( 'Start this thing!' , 'What would you like to set data to?' )
113+ . sendMessageToBot ( 'Start this thing!' , 'What would you like to set data to?' )
114114 . sendMessageToBotAndExpectSaveWithNoResponse ( 'This is data!' )
115115 . checkSession ( ( session ) => {
116116 expect ( session . userData ) . not . to . be . null ;
@@ -152,16 +152,18 @@ describe('BotTester', () => {
152152//# Address/multiuser cases
153153//```javascript
154154 describe ( 'Address/multi user' , ( ) => {
155- const defaultAddress = { channelId : 'console' ,
156- user : { id : 'customUser1' , name : 'A' } ,
157- bot : { id : 'customBot1' , name : 'Bot1' } ,
158- conversation : { id : 'customUser1Conversation' }
155+ const defaultAddress = {
156+ channelId : 'console' ,
157+ user : { id : 'customUser1' , name : 'A' } ,
158+ bot : { id : 'customBot1' , name : 'Bot1' } ,
159+ conversation : { id : 'customUser1Conversation' }
159160 } ;
160161
161- const user2Address = { channelId : 'console' ,
162- user : { id : 'user2' , name : 'B' } ,
163- bot : { id : 'bot' , name : 'Bot' } ,
164- conversation : { id : 'user2Conversation' }
162+ const user2Address = {
163+ channelId : 'console' ,
164+ user : { id : 'user2' , name : 'B' } ,
165+ bot : { id : 'bot' , name : 'Bot' } ,
166+ conversation : { id : 'user2Conversation' }
165167 } ;
166168
167169 beforeEach ( ( ) => {
@@ -201,7 +203,7 @@ describe('BotTester', () => {
201203
202204//## Can have a default address assigned to the bot
203205//```javascript
204- // the bot can have a default address that messages are sent to. If needed, the default address can be ignored by sending an IMessage
206+ // the bot can have a default address that messages are sent to. If needed, the default address can be ignored by sending an IMessage
205207 it ( 'Can have a default address assigned to it and communicate to multiple users' , ( ) => {
206208 const askForUser1Name = new Message ( )
207209 . text ( 'What is my name?' )
@@ -224,8 +226,8 @@ describe('BotTester', () => {
224226 . toMessage ( ) ;
225227
226228 // when testing for an address that is not the default for the bot, the address must be passed in
227- return new BotTester ( bot , { defaultAddress } )
228- // because user 1 is the default address, the expected responses can be a string
229+ return new BotTester ( bot , { defaultAddress} )
230+ // because user 1 is the default address, the expected responses can be a string
229231 . sendMessageToBot ( askForUser1Name , 'A' )
230232 . sendMessageToBot ( 'What is my name?' , user1ExpectedResponse )
231233 . sendMessageToBot ( askForUser1Name , user1ExpectedResponse )
@@ -238,10 +240,11 @@ describe('BotTester', () => {
238240//# Can test batch responses
239241//```javascript
240242 it ( 'can handle batch responses' , ( ) => {
241- const CUSTOMER_ADDRESS : IAddress = { channelId : 'console' ,
242- user : { id : 'userId1' , name : 'user1' } ,
243- bot : { id : 'bot' , name : 'Bot' } ,
244- conversation : { id : 'user1Conversation' }
243+ const CUSTOMER_ADDRESS : IAddress = {
244+ channelId : 'console' ,
245+ user : { id : 'userId1' , name : 'user1' } ,
246+ bot : { id : 'bot' , name : 'Bot' } ,
247+ conversation : { id : 'user1Conversation' }
245248 } ;
246249
247250 const msg1 = new Message ( )
@@ -258,7 +261,7 @@ describe('BotTester', () => {
258261 bot . send ( [ msg1 , msg2 ] ) ;
259262 } ) ;
260263
261- return new BotTester ( bot , { defaultAddress : CUSTOMER_ADDRESS } )
264+ return new BotTester ( bot , { defaultAddress : CUSTOMER_ADDRESS } )
262265 . sendMessageToBot ( 'anything' , 'hello' , 'there' )
263266 . runTest ( ) ;
264267 } ) ;
@@ -282,6 +285,44 @@ describe('BotTester', () => {
282285 } ) ;
283286//```
284287
288+ //# Can test using Function
289+ //```javascript
290+ it ( 'accepts Function' , ( ) => {
291+ bot . dialog ( '/' , ( session : Session ) => {
292+ session . send ( 'hello!' ) ;
293+ session . send ( '12' ) ;
294+ } ) ;
295+
296+ const botTester = new BotTester ( bot )
297+ . sendMessageToBot ( 'Hi' , ( message : IMessage ) => {
298+ if ( message . text === 'hello!' ) {
299+ return true ;
300+ }
301+ } , ( message : IMessage ) => {
302+ if ( parseInt ( message . text , 0 ) % 2 === 0 ) {
303+ return true ;
304+ }
305+ } ) ;
306+
307+ return botTester . runTest ( ) ;
308+ } ) ;
309+ //```
310+
311+ //```javascript
312+ it ( 'accepts Function that return string' , ( ) => {
313+ bot . dialog ( '/' , ( session : Session ) => {
314+ session . send ( 'hello!' ) ;
315+ } ) ;
316+
317+ const botTester = new BotTester ( bot )
318+ . sendMessageToBot ( 'Hi' , ( message : IMessage ) => {
319+ return message . text ;
320+ } ) ;
321+
322+ return botTester . runTest ( ) ;
323+ } ) ;
324+ //```
325+
285326//# variable # args can have mixed type
286327//```javascript
287328 it ( 'rest params can have mixed type' , ( ) => {
@@ -367,7 +408,7 @@ describe('BotTester', () => {
367408 const ignoreHowMessage = ( message ) => ! message . text . includes ( 'how' ) ;
368409 const ignoreAreMessage = ( message ) => ! message . text . includes ( 'are' ) ;
369410
370- return new BotTester ( bot , { messageFilters : [ ignoreHowMessage , ignoreAreMessage ] } )
411+ return new BotTester ( bot , { messageFilters : [ ignoreHowMessage , ignoreAreMessage ] } )
371412 . sendMessageToBot ( 'intro' , 'hello' , 'you?' )
372413 . runTest ( ) ;
373414 } ) ;
@@ -393,7 +434,7 @@ describe('BotTester', () => {
393434 it ( 'change timeout time' , ( done ) => {
394435 const timeout = 750 ;
395436 bot . dialog ( '/' , ( session ) => {
396- setTimeout ( ( ) => session . send ( 'hi there' ) , timeout * 2 ) ;
437+ setTimeout ( ( ) => session . send ( 'hi there' ) , timeout * 2 ) ;
397438 } ) ;
398439
399440 expect ( new BotTester ( bot )
0 commit comments