diff --git a/src/worker/execution-plugins/mapper.ts b/src/worker/execution-plugins/mapper.ts index 5c2b58d..f3cbf2e 100644 --- a/src/worker/execution-plugins/mapper.ts +++ b/src/worker/execution-plugins/mapper.ts @@ -38,7 +38,10 @@ export default class MapperPlugin extends OperatorPlugin implements PluginExecut logger.info(this.preLog, 'Object mapping applied') if (this.options.merge) { - return Promise.resolve(Object.assign({}, message, transformedObj)) + return Promise.resolve({ + ...message, + ...transformedObj, + }) } return Promise.resolve(transformedObj) diff --git a/src/worker/execution-plugins/template.spec.ts b/src/worker/execution-plugins/template.spec.ts index ccd6f2f..0f5549d 100644 --- a/src/worker/execution-plugins/template.spec.ts +++ b/src/worker/execution-plugins/template.spec.ts @@ -31,5 +31,12 @@ describe('execution-plugins :: template', () => { return expect(setObj.test).toEqual('34.56') }) }) + + it('should reject in case there\'s a render problem', () => { + options.fields.test = '{{ amounts' + const objTransformer = new TemplatePlugin(action(options), '') + + return expect(objTransformer.execute(msg)).rejects.toBeTruthy() + }) }) }) diff --git a/src/worker/execution-plugins/template.ts b/src/worker/execution-plugins/template.ts index 503869b..bc3a7bd 100644 --- a/src/worker/execution-plugins/template.ts +++ b/src/worker/execution-plugins/template.ts @@ -24,13 +24,21 @@ export default class TemplatePlugin extends OperatorPlugin implements PluginExec ) const fieldsTemplate = {} - Object.keys(this.options.fields).forEach((field) => { - fieldsTemplate[field] = nunjucks.renderString(this.options.fields[field], message) - }) + try { + Object.keys(this.options.fields).forEach((field) => { + fieldsTemplate[field] = nunjucks.renderString(this.options.fields[field], message) + }) + } catch (error) { + return Promise.reject(error) + } - const setTemplate = Object.assign({}, message, fieldsTemplate) + const setTemplate = Object.assign({ + ...message, + ...fieldsTemplate + }) logger.info(this.preLog, 'Template applied') + return Promise.resolve(setTemplate) } } diff --git a/test/operators-tester.spec.ts b/test/operators-tester.spec.ts index 5c61fd7..efd166d 100644 --- a/test/operators-tester.spec.ts +++ b/test/operators-tester.spec.ts @@ -51,7 +51,12 @@ const executeActions = async (operator, {input, actions, response}) => { return retorn }).catch((err) => { - return Promise.resolve(err) + // This is due to how errored payloads are treaten... something that + // should be reviewed + if (err.action && err.action === 'abort') { + return Promise.resolve(err) + } + return Promise.reject(err) }) }