From 7bebf1ae21f15b4a0c0b74e47203173d426cb644 Mon Sep 17 00:00:00 2001 From: Eetu Tuomala Date: Wed, 9 Nov 2016 23:17:48 +0200 Subject: [PATCH 1/4] fixes endpoint path slash issue --- lib/plugins/aws/info/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/aws/info/index.js b/lib/plugins/aws/info/index.js index 915c87462..4fd64b94c 100644 --- a/lib/plugins/aws/info/index.js +++ b/lib/plugins/aws/info/index.js @@ -177,8 +177,8 @@ ${chalk.yellow('region:')} ${info.region}`; method = event.http.split(' ')[0].toUpperCase(); path = event.http.split(' ')[1]; } - - endpointsMessage = endpointsMessage.concat(`\n ${method} - ${info.endpoint}/${path}`); + path = path.length > 1 ? `/${path.split('/').filter(p => p !== '').join('/')}` : ''; + endpointsMessage = endpointsMessage.concat(`\n ${method} - ${info.endpoint}${path}`); } }); }); From a19d2bdb789f3260f0c86b84a9e9ffc03c7be32a Mon Sep 17 00:00:00 2001 From: Eetu Tuomala Date: Wed, 9 Nov 2016 23:34:16 +0200 Subject: [PATCH 2/4] fixed bad condition --- lib/plugins/aws/info/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/aws/info/index.js b/lib/plugins/aws/info/index.js index 4fd64b94c..bc241a85e 100644 --- a/lib/plugins/aws/info/index.js +++ b/lib/plugins/aws/info/index.js @@ -177,7 +177,7 @@ ${chalk.yellow('region:')} ${info.region}`; method = event.http.split(' ')[0].toUpperCase(); path = event.http.split(' ')[1]; } - path = path.length > 1 ? `/${path.split('/').filter(p => p !== '').join('/')}` : ''; + path = path !== '/' ? `/${path.split('/').filter(p => p !== '').join('/')}` : ''; endpointsMessage = endpointsMessage.concat(`\n ${method} - ${info.endpoint}${path}`); } }); From 32b78dbb7699034b2b2c322cd390bc07621f472a Mon Sep 17 00:00:00 2001 From: Eetu Tuomala Date: Thu, 10 Nov 2016 00:10:04 +0200 Subject: [PATCH 3/4] adds test for endpoints with slashes --- lib/plugins/aws/info/tests/index.js | 66 ++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/lib/plugins/aws/info/tests/index.js b/lib/plugins/aws/info/tests/index.js index 757049512..1117e540b 100644 --- a/lib/plugins/aws/info/tests/index.js +++ b/lib/plugins/aws/info/tests/index.js @@ -387,7 +387,71 @@ ${chalk.yellow('functions:')} expect(awsInfo.display(data)).to.equal(expectedMessage); }); - it("should display only general information when stack doesn't exist", () => { + it('should format information message correctly with additional endpoints', () => { + serverless.cli = new CLI(serverless); + const additionalFunctions = [ + { + http: { + path: '/', + method: 'POST', + }, + }, + { + http: { + path: '/both/', + method: 'POST', + }, + }, + { + http: { + path: '/both/add/', + method: 'POST', + }, + }, + { + http: { + path: 'e', + method: 'POST', + }, + }, + ]; + serverless.service.functions.function2.events = + serverless.service.functions.function2.events.concat(additionalFunctions); + + sinon.stub(serverless.cli, 'consoleLog').returns(); + + const data = { + info: { + service: 'my-first', + stage: 'dev', + region: 'eu-west-1', + endpoint: 'ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev', + functions: [], + }, + }; + + const expectedMessage = ` +${chalk.yellow.underline('Service Information')} +${chalk.yellow('service:')} my-first +${chalk.yellow('stage:')} dev +${chalk.yellow('region:')} eu-west-1 +${chalk.yellow('api keys:')} + None +${chalk.yellow('endpoints:')} + GET - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/function1 + POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/function2 + POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev + POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/both + POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/both/add + POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/e +${chalk.yellow('functions:')} + None +`; + + expect(awsInfo.display(data)).to.equal(expectedMessage); + }); + + it('should display only general information when stack doesn\'t exist', () => { serverless.cli = new CLI(serverless); sinon.stub(serverless.cli, 'consoleLog').returns(); From 5ce7f95663ba11fce0fa90f53da70c7c3df131ab Mon Sep 17 00:00:00 2001 From: Eetu Tuomala Date: Thu, 10 Nov 2016 00:18:04 +0200 Subject: [PATCH 4/4] cleans test --- lib/plugins/aws/info/tests/index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/plugins/aws/info/tests/index.js b/lib/plugins/aws/info/tests/index.js index 1117e540b..dd1a6749d 100644 --- a/lib/plugins/aws/info/tests/index.js +++ b/lib/plugins/aws/info/tests/index.js @@ -387,9 +387,9 @@ ${chalk.yellow('functions:')} expect(awsInfo.display(data)).to.equal(expectedMessage); }); - it('should format information message correctly with additional endpoints', () => { + it('should format information message correctly with slashed endpoint events', () => { serverless.cli = new CLI(serverless); - const additionalFunctions = [ + const additionalEvents = [ { http: { path: '/', @@ -415,8 +415,11 @@ ${chalk.yellow('functions:')} }, }, ]; - serverless.service.functions.function2.events = - serverless.service.functions.function2.events.concat(additionalFunctions); + serverless.service.functions = { + function1: { + events: additionalEvents, + }, + }; sinon.stub(serverless.cli, 'consoleLog').returns(); @@ -438,8 +441,6 @@ ${chalk.yellow('region:')} eu-west-1 ${chalk.yellow('api keys:')} None ${chalk.yellow('endpoints:')} - GET - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/function1 - POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/function2 POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/both POST - ab12cd34ef.execute-api.us-east-1.amazonaws.com/dev/both/add