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

fix: changes for default output property #377

Merged
merged 5 commits into from
Feb 2, 2022
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
3 changes: 2 additions & 1 deletion src/base-commands/twilio-api-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ TwilioApiCommand.setUpNewCommandClass = (NewCommandClass) => {

// 'remove' commands have no response body and thus do not need display properties.
if (NewCommandClass.actionDefinition.commandName !== 'remove') {
const defaultProperties = (resource && resource.defaultOutputProperties) || [];
const defaultProperties =
(action && action.defaultOutputProperties) || (resource && resource.defaultOutputProperties) || [];

cmdFlags.properties = flags.string({
// Camel-cased, CSV of the provided property list. Or just the SID.
Expand Down
40 changes: 40 additions & 0 deletions test/base-commands/twilio-api-command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,37 @@ describe('base-commands', () => {
},
};

// where default output is property is defined at operation level.
const createNewFactorActionDefinition = {
domainName: 'verify',
commandName: 'post',
path: '/v2/Services/{ServiceSid}/Entities/{Identity}/Factors',
resource: fakeResource,
actionName: 'post',
action: {
parameters: [
{ name: 'Identity', in: 'path', schema: { type: 'string' } },
{ name: 'ServiceSid', in: 'path', schema: { type: 'string' } },
],
defaultOutputProperties: ['sid', 'binding'],
},
};

const getFactorListActionDefinition = {
domainName: 'verify',
commandName: 'list',
path: '/v2/Services/{ServiceSid}/Entities/{Identity}/Factors',
resource: fakeResource,
actionName: 'get',
action: {
parameters: [
{ name: 'Identity', in: 'path', schema: { type: 'string' } },
{ name: 'ServiceSid', in: 'path', schema: { type: 'string' } },
{ name: 'PageSize', in: 'query', schema: { type: 'integer' } },
],
},
};

const syncMapItemUpdateActionDefinition = {
domainName: 'sync',
commandName: 'update',
Expand Down Expand Up @@ -157,6 +188,15 @@ describe('base-commands', () => {
expect(NewCommandClass.flags.properties).to.be.undefined;
});

test.it('check default output property propagation at operation level', () => {
const NewCommandClass = getCommandClass(createNewFactorActionDefinition);
expect(NewCommandClass.flags.properties.default).to.equal('sid,binding');
});
test.it('fallback to default output property at path level if not specified at operation level', () => {
const NewCommandClass = getCommandClass(getFactorListActionDefinition);
expect(NewCommandClass.flags.properties.default).to.equal('sid,friendly_name,status');
});

test
.twilioFakeProfile(ConfigData)
.twilioCliEnv(Config)
Expand Down