Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom HTTP header parameter support #200

Merged
merged 4 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/services/twilio-api/api-command-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -87,7 +88,8 @@ class ApiCommandRunner {
domain: domainName,
path: path,
pathParams: pathParams,
data: queryParams
data: queryParams,
headers: headerParams
});

// TODO: Possible extender event: "afterInvokeApi"
Expand Down
42 changes: 42 additions & 0 deletions test/base-commands/twilio-api-command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
};
Expand Down Expand Up @@ -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' });
});
});
});
});