Skip to content

Commit

Permalink
Fixed test actions not failing as expected + ensure nunjuck render
Browse files Browse the repository at this point in the history
errors are captured
  • Loading branch information
elboletaire committed Mar 25, 2019
1 parent 53099b6 commit f2cab97
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/worker/execution-plugins/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/worker/execution-plugins/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
})
16 changes: 12 additions & 4 deletions src/worker/execution-plugins/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
7 changes: 6 additions & 1 deletion test/operators-tester.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down

0 comments on commit f2cab97

Please sign in to comment.