All files / src/messages CustomMessage.js

33.33% Statements 5/15
0% Branches 0/4
0% Functions 0/3
33.33% Lines 5/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                 1x 1x   1x                           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 () {
  if (!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;