Skip to content

Commit

Permalink
fix: add condition to load vendor id for smapi commands
Browse files Browse the repository at this point in the history
  • Loading branch information
kakha urigashvili committed May 6, 2020
1 parent f4d12f8 commit c952eec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/commands/smapi/before-send-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BeforeSendProcessor {
}

appendVendorId() {
const vendorId = AppConfig.getInstance().getVendorId(this.profile);
const vendorId = process.env.ASK_VENDOR_ID || AppConfig.getInstance().getVendorId(this.profile);
const nonBodyParam = this.params.find(p => p.name === 'vendorId');
if (nonBodyParam) {
this.paramsObject.vendorId = vendorId;
Expand Down
6 changes: 4 additions & 2 deletions lib/commands/smapi/smapi-command-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ const _sdkFunctionName = (swaggerApiOperationName) => `call${swaggerApiOperation
* @param {Object} cmdObj Commander object with passed values.
*/
const smapiCommandHandler = (swaggerApiOperationName, flatParamsMap, commanderToApiCustomizationMap, inputCmdObj, modelIntrospector) => {
new AppConfig(configFilePath);
if (profileHelper.runtimeProfile() !== CONSTANTS.PLACEHOLDER.ENVIRONMENT_VAR.PROFILE_NAME) {
new AppConfig(configFilePath);
}
const inputOpts = inputCmdObj.opts();
const authorizationController = new AuthorizationController({
auth_client_type: 'LWA',
Expand All @@ -96,7 +98,7 @@ const smapiCommandHandler = (swaggerApiOperationName, flatParamsMap, commanderTo
const refreshTokenConfig = {
clientId: authorizationController.oauthClient.config.clientId,
clientSecret: authorizationController.oauthClient.config.clientConfirmation,
refreshToken: AppConfig.getInstance().getToken(profile).refresh_token
refreshToken: process.env.ASK_REFRESH_TOKEN || AppConfig.getInstance().getToken(profile).refresh_token
};
const authEndpoint = resolveProviderChain([process.env.ASK_LWA_TOKEN_HOST, CONSTANTS.LWA.DEFAULT_TOKEN_HOST]);
const smapiEndpoint = resolveProviderChain([process.env.ASK_SMAPI_SERVER_BASE_URL, CONSTANTS.SMAPI.ENDPOINT]);
Expand Down
16 changes: 16 additions & 0 deletions test/unit/commands/smapi/before-send-processor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Smapi test - BeforeSendProcessor class tests', () => {
const paramName = 'someParam';
const commandName = 'some-command';
beforeEach(() => {
delete process.env.ASK_VENDOR_ID;
sinon.stub(AppConfig, 'getInstance').returns({
getVendorId() {
return vendorId;
Expand All @@ -31,6 +32,21 @@ describe('Smapi test - BeforeSendProcessor class tests', () => {
expect(paramObject[paramName].vendorId).eql(vendorId);
});

it('| should add vendor id from env variable to body param', () => {
process.env.ASK_VENDOR_ID = 'someVendorIdFromVariable';
const paramObject = {};
const params = [{ in: 'body', name: paramName, required: true, schema: { $ref: `#/definitions/${definitionRef}` } }];
const modelInterceptor = {
operations: new Map([[commandName, { params }]]),
definitions: new Map([[definitionRef, { properties: { vendorId: {} } }]])
};

const beforeSendProcessor = new BeforeSendProcessor(commandName, paramObject, modelInterceptor, profile);
beforeSendProcessor.processAll();

expect(paramObject[paramName].vendorId).eql(process.env.ASK_VENDOR_ID);
});

it('| should not add vendor id when no properties in reference object', () => {
const paramObject = {};
const params = [{ in: 'body', name: paramName, required: true, schema: { $ref: `#/definitions/${definitionRef}` } }];
Expand Down
1 change: 1 addition & 0 deletions test/unit/commands/smapi/smapi-command-handler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('Smapi test - smapiCommandHandler function', () => {
};

beforeEach(() => {
delete process.env.ASK_REFRESH_TOKEN;
cmdObj = {
opts() {
return { skillId, someNumber, someBoolean, someJson: JSON.stringify(jsonValue), someArray: arrayValueStr };
Expand Down

0 comments on commit c952eec

Please sign in to comment.