Skip to content

Commit

Permalink
chore: added check for multiple arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishkkatara committed Jun 12, 2024
1 parent ce2d62d commit 546a937
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/util/ivmFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async function createIvm(code, libraryVersionIds, versionId, credentials, secret
if (_.isNil(credentials) || !_.isObject(credentials)) {
throw new Error('Credentials in incorrect format');

Check warning on line 248 in src/util/ivmFactory.js

View check run for this annotation

Codecov / codecov/patch

src/util/ivmFactory.js#L248

Added line #L248 was not covered by tests
}
if (_.isNil(key[0]) || !_.isString(key[0])) {
if (key.length > 1 || _.isNil(key[0]) || !_.isString(key[0])) {
throw new Error('Key should be a string');
}
return credentials[key];
Expand Down
29 changes: 29 additions & 0 deletions test/__tests__/user_transformation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,35 @@ describe("User transformation", () => {
expect(output[0].error).toMatch(/Key should be a string/);
});

it(`Simple ${name} Test with credentials with multiple arguements for codeVersion 1`, async () => {
const versionId = randomID();

const inputData = require(`./data/${integration}_input_credentials.json`);

const respBody = {
versionId: versionId,
codeVersion: "1",
name,
code: `
export function transformEvent(event, metadata) {
event.credentialValue = credential('arg1', 'arg2');
return event;
}
`
};
fetch.mockResolvedValue({
status: 200,
json: jest.fn().mockResolvedValue(respBody)
});

const output = await userTransformHandler(inputData, versionId, []);

expect(fetch).toHaveBeenCalledWith(
`https://api.rudderlabs.com/transformation/getByVersionId?versionId=${versionId}`
);
expect(output[0].error).toMatch(/Key should be a string/);
});

it(`Simple ${name} Test with credentials with non string key for codeVersion 1`, async () => {
const versionId = randomID();

Expand Down

0 comments on commit 546a937

Please sign in to comment.