All files / botbuilder-unit/src/messages CustomMessage.js

93.33% Statements 14/15
75% Branches 3/4
100% Functions 3/3
93.33% Lines 14/15
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    1x     3x   3x 3x     1x 1x   1x 3x       3x   3x 3x 1x   2x     1x
'use strict';
 
const BaseScriptStep = require('./BaseScriptStep');
 
function CustomMessage(step, config, bot, logReporter, prevStepPromise ) {
  BaseScriptStep.call(this,step,config,bot,logReporter,prevStepPromise);
 
  this.stepFinishedPromise = Promise.all([prevStepPromise] ).then(() => {
    return this.send();
  });
}
CustomMessage.prototype = Object.create(BaseScriptStep.prototype);
CustomMessage.prototype.constructor = CustomMessage;
 
CustomMessage.prototype.send = function () {
  Iif (!this.config['custom']) {
    throw new Error(`Failed to find or execute \`custom\` attribute`);
  }
 
  this.logReporter.customStep(this.step, this.config);
 
  let result = this.config['custom'].call(this);
  if ( !(result instanceof Promise )) {
    throw new Error('Custom step should return a Promise');
  }
  return result;
}
 
module.exports = CustomMessage;