diff --git a/README.md b/README.md index d872b91..0dd3e7b 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,22 @@ config can be set one of 2 ways: 1. creating a bot-tester.json file in the root directory of your project. 2. passing in a config object into the options param, which is the last, when creating a BotTester instance + Passing in the config overrides any default values or values set by bot-tester.json. At the moment, the options are: -```javascript +```typescript { defaultAddress: botbuilder.IAddress, timeout: number // in milliseconds + // each filter returns false for messages that the BotTester should ignore + messageFilters: ((message:IMessage) => boolean)[], + ignoreTypingEvent: boolean, + ignoreEndOfConversationEvent: boolean } ``` if timeout is defined, then a particular ```runTest()``` call will fail if it does not receive each expected message within the timeout period of time set in the options. +additionally, config can be set by using the config updating options in the build chain, documented below in the example use + For a more in depth view, check out [the Bot Tester Framework Config doc](https://microsoftly.github.io/BotTester/interfaces/_config_.iconfig.html) # Example Usage ```javascript @@ -357,3 +364,67 @@ describe('BotTester', () => { .runTest(); }); ``` + +# can apply one or more message filters in the BotTester options for messages to ignore +``` javascript + it('can apply one or more message filters in the BotTester options for messages to ignore', () => { + bot.dialog('/', (session) => { + session.send('hello'); + session.send('how'); + session.send('are'); + session.send('you?'); + }); + + const ignoreHowMessage = (message) => !message.text.includes('how'); + const ignoreAreMessage = (message) => !message.text.includes('are'); + + return new BotTester(bot, { messageFilters: [ignoreHowMessage, ignoreAreMessage]}) + .sendMessageToBot('intro', 'hello', 'you?') + .runTest(); + }); +``` + +# can modify BotTester options +``` javascript + describe('can modifiy options in line in builder chain', () => { + it('add a message filter', () => { + bot.dialog('/', (session) => { + session.send('hello'); + session.send('there'); + session.send('green'); + }); + + return new BotTester(bot) + .addMessageFilter((msg) => !msg.text.includes('hello')) + .addMessageFilter((msg) => !msg.text.includes('there')) + .sendMessageToBot('hey', 'green') + .runTest(); + }); + + it('change timeout time', (done) => { + const timeout = 750; + bot.dialog('/', (session) => { + setTimeout(() => session.send('hi there'), timeout * 2 ); + }); + + expect(new BotTester(bot) + .setTimeout(timeout) + .sendMessageToBot('hey', 'hi there') + .runTest() + ).to.be.rejected.notify(done); + }); + + it('can ignore typing events', () => { + bot.dialog('/', (session) => { + session.send('hello'); + session.sendTyping(); + session.send('goodbye'); + }); + + return new BotTester(bot) + .ignoreTypingEvent() + .sendMessageToBot('hey', 'hello', 'goodbye') + .runTest(); + }); + }); +``` diff --git a/docs/assets/js/search.js b/docs/assets/js/search.js index 636b530..f8620f9 100644 --- a/docs/assets/js/search.js +++ b/docs/assets/js/search.js @@ -1,3 +1,3 @@ var typedoc = typedoc || {}; typedoc.search = typedoc.search || {}; - typedoc.search.data = {"kinds":{"1":"External module","65536":"Type literal"},"rows":[{"id":0,"kind":65536,"name":"__type","url":"classes/_testconnector_.testconnector.html#oneventhandler.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"TestConnector\".TestConnector.onEventHandler"},{"id":1,"kind":65536,"name":"__type","url":"classes/_testconnector_.testconnector.html#oninvokehandler.__type-1","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"TestConnector\".TestConnector.onInvokeHandler"},{"id":2,"kind":65536,"name":"__type","url":"modules/_messageservice_.html#bottousermessagecheckerfunction.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"MessageService\".botToUserMessageCheckerFunction"},{"id":3,"kind":65536,"name":"__type","url":"classes/_sessionservice_.sessionservice.html#currentsessionloadresolver.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"SessionService\".SessionService.currentSessionLoadResolver"},{"id":4,"kind":65536,"name":"__type","url":"modules/_bottester_.html#checksessionfunction.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"BotTester\".checkSessionFunction"},{"id":5,"kind":1,"name":"\"index\"","url":"modules/_index_.html","classes":"tsd-kind-external-module"}]}; \ No newline at end of file + typedoc.search.data = {"kinds":{"1":"External module","65536":"Type literal"},"rows":[{"id":0,"kind":65536,"name":"__type","url":"classes/_testconnector_.testconnector.html#oneventhandler.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"TestConnector\".TestConnector.onEventHandler"},{"id":1,"kind":65536,"name":"__type","url":"classes/_testconnector_.testconnector.html#oninvokehandler.__type-1","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"TestConnector\".TestConnector.onInvokeHandler"},{"id":2,"kind":65536,"name":"__type","url":"modules/_config_.html#messagefilter.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"config\".MessageFilter"},{"id":3,"kind":65536,"name":"__type","url":"modules/_messageservice_.html#bottousermessagecheckerfunction.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"MessageService\".botToUserMessageCheckerFunction"},{"id":4,"kind":65536,"name":"__type","url":"classes/_sessionservice_.sessionservice.html#currentsessionloadresolver.__type","classes":"tsd-kind-type-literal tsd-parent-kind-property tsd-is-not-exported","parent":"\"SessionService\".SessionService.currentSessionLoadResolver"},{"id":5,"kind":65536,"name":"__type","url":"modules/_bottester_.html#checksessionfunction.__type","classes":"tsd-kind-type-literal tsd-parent-kind-type-alias tsd-is-not-exported","parent":"\"BotTester\".checkSessionFunction"},{"id":6,"kind":1,"name":"\"index\"","url":"modules/_index_.html","classes":"tsd-kind-external-module"}]}; \ No newline at end of file diff --git a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html index fb1c32e..cbb5966 100644 --- a/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html +++ b/docs/classes/_assertionlibraries_chaiexpectation_.chaiexpectation.html @@ -130,7 +130,7 @@
loads a session associated with an address and passes it to a user defined function
-function passed in to inspect message
-(Optional) address of the session to load. Defaults to bot's default address if not defined
-executes each test step serially
+Initializes the MessegeService here to allow config changes to accumulate
sends a message to a bot and compares bot responses against expectedResponsess. Expected responses can be a variable number of args, - each of which can be a single expected response of any PossibleExpectedMessageType or a collection of PossibleExpectedMessageType - that mocks a randomly selected response by the bot
-message to send to bot
-(Optional) responses the bot-tester framework checks against
-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 - to a limitation in the current implementation of the botbuilder framework
-message to send to bot
-expected responses
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 - another .then)
-some function to run
-Waits for the given delay between test steps.
-Test builder/runner suite. After any of these are called, no functions in IConfigModified should be accessible
+loads a session associated with an address and passes it to a user defined function
+function passed in to inspect message
+(Optional) address of the session to load. Defaults to bot's default address if not defined
+executes each test step serially.
+sends a message to a bot and compares bot responses against expectedResponsess. Expected responses can be a variable number of args, + each of which can be a single expected response of any PossibleExpectedMessageType or a collection of PossibleExpectedMessageType + that mocks a randomly selected response by the bot
+message to send to bot
+(Optional) responses the bot-tester framework checks against
+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 + to a limitation in the current implementation of the botbuilder framework
+message to send to bot
+same as sendMessageToBot, but the order of responses is not checked. This will cause the test to hang until all messages it expects + are returned
+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 + another .then)
+some function to run
+Waits for the given delay between test steps.
+methods that the Test builder can call to edit/modify the options. These can be called until any of the IBotTester method are called.
+adds a message filter to the options.
+message filter to add
+adds prebuilt filter to ignore endOfConversationEvent
+adds prebuilt filter to ignore typing event
+sets the timeout time that the BotTester will wait for any particular message before failing
+ignores end of conversation event messages
+ignores typing event messages
+filters for messages that the BotTester framework should use
+Returns true if a message
+
toEqual
Parameters
@@ -276,7 +276,7 @@toInclude
Parameters
@@ -330,6 +330,9 @@Returns void "assertionLibraries/IExpectation"
+
+ "builtInMessageFilters"
+
"config"
diff --git a/docs/classes/_bottester_.bottester.html b/docs/classes/_bottester_.bottester.html
index 5f0f331..6b2c6ac 100644
--- a/docs/classes/_bottester_.bottester.html
+++ b/docs/classes/_bottester_.bottester.html
@@ -82,6 +82,13 @@
+
@@ -96,7 +103,7 @@ - bot
- - default
Address
+ - config
- message
Service
- session
Loader
- test
Steps
@@ -105,13 +112,17 @@
-
-
-
-
-
-
-
-
-
-
-
bot: UniversalBot
-
- defaultAddress: IAddress
+
+ config: IConfig
@@ -188,7 +187,7 @@ Service: MessageService
Hierarchy
+Implements
++- IBotTester
+ - IOptionsModifier
+
+Index
Constructors
Properties
Properties
Methods
+- add
MessageFilter
- check
Session
- convert
ToIMessage
+ - ignore
EndOfConversationEvent
+ - ignore
TypingEvent
- run
Test
- send
MessageToBot
- send
MessageToBotAndExpectSaveWithNoResponse
- send
MessageToBotIgnoringResponseOrder
- send
MessageToBotInternal
+ - set
Timeout
- then
- wait
@@ -131,28 +142,16 @@constructor
Parameters
bot: UniversalBot
-bot that will be tested against
-Default value options: IConfig = config
-(optional) options to pass to bot. Sets the default address and test timeout
-Returns BotTester
@@ -168,17 +167,17 @@Private bot
Private defaultAddress
-Private config
+Private messageService
message