diff --git a/lib/commands/smapi/before-send-processor.js b/lib/commands/smapi/before-send-processor.js index f44ee739..4318fa10 100644 --- a/lib/commands/smapi/before-send-processor.js +++ b/lib/commands/smapi/before-send-processor.js @@ -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; diff --git a/lib/commands/smapi/smapi-command-handler.js b/lib/commands/smapi/smapi-command-handler.js index 6d9a25ce..0cb7f0bc 100644 --- a/lib/commands/smapi/smapi-command-handler.js +++ b/lib/commands/smapi/smapi-command-handler.js @@ -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', @@ -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]); diff --git a/test/unit/commands/smapi/before-send-processor-test.js b/test/unit/commands/smapi/before-send-processor-test.js index 2efd9106..d0c85f07 100644 --- a/test/unit/commands/smapi/before-send-processor-test.js +++ b/test/unit/commands/smapi/before-send-processor-test.js @@ -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; @@ -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}` } }]; diff --git a/test/unit/commands/smapi/smapi-command-handler-test.js b/test/unit/commands/smapi/smapi-command-handler-test.js index 4b5099d1..739d0bc9 100644 --- a/test/unit/commands/smapi/smapi-command-handler-test.js +++ b/test/unit/commands/smapi/smapi-command-handler-test.js @@ -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 };