All files / botbuilder-unit/src ConversationMock.js

100% Statements 16/16
75% Branches 3/4
100% Functions 6/6
100% Lines 16/16
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        6x 6x     2x 14x 20x 2x   18x 18x 18x                     2x 4x 4x 8x   4x 4x       2x
/* jslint es6 */
'use strict';
 
function ConversationMock(steps) {
  this.steps = steps;
  this.currentStep = 0;
 
}
ConversationMock.prototype.getListener = function ( ) {
  return (session, args, next) => {
    if ( this.currentStep >= this.steps.length) {
      throw new Error("Out of range for mocked steps  ");
    }
    let step = this.steps[this.currentStep];
    this.currentStep++;
    step(session,args,next);
 
  };
}
 
/**
 * Creates a step for waterfall dialog
 * @param messages array, these messages will be sent to user
 * @param afterFunc callable, will be called after messages will be sent
 * @returns {Function}
 */
ConversationMock.sendMessagesStep = function (messages, afterFunc) {
  return (session, args, next) => {
    messages.forEach((item) => {
      session.send(item);
    });
    Eif (afterFunc) {
      afterFunc.call(this, session, args, next)
    }
  };
}
module.exports = ConversationMock;