diff --git a/src/services/twilio-api/api-command-runner.js b/src/services/twilio-api/api-command-runner.js index 9d172145b..caced630e 100644 --- a/src/services/twilio-api/api-command-runner.js +++ b/src/services/twilio-api/api-command-runner.js @@ -69,10 +69,11 @@ class ApiCommandRunner { const pathParams = {}; const queryParams = {}; + const headerParams = {}; - // Build the path and query params based on the parameters defined with the API action. + // Build the path, query, and header params based on the parameters defined with the API action. actionParams.forEach(parameter => { - const destination = (parameter.in === 'path' ? pathParams : queryParams); + const destination = (parameter.in === 'path' ? pathParams : (parameter.in === 'header' ? headerParams : queryParams)); this.addParameter(parameter, destination); }); @@ -87,7 +88,8 @@ class ApiCommandRunner { domain: domainName, path: path, pathParams: pathParams, - data: queryParams + data: queryParams, + headers: headerParams }); // TODO: Possible extender event: "afterInvokeApi" diff --git a/test/base-commands/twilio-api-command.test.js b/test/base-commands/twilio-api-command.test.js index 2664beb94..5df2b4d43 100644 --- a/test/base-commands/twilio-api-command.test.js +++ b/test/base-commands/twilio-api-command.test.js @@ -57,6 +57,22 @@ describe('base-commands', () => { } }; + const syncMapItemUpdateActionDefinition = { + domainName: 'sync', + commandName: 'update', + path: '/v1/Services/{ServiceSid}/Maps/{MapSid}/Items/{Sid}.json', + actionName: 'update', + action: { + parameters: [ + { name: 'Sid', in: 'path', schema: { type: 'string' } }, + { name: 'MapSid', in: 'path', schema: { type: 'string' } }, + { name: 'ServiceSid', in: 'path', schema: { type: 'string' } }, + { name: 'Key', in: 'query', schema: { type: 'string' } }, + { name: 'If-Match', in: 'header', schema: { type: 'string' } } + ] + } + }; + const getCommandClass = (actionDefinition = callCreateActionDefinition) => { const NewCommandClass = class extends TwilioApiCommand { }; @@ -240,6 +256,32 @@ describe('base-commands', () => { .it('creates a call with an invalid parameter', ctx => { expect(ctx.stdout).to.contain(fakeCallResponse.sid); }); + + test + .twilioFakeProfile(ConfigData) + .twilioCliEnv(Config) + .stdout() + .stderr() + .twilioCreateCommand(getCommandClass(syncMapItemUpdateActionDefinition), [ + '--sid', + 'unique_name', + '--map-sid', + 'MP0123', + '--service-sid', + 'IS1234', + '--key', + 'test_key', + '--if-match', + 'revision' + ]) + .do(ctx => { + ctx.testCmd.twilioApi = { update: sinon.stub().returns({}) }; + return ctx.testCmd.run(); + }) + .it('adds header parameters', ctx => { + const syncOptions = ctx.testCmd.twilioApi.update.firstCall.firstArg; + expect(syncOptions.headers).to.include({ 'If-Match': 'revision' }); + }); }); }); });