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

Add --skip-parameter-validation flag #72

Merged
merged 2 commits into from
Jul 23, 2019
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
10 changes: 9 additions & 1 deletion src/base-commands/twilio-api-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ class TwilioApiCommand extends TwilioClientCommand {
}
}

TwilioApiCommand.flags = TwilioClientCommand.flags;
TwilioApiCommand.flags = Object.assign(
{
'skip-parameter-validation': flags.boolean({
default: false,
hidden: true
})
},
TwilioClientCommand.flags
);

// A static function to help us add the other static
// fields required by oclif on our dynamically created
Expand Down
2 changes: 1 addition & 1 deletion src/services/twilio-api/api-command-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ApiCommandRunner {

// If there were any errors validating the flag values, log them by flag
// key and throw.
if (Object.keys(flagErrors).length > 0) {
if (Object.keys(flagErrors).length > 0 && !this.flagValues['skip-parameter-validation']) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it beneficial to log the errors but not throw?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was on vacation @childish-sambino ... it wouldn't be beneficial for the tricorder use-case.

logger.error('Flag value validation errors:');
Object.keys(flagErrors).forEach(key => {
flagErrors[key].forEach(error => {
Expand Down
29 changes: 24 additions & 5 deletions test/base-commands/twilio-api-command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { expect, test, constants } = require('@twilio/cli-test');
const { fakeResource, fakeCallResponse } = require('./twilio-api-command.fixtures');
const { Config, ConfigData } = require('@twilio/cli-core').services.config;

const NUMBER_OF_BASE_COMMAND_FLAGS = 4;
const NUMBER_OF_BASE_COMMAND_FLAGS = 5;
const NUMBER_OF_PARAMS_FOR_CALL_CREATE = fakeResource.actions.create.parameters.length;

describe('base-commands', () => {
Expand Down Expand Up @@ -101,10 +101,7 @@ describe('base-commands', () => {
.nock('https://api.twilio.com', api =>
api.delete(`/2010-04-01/Accounts/${constants.FAKE_ACCOUNT_SID}/Calls/${fakeCallResponse.sid}.json`).reply(204)
)
.twilioCommand(getCommandClass(callRemoveActionDefinition), [
'--sid',
fakeCallResponse.sid
])
.twilioCommand(getCommandClass(callRemoveActionDefinition), ['--sid', fakeCallResponse.sid])
.it('creates a call', ctx => {
expect(ctx.stdout).to.be.empty;
expect(ctx.stderr).to.contain('success');
Expand All @@ -128,6 +125,28 @@ describe('base-commands', () => {
.it('exits with a failure code and prints validation errors', ctx => {
expect(ctx.stderr).to.contain('validation errors');
});

test
.twilioFakeProject(ConfigData)
.twilioCliEnv(Config)
.stdout()
.nock('https://api.twilio.com', api =>
api.post(`/2010-04-01/Accounts/${constants.FAKE_ACCOUNT_SID}/Calls.json`).reply(201, fakeCallResponse)
)
.twilioCommand(getCommandClass(), [
'--skip-parameter-validation',
'--from',
'+15555555555',
'--to',
'+14155555555',
'--url',
'http://example.com/',
'--account-sid',
'ac12345678901234567890123456789012' // Lower-cased 'ac'
])
.it('creates a call with invalid parameter', ctx => {
expect(ctx.stdout).to.contain(fakeCallResponse.sid);
});
});
});
});