Skip to content

Commit

Permalink
fix(#9747): throw error if outbound config is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
witash committed Jan 16, 2025
1 parent 651f54a commit e63dcd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion shared-libs/outbound/src/outbound.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions shared-libs/outbound/test/outbound.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});
});

describe('updateInfo', () => {
Expand Down

0 comments on commit e63dcd6

Please sign in to comment.