All files / botbuilder-unit/spec conversationMockSpec.js

88.24% Statements 30/34
100% Branches 0/0
86.67% Functions 13/15
88.24% Lines 30/34
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 981x 1x 1x 1x 1x 1x   1x 1x     1x 1x     1x       1x 1x     1x 1x     1x 1x       1x         1x                       1x     1x           1x 1x 1x       1x       1x     1x         1x                       1x     1x            
const botFactory = require('./lib/botFactory');
const unit = require('../');
describe('Test Suite for Conversation Mock class', function () {
  it('Test Conversation Mock in simple dialog', (done) => {
    let bot = botFactory();
    let mock = new unit.ConversationMock([
      (session, args, next) => {
        session.send('Hello!');
        next()
      },
      (session, args, next) => {
        session.send('Second call');
        next()
      },
      (session, args, next) => {
        session.endConversation('Third call');
 
      },
      (session, args, next) => {
        session.send('Forth call');
        next()
      },
      (session, args, next) => {
        session.send('Fifth call');
        next()
      },
      (session, args, next) => {
        session.send('Sixth call');
        session.endConversation();
      }
    ]);
 
    bot.dialog('/test', [
      mock.getListener(),
      mock.getListener(),
      mock.getListener()
    ]);
    let script = [
      {user: 'Hi'},
      {bot: 'Hello!'},
      {bot: 'Second call'},
      {bot: 'Third call'},
      {endConversation: true},
      {user: 'Hi!'},
      {bot: 'Forth call'},
      {bot: 'Fifth call'},
      {bot: 'Sixth call'},
      {endConversation: true}
    ];
    unit(bot, script, {
      title: 'Test Conversation Mock in simple dialog'
    }).then(function () {
      done();
    }, function (error) {
      fail('Error during testing ConversationMock:' + error.toString());
      done();
    })
  });
  it('Test Conversation Mock sendMessagesStep', (done) => {
    let bot = botFactory();
    let mock = new unit.ConversationMock([
      unit.ConversationMock.sendMessagesStep([
        'Hello!',
        'Second call'
      ], session => session.endConversation('Third call')),
      unit.ConversationMock.sendMessagesStep([
        'Forth call',
        'Fifth call'
      ], session => session.endConversation('Sixth call'))
    ]);
 
    bot.dialog('/test', [
      mock.getListener(),
      mock.getListener(),
      mock.getListener()
    ]);
    let script = [
      {user: 'Hi'},
      {bot: 'Hello!'},
      {bot: 'Second call'},
      {bot: 'Third call'},
      {endConversation: true},
      {user: 'Hi!'},
      {bot: 'Forth call'},
      {bot: 'Fifth call'},
      {bot: 'Sixth call'},
      {endConversation: true}
    ];
    unit(bot, script, {
      title: 'Test Conversation Mock in simple dialog'
    }).then(function () {
      done();
    }, function (error) {
      fail('Error during testing ConversationMock:' + error.toString());
      done();
    })
  });
})