diff --git a/shared-libs/outbound/src/outbound.js b/shared-libs/outbound/src/outbound.js index 9fbc6efc58..f7ac203eb5 100644 --- a/shared-libs/outbound/src/outbound.js +++ b/shared-libs/outbound/src/outbound.js @@ -69,12 +69,14 @@ const mapDocumentToPayload = (doc, config, key) => { } catch (err) { throw new OutboundError(`Mapping error for '${key}/${dest}' JS error on source document: '${doc._id}': ${err}`); } - } else { + } else if (path) { try { srcValue = objectPath.get({doc}, path); } catch (err) { throw new OutboundError(`Mapping error for '${key}/${dest}' JS error on source document: '${doc._id}': ${err}`); } + } else { + throw new OutboundError(`Mapping error for '${key}/${dest}' either 'expr' or 'path' is required: '${doc._id}'`); } if (required && srcValue === undefined) { diff --git a/shared-libs/outbound/test/outbound.spec.js b/shared-libs/outbound/test/outbound.spec.js index 5a706965cb..948351d898 100644 --- a/shared-libs/outbound/test/outbound.spec.js +++ b/shared-libs/outbound/test/outbound.spec.js @@ -210,6 +210,20 @@ describe('outbound shared library', () => { assert.throws(() => mapDocumentToPayload(doc, conf, 'test-doc'), /Mapping error/); }); + + it('throws an exception if the expression does not have either path or expr', () => { + const doc = { + _id: 'test-doc', + }; + + const conf = { + mapping: { + is_gonna_fail: {not_path_or_expr: 'doc.fields.null.pointer'}, + } + }; + + assert.throws(() => mapDocumentToPayload(doc, conf, 'test-doc'), /Mapping error.*'expr' or 'path' is required/); + }); }); describe('updateInfo', () => {