Skip to content

Commit

Permalink
fix: added logic to handle non alphanumeric characters in smapi swagg… (
Browse files Browse the repository at this point in the history
  • Loading branch information
kakhaUrigashvili authored May 4, 2020
1 parent 0ad7e8f commit 768d56f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '10.x'
node-version: '12.x'
- run: npm install
- run: npm link
- run: npm run integration-test
15 changes: 9 additions & 6 deletions lib/commands/smapi/smapi-command-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,20 @@ const smapiCommandHandler = (swaggerApiOperationName, flatParamsMap, commanderTo
const beforeSendProcessor = new BeforeSendProcessor(inputCmdObj._name, paramsObject, modelIntrospector, profile);
beforeSendProcessor.processAll();

// TODO revisit with debug flow
const functionName = _sdkFunctionName(swaggerApiOperationName);
const params = getParamNames(client[functionName]);
const args = _mapToArgs(params, paramsObject);

if (inputOpts.debug) {
const payload = {};
params.forEach((k, i) => {
payload[k] = args[i];
});
Messenger.getInstance().info(`Operation: ${swaggerApiOperationName}`);
Messenger.getInstance().info('Payload:');
Messenger.getInstance().info(`${jsonView.toString(paramsObject)}\n`);
Messenger.getInstance().info(`${jsonView.toString(payload)}\n`);
}

const functionName = _sdkFunctionName(swaggerApiOperationName);
const params = getParamNames(client[functionName]);
const args = _mapToArgs(params, paramsObject);

return client[functionName](...args)
.then(response => {
const { body, headers, statusCode } = response;
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/string-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function kebabCase(str) {
}

function standardize(str) {
return camelCase(str).toLowerCase();
return filterNonAlphanumeric(camelCase(str).toLowerCase());
}
function isNonEmptyString(str) {
return R.is(String, str) && !R.isEmpty(str);
Expand Down
7 changes: 6 additions & 1 deletion test/unit/commands/smapi/smapi-command-handler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ describe('Smapi test - smapiCommandHandler function', () => {

expect(messengerStub.args[0]).eql(['INFO', 'Operation: someApiOperation']);
expect(messengerStub.args[1]).eql(['INFO', 'Payload:']);
expect(messengerStub.args[2]).eql(['INFO', `${jsonView.toString({ skillId })}\n`]);
expect(messengerStub.args[2])
.eql(['INFO', `${jsonView.toString({ someJson: null,
skillId,
someNonPopulatedProperty: null,
someArray: null,
simulationsApiRequest: null })}\n`]);
expect(messengerStub.args[3]).eql(['INFO', `Status code: ${fakeResponse.statusCode}`]);
expect(messengerStub.args[4]).eql(['INFO', `Response headers: ${jsonView.toString(fakeResponse.headers)}`]);
expect(messengerStub.args[5]).eql(['INFO', `Response body: ${jsonView.toString(fakeResponse.body)}`]);
Expand Down
27 changes: 27 additions & 0 deletions test/unit/utils/string-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,33 @@ describe('Utils test - string utility', () => {
});
});

describe('# test function standardize', () => {
[
{
testCase: 'camel case to lower',
str: 'testTest',
expectation: 'testtest'
},
{
testCase: 'capital case to lower',
str: 'TestTest',
expectation: 'testtest'
},
{
testCase: 'non alphanumeric',
str: 'test.test',
expectation: 'testtest'
},
].forEach(({ testCase, str, expectation }) => {
it(`| ${testCase}, expect standardize ${str}`, () => {
// call
const callResult = stringUtils.standardize(str);
// verify
expect(callResult).equal(expectation);
});
});
});

describe('# test function isNonBlankString', () => {
[
{
Expand Down

0 comments on commit 768d56f

Please sign in to comment.