From d26f504594e4d34eb1244f36e10ef1088f1beaad Mon Sep 17 00:00:00 2001 From: ravali-rimmalapudi <83863595+ravali-rimmalapudi@users.noreply.github.com> Date: Fri, 3 Dec 2021 15:10:05 +0530 Subject: [PATCH] feat: Add flag no header for fetch and list commands. (#344) * feat: Adding --no-header flag for list commands * Added the test cases Co-authored-by: Sindhura Chamala --- src/base-commands/twilio-api-command.js | 7 ++++++ src/commands/debugger/logs/list.js | 1 + src/commands/phone-numbers/list.js | 1 + src/commands/profiles/list.js | 4 ++-- test/base-commands/twilio-api-command.test.js | 2 ++ test/commands/debugger/logs/list.test.js | 23 +++++++++++++++++++ test/commands/phone-numbers/list.test.js | 3 +++ test/commands/profiles/list.test.js | 21 +++++++++++++++++ 8 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/base-commands/twilio-api-command.js b/src/base-commands/twilio-api-command.js index dd6e6ebed..1dc26c090 100644 --- a/src/base-commands/twilio-api-command.js +++ b/src/base-commands/twilio-api-command.js @@ -114,6 +114,13 @@ TwilioApiCommand.setUpNewCommandClass = (NewCommandClass) => { }); } + if ( + NewCommandClass.actionDefinition.commandName === 'list' || + NewCommandClass.actionDefinition.commandName === 'fetch' + ) { + cmdFlags = Object.assign(cmdFlags, TwilioClientCommand.noHeader); + } + // 'list' commands get limit flags for specifying the result set size. if (NewCommandClass.actionDefinition.commandName === 'list') { cmdFlags = Object.assign(cmdFlags, TwilioClientCommand.limitFlags); diff --git a/src/commands/debugger/logs/list.js b/src/commands/debugger/logs/list.js index 251293e66..4a226da22 100644 --- a/src/commands/debugger/logs/list.js +++ b/src/commands/debugger/logs/list.js @@ -120,6 +120,7 @@ DebuggerLogsList.flags = { }), ...DebuggerLogsList.PropertyFlags, ...TwilioClientCommand.flags, + ...TwilioClientCommand.noHeader, }; module.exports = DebuggerLogsList; diff --git a/src/commands/phone-numbers/list.js b/src/commands/phone-numbers/list.js index a32d3e3b2..fdaf8afe6 100644 --- a/src/commands/phone-numbers/list.js +++ b/src/commands/phone-numbers/list.js @@ -19,6 +19,7 @@ NumberList.flags = { }), ...TwilioClientCommand.flags, ...TwilioClientCommand.accountSidFlag, + ...TwilioClientCommand.noHeader, }; module.exports = NumberList; diff --git a/src/commands/profiles/list.js b/src/commands/profiles/list.js index 9c7e3c139..634b42f55 100644 --- a/src/commands/profiles/list.js +++ b/src/commands/profiles/list.js @@ -1,5 +1,5 @@ const chalk = require('chalk'); -const { BaseCommand } = require('@twilio/cli-core').baseCommands; +const { BaseCommand, TwilioClientCommand } = require('@twilio/cli-core').baseCommands; class ProfilesList extends BaseCommand { async run() { @@ -33,6 +33,6 @@ class ProfilesList extends BaseCommand { } ProfilesList.description = 'show what profiles you have configured'; -ProfilesList.flags = BaseCommand.flags; +ProfilesList.flags = { ...BaseCommand.flags, ...TwilioClientCommand.noHeader }; module.exports = ProfilesList; diff --git a/test/base-commands/twilio-api-command.test.js b/test/base-commands/twilio-api-command.test.js index 6f3b8d684..4f4bd5305 100644 --- a/test/base-commands/twilio-api-command.test.js +++ b/test/base-commands/twilio-api-command.test.js @@ -133,6 +133,7 @@ describe('base-commands', () => { expect(Object.keys(NewCommandClass.flags)).to.include('start-time-before'); expect(Object.keys(NewCommandClass.flags)).to.include('limit'); expect(Object.keys(NewCommandClass.flags)).to.include('no-limit'); + expect(Object.keys(NewCommandClass.flags)).to.include('no-header'); }); test.it('checks the help document url', () => { @@ -140,6 +141,7 @@ describe('base-commands', () => { expect(NewCommandClass.id).to.equal('api:core:calls:create'); expect(NewCommandClass.description).to.equal(fakeResource.actions.create.description); expect(NewCommandClass.docLink).to.equal('https://twilio.com/docs/usage/api'); + expect(Object.keys(NewCommandClass.flags)).not.to.include('no-header'); }); test.it('checks the help document url', () => { diff --git a/test/commands/debugger/logs/list.test.js b/test/commands/debugger/logs/list.test.js index 4311ee609..0db502501 100644 --- a/test/commands/debugger/logs/list.test.js +++ b/test/commands/debugger/logs/list.test.js @@ -81,6 +81,29 @@ describe('debugger:logs:list', () => { .it('streams and then quits', (ctx) => { expect(ctx.stdout.match(INFO_LOG.error_code)).to.have.length(1); expect(ctx.stdout.match(WARN_LOG.alert_text)).to.have.length(1); + expect(ctx.stdout).to.contain('Date Created'); + }); + + testConfig + .nock('https://monitor.twilio.com', (api) => { + api + .get('/v1/Alerts') + .query(true) + .times(2) + .reply(200, { alerts: [INFO_LOG, WARN_LOG, INFO_LOG] }) + .get('/v1/Alerts') + .query(true) + .reply(404, { code: 999, message: 'Some random error' }); + }) + .twilioCommand(DebuggerLogsList, ['--streaming', '--no-header']) + .catch(/999.*Some random error/) + .it('streams and then quits and displays with --no-header', (ctx) => { + expect(ctx.stdout).not.to.contain('Date Created'); + expect(ctx.stdout).not.to.contain('Log Level'); + expect(ctx.stdout).not.to.contain('Error Code'); + expect(ctx.stdout).not.to.contain('Alert Text'); + expect(ctx.stdout.match(INFO_LOG.error_code)).to.have.length(1); + expect(ctx.stdout.match(WARN_LOG.alert_text)).to.have.length(1); }); testConfig diff --git a/test/commands/phone-numbers/list.test.js b/test/commands/phone-numbers/list.test.js index d4fd6fb21..a905bb611 100644 --- a/test/commands/phone-numbers/list.test.js +++ b/test/commands/phone-numbers/list.test.js @@ -26,6 +26,9 @@ describe('commands', () => { setUpTest(['--properties', 'phoneNumber']).it('runs incoming-phone-number:list with custom properties', (ctx) => { expect(ctx.stdout).to.equal('Phone Number\n+12095551212\n'); }); + setUpTest(['--no-header']).it('runs incoming-phone-number:list --no-header', (ctx) => { + expect(ctx.stdout).to.equal('PN123 +12095551212 my phone #\n'); + }); }); }); }); diff --git a/test/commands/profiles/list.test.js b/test/commands/profiles/list.test.js index e97510c20..7f56283d0 100644 --- a/test/commands/profiles/list.test.js +++ b/test/commands/profiles/list.test.js @@ -88,6 +88,27 @@ describe('commands', () => { expect(ctx.stdout.match(/true/g)).to.have.length(1); expect(ctx.stdout).to.match(/profile1.*true/); expect(ctx.stderr).to.equal(''); + expect(ctx.stdout).to.contain('ID'); + }); + + test + .do((ctx) => { + ctx.userConfig = new ConfigData(); + ctx.userConfig.addProfile('profile1', constants.FAKE_ACCOUNT_SID); + ctx.userConfig.addProfile('profile2', constants.FAKE_ACCOUNT_SID); + ctx.userConfig.activeProfile = 'profile1'; + }) + .twilioCliEnv(Config) + .stdout() + .stderr() + .twilioCommand(ProfilesList, ['--no-header']) + .it('list with --no-header', (ctx) => { + expect(ctx.stdout).not.to.contain('ID'); + expect(ctx.stdout).not.to.contain('Account SID'); + expect(ctx.stdout).not.to.contain('Active'); + expect(ctx.stdout).to.contain('profile1'); + expect(ctx.stdout).to.contain('profile2'); + expect(ctx.stdout).to.contain(constants.FAKE_ACCOUNT_SID); }); test