All files / botbuilder-unit/src ScriptStepFactory.js

100% Statements 22/22
100% Branches 17/17
100% Functions 1/1
100% Lines 22/22
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      2x 2x 2x 2x 2x 2x 500x   500x 288x   212x 212x 174x   38x 38x 16x   22x 22x 14x   8x 8x 6x   2x  
/* jslint es6 */
'use strict';
 
const BotMessage = require('./messages/BotMessage');
const CustomMessage = require('./messages/CustomMessage');
const UserMessage = require('./messages/UserMessage');
const SessionMessage = require('./messages/SessionMessage');
const SetDialogMessage = require('./messages/SetDialogMessage');
module.exports = function MessageFactory(step, config, bot, logReporter, prevStepPromise) {
  let isBot = config.bot || config.endConversation || config.typing
    || config.attachmentLayout || config.attachments;
  if (isBot) {
    return new BotMessage(step, config, bot, logReporter, prevStepPromise);
  }
  let isUser = "undefined" != typeof config.user;
  if (isUser) {
    return new UserMessage(step, config, bot, logReporter, prevStepPromise)
  }
  let isSession = "undefined" != typeof config.session;
  if (isSession) {
    return new SessionMessage(step, config, bot, logReporter, prevStepPromise);
  }
  let isSetDialog = ("undefined" != typeof config.dialog) || ("undefined" != typeof config.args );
  if (isSetDialog) {
    return new SetDialogMessage(step, config, bot, logReporter, prevStepPromise)
  }
  let isCustomDialog = "function" === typeof config.custom;
  if (isCustomDialog) {
    return new CustomMessage(step, config, bot, logReporter, prevStepPromise)
  }
  throw new Error('Unsupported config - ' + JSON.stringify(config));
}