Giter Club home page Giter Club logo

bottester's People

Contributors

bilby91 avatar microsoftly avatar santiagodoldan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bottester's Issues

Condition based test

How can i put condition on the behalf of message
and check conditions based response
example
.sendMessageToBot('XYZ','ABC' || 'BCD')
if(bot respone === 'ABC') {
.sendMessageToBot('PQR','PQR')
} else {
.sendMessageToBot('TUV','TUV')
}
Please help

Separating tests

Hi, I am new to bottester. I wonder if there are ways to separate the code with the tests, maybe there are some ways to connect to the existing bot to test it or reuse part of the code?

As seen in the tests:

    it('can handle a single response', () => {
        bot.dialog('/', (session) => {
            session.send('hello!');
        });

        const botTester = new BotTester(bot)
            .sendMessageToBot('Hola!', 'hello!');

        return botTester.runTest();
    });

The part bot.dialog('/', (session) => { is already written in app.js, is there anyway for me not to write everything twice?

Add support for random order expectations

At the moment the array of messages that is used to check responses against a message is used in the order the user provides the message. In some situations, a bot can respond to a message with multiple messages but the order of the messages is not known before hand. I think it would be a good idea to support random order of message, in other words, expect that all the messages are sent from the bot to the user but don't force the same order.

What do you think @microsoftly ?

Test case

Hi i am new with bot any body please provide me detail description how to use this module in unit testing or please provide a working example

add testing for failed cases

right now the tests only check for passing cases. This can produce false positives. Create tests ensuring correct failure behavior

Adaptivecards support

Now with adaptive cards being available and consoleconnector not supporting adaptivecards is there a way to automate testing for these features?

Show custom error messages

For example when comparing simple texts it shows

AssertionError: expected [ 'a' ] to include 'b.'

instead of

AssertionError: Bot should have responded with 'a', but was 'b'

Error

'node_modules' is not recognized as an internal or external command,

Add filter for outgoing messages

It would be a good idea to be able to configure a filter function for outgoing message. For example, when ending a conversation, the botbuilder sends a silent menssage with type: 'endOfConversation' that I don't want to match.

@types/bluebird is required

Installing just BotTester and then compiling tests in Typescript throws the following

node_modules/bot-tester/dist/BotTester.d.ts:1:23 - error TS2688: Cannot find type definition file for 'bluebird'.

1 /// <reference types="bluebird" />

Workaround: npm install --save-dev @types/bluebird

Send args with sendMessageToBot() ?

Hello there, was wondering if there was any way to send arguments alongside the message with .sendMessageToBot();

something like the following:

const msg = {
    message: 'hello',
    args: { entities: ['bla1', 'bla2'], intents: 'test' }
}

.sendMessageToBot(msg, "Bot says hello to you too");

I am using args in my dialogs to handle logic

(session, args, next) => {
    if (args.something) {
        do something 
    }
    else {
        do something else
    }
}

Thank you.

Test with custom root dialog id

Hello,

Is it possible to change the root id of the dialogs? In the README examples, '/' is always used as the id

bot.dialog('/',...

I receive the below error if I don't initialize a dialog with '/'

Uncaught Error: Dialog[*:/] not found.

Thanks

message is missing address or serviceUrl

Hi,

I've been using BotTester to test my bot, and it seems to be working pretty well, however, BotBuilder keeps raising the error ChatConnector: send - message is missing address or serviceUrl.. It doesn't interfere with the running of my tests, but is a bit noisy. Any ideas where I might be going wrong? (p.s. Node is not my first language - I'm primarily a Rubyist)

require('dotenv').config()

var _wastebot = require('../lib/bot');

var _botBuilder = require('botbuilder');
var _botTester = require('bot-tester');

var nock = require('nock');

const connector = new _botTester.TestConnector({
  defaultAddress: _botBuilder.IAddress
});

describe('bot', function() {
  let bot;
  let botTester;
  
  beforeEach(() => {
    bot = _wastebot._private.bot
    botTester = new _botTester.BotTester(bot)
  });
  
  it('sends a welcome message', () => {
    return botTester
      .sendMessageToBot('Hello!', 'Welcome to Wastebot.', 'What is your postcode?')
      .runTest();
  });
  
  it('only supports postcodes in Lichfield District', () => {
    nock('http://api.postcodes.io')
      .get('/postcodes/sw1a1aa')
      .reply(200, {
        result: {
          codes: {
            admin_district: 'hahajajaaak'
          }
        }
      })
    
    return botTester
      .sendMessageToBot('sw1a1aa', 'Sorry, this service is for residents of Lichfield District only')
      .runTest();
  });
  
  it('returns a list of addresses', () => {
    nock('http://api.postcodes.io')
      .get('/postcodes/sw1a1aa')
      .reply(200, {
        result: {
          codes: {
            admin_district: 'E07000194'
          }
        }
      })
    
    nock('https://api.getaddress.io')
      .get('/v2/uk/sw1a1aa')
      .query(true)
      .reply(200, {
        Addresses: [
          [
            '123 Test Road',
            '',
            '',
            'Testtown',
            'Testshire'
          ],
          [
            '125 Test Road',
            '',
            '',
            'Testtown',
            'Testshire'
          ]
        ]
      })
    
    return botTester
      .sendMessageToBot('Hello!', 'Welcome to Wastebot.', 'What is your postcode?')
      .sendMessageToBot('sw1a1aa', 'Choose your address from the list below (1. 123 Test Road, Testtown, Testshire or 2. 125 Test Road, Testtown, Testshire)')
      .runTest();
  });

});

How to test Adaptive Cards

I am trying to test an AdaptiveCard. I am using the example from the documentation to create the card.

    var msg = new builder.Message(session);
    msg.attachmentLayout(builder.AttachmentLayout.carousel)
    msg.attachments([
        new builder.HeroCard(session)
            .title("Classic White T-Shirt")
            .subtitle("100% Soft and Luxurious Cotton")
            .text("Price is $25 and carried in sizes (S, M, L, and XL)")
            .images([builder.CardImage.create(session, 'http://petersapparel.parseapp.com/img/whiteshirt.png')])
            .buttons([
                builder.CardAction.imBack(session, "buy classic white t-shirt", "Buy")
            ]),
        new builder.HeroCard(session)
            .title("Classic Gray T-Shirt")
            .subtitle("100% Soft and Luxurious Cotton")
            .text("Price is $25 and carried in sizes (S, M, L, and XL)")
            .images([builder.CardImage.create(session, 'http://petersapparel.parseapp.com/img/grayshirt.png')])
            .buttons([
                builder.CardAction.imBack(session, "buy classic gray t-shirt", "Buy")
            ])
    ]);

The example in the BotTester documentation says to test against an adaptive card object refrenece. My problem is I can't create the Adaptive card because I don't have a session object.

defaultAddress is not working when passing plain strings to sendMessageToBot function

  const address = {
        channelId: 'slack',
        user: { id: 'UXXX', name: 'Santiago' },
        bot: { id: 'BXXX', name: 'Suttna' },
        conversation: { id: 'TXXX:CXXX' }
  }

  bot.dialog('/', (session: Session) => {
    bot.send("Bye")
  })

  const message = new Message().address(address).text("Bye").toMessage()

  return new BotTester(bot, { defaultAddress: address })
    .sendMessageToBot("Hello", message)
    .runTest()

In the above scenario, the expectation fails because it doesn't use given address, it uses always this one https://github.com/microsoftly/BotTester/blob/master/src/config.ts#L25.

Here is a hotfix for this issue #25

Add support for additional test libraries

If you want support added for a library that we don't already support, please comment below. We will also happily accept PRs.

Once a new test library is accepted, I will open up a new issue to track it

Add support for asynchronous (not batched) messages

@microsoftly

We have the following case that is not working at the moment.

  1. Send a message to bot
  2. Bot starts 3 dialogs with 3 different users
  3. I would like to expect the three messages under the same sendMessageToBot since the message that is sent to the bot is the one that triggers the three new dialogs.

Test prompt objects other than text

I would like to test the bot ability to respond with choices prompts and be able to answer those prompts.
So for:

var salesData = {
    "west": {
        units: 200,
        total: "$6,000"
    },
    "central": {
        units: 100,
        total: "$3,000"
    },
    "east": {
        units: 300,
        total: "$9,000"
    }
};

bot.dialog('getSalesData', [
    function (session) {
        builder.Prompts.choice(session, "Which region would you like sales for?", salesData); 
    },
    function (session, results) {
        if (results.response) {
            var region = salesData[results.response.entity];
            session.send(`We sold ${region.units} units for a total of ${region.total}.`); 
        } else {
            session.send("OK");
        }
    }
]);

do:

var expectedChoicePrompt  = PromptChoice("Which region would you like sales for?", salesData)
new BotTester(bot)
            .sendMessageToBot("hello", expectedChoicePrompt)
            .sendMessageToBot("central", " We sold 100 units for a total of \"300$\".")
            .runTest();

Ignore responses when sending a message

Hello!

We came up with another use case that could be added to the api. We have some test cases were we don't care about the X replied messages from the bot.

Something like this:

new BotTester()
  .sendMessageToBot("Hey", "I", "dont", "care", "about", "this", "messages")
  .sendMessageToBot("Bye" "But I care about this message")

I was thinking that maybe we could add something like:

new BotTester()
  .sendMessageToBotAndIgnoreResponses("Hey", 6)
  .sendMessageToBot("Bye" "But I care about this message")

What do you think @microsoftly ?

CC @santiagodoldan

How to test our own dialogs,prompts

@microsoftly, I looked over code samples [1] from your README.md file. and those are really helpful to get started. But, I have a doubt about testing my own dialogs or prompts which has a specific conversation flow. I see in your examples you are creating a sample dialog '/' with prompts & and testing it with BotTester but how do we test how our actual bot is responding the way we want if sample data/input is provided.

[1]

    it('can test prompts', () => {
        bot.dialog('/', [(session) => {
            new Prompts.text(session, 'Hi there! Tell me something you like');
        }, (session, results) => {
            session.send(`${results.response} is pretty cool.`);
            new Prompts.text(session, 'Why do you like it?');
        }, (session) => session.send('Interesting. Well, that\'s all I have for now')]);

        return new BotTester(bot)
            .sendMessageToBot('Hola!', 'Hi there! Tell me something you like')
            .sendMessageToBot('The sky', 'The sky is pretty cool.', 'Why do you like it?')
            .sendMessageToBot('It\'s blue', 'Interesting. Well, that\'s all I have for now')
            .runTest();
    });

Testing other dialogues

Hello,

We have a fairly complex bot set up with many dialogues, middleware, etc... I'd love a simple way of having a set of questions and answers that i can run through this test harness, but it appears as though every dialogue in the documentation is created inside of the harness. Is it straightforward to have the harness use the full extent of dialogues we've created?

Thanks

Getting false positives

Hello,

I'm trying to use BotTester to test one our internal libraries and I'm having some issues. All my specs seem to run fine when I add failing cases. It seems that the runner finishes before the test can actually execute. If I add the done function to it it runs correctly and failure is shown.

Anyone having the same problem ?

Add .timeout option

e.g.

new BotTester(bot)
  .sendMessageToBot('you only give responses after a delay')
  .timeout(1000)
  .sendMessageToBot('hi', 'hello! thanks for waiting')
  .runTest()

Added regex support on expectedResponses

I'm trying to integrate a regexp type of message so that you can test that the bot response matched the regexp.

I'm thinking of subclassing the Message class and adding a regexp property so that the match is done against that property instead of the text.

Do you think this can be useful of have another alternative ? From what I saw all is based on the IMessage interface so subclassing seems the correct way at first glance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.