Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#9747): throw error if outbound config is undefined #9748

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.*'expr' or 'path' is required/);
});
});

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