Skip to content

Commit

Permalink
Check for empty props when looking for localhost callback flags (#105)
Browse files Browse the repository at this point in the history
Fixes #104
  • Loading branch information
childish-sambino committed Aug 19, 2019
1 parent bc12f4a commit 478177c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
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

0 comments on commit 478177c

Please sign in to comment.