All files / botbuilder-unit/src ScriptStepFactory.js

95.65% Statements 22/23
94.12% Branches 16/17
50% Functions 1/2
95.65% Lines 22/23
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      1x 1x 1x 1x 1x       1x 200x   200x 116x   84x 84x 69x   15x 15x 7x   8x 8x 5x   3x 3x 3x         1x
/* 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');
function MessageFactory() {
 
}
MessageFactory.produce = function (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;
  Eif (isCustomDialog) {
    return new CustomMessage(step, config, bot, logReporter, prevStepPromise)
  }
  throw new Error('Unsupported config - ' + JSON.stringify(config));
 
}
module.exports = MessageFactory;