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

Check for empty props when looking for localhost callback flags #105

Merged
merged 1 commit into from
Aug 19, 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
2 changes: 1 addition & 1 deletion src/commands/phone-numbers/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class NumberUpdate extends TwilioClientCommand {
}

isLocalhostUrl(props, propName) {
if (props[propName]) {
if (props && props[propName]) {
const url = new URL(props[propName]);

return ['localhost', '127.0.0.1'].includes(url.hostname) && url.protocol === 'http:';
Expand Down
29 changes: 19 additions & 10 deletions test/commands/phone-numbers/update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ describe('commands', () => {
api.get(fakeNumberUrl).reply(200, fakeNumberResource);
api.post(fakeNumberUrl).reply(200, fakeNumberResource);
})
.it(`runs incoming-phone-number:update ${fakeNumberSid} --friendly-name <name>`, async ctx => {
await ctx.testCmd.run();
.do(ctx => ctx.testCmd.run())
.it(`runs incoming-phone-number:update ${fakeNumberSid} --friendly-name <name>`, ctx => {
expect(ctx.stdout).to.contain(`sid\tresult\tfriendlyName\n${fakeNumberSid}\tSuccess\tMyPhoneNumber`);
});

Expand All @@ -72,21 +72,30 @@ describe('commands', () => {
api.get(fakeNumberUrl).reply(200, fakeNumberResource);
api.post(fakeNumberUrl).reply(200, fakeNumberResource);
})
.it(`runs incoming-phone-number:update ${fakeNumberSid} --sms-url <url>`, async ctx => {
await ctx.testCmd.run();
.do(ctx => ctx.testCmd.run())
.it(`runs incoming-phone-number:update ${fakeNumberSid} --sms-url <url>`, ctx => {
expect(ctx.stdout).to.contain(`sid\tresult\tsmsUrl\n${fakeNumberSid}\tSuccess\thttp://example.com/`);
});

setUpTest([fakeNumberSid])
.nock('https://api.twilio.com', api => {
api.get(fakeNumberUrl).reply(200, fakeNumberResource);
})
.stderr()
.do(ctx => ctx.testCmd.run())
.it('should return nothing to update if no properties passed', ctx => {
expect(ctx.stderr).to.contain('Nothing to update');
});

setUpTest([fakeNumberSid, '--sms-url', 'http://localhost:4567/', '-o', 'tsv'], { useFakeNgrok: true })
.nock('https://api.twilio.com', api => {
api.get(fakeNumberUrl).reply(200, fakeNumberResource);
api.post(fakeNumberUrl).reply(200, fakeNumberResource);
})
.stderr()
.it(
`runs incoming-phone-number:update ${fakeNumberSid} --sms-url <LOCALHOST url> and starts ngrok`,
async ctx => {
await ctx.testCmd.run();
.do(ctx => ctx.testCmd.run())
.it(`runs incoming-phone-number:update ${fakeNumberSid} --sms-url <LOCALHOST url> and starts ngrok`,
ctx => {
expect(ctx.stdout).to.contain(`sid\tresult\tsmsUrl\n${fakeNumberSid}\tSuccess\t${fakeNgrokUrl}/`);
expect(ctx.stderr).to.contain('WARNING: Detected localhost');
expect(ctx.stderr).to.contain('ngrok is running');
Expand Down Expand Up @@ -119,8 +128,8 @@ describe('commands', () => {
api.post(fakeNumberUrl).reply(200, fakeNumberResource);
})
.stderr()
.it('runs incoming-phone-number:update with multiple urls and multiple ngrok tunnels', async ctx => {
await ctx.testCmd.run();
.do(ctx => ctx.testCmd.run())
.it('runs incoming-phone-number:update with multiple urls and multiple ngrok tunnels', ctx => {
expect(ctx.stdout).to.contain(
`sid\tresult\tsmsUrl\tsmsFallbackUrl\tvoiceUrl\tvoiceFallbackUrl\n${fakeNumberSid}\tSuccess\t${fakeNgrokUrl}/\t${fakeNgrokUrl}/\t${fakeNgrokUrl}/\t${fakeNgrokUrl}/`
);
Expand Down