From 59701f560cd4f02ebc5a18549af265bd8038c67d Mon Sep 17 00:00:00 2001 From: Scott Smethurst Date: Tue, 6 Apr 2021 16:59:55 +0100 Subject: [PATCH 1/5] =?UTF-8?q?I=E2=80=99ve=20added=20an=20optional=20?= =?UTF-8?q?=E2=80=98restApiId=E2=80=99=20setting=20so=20that=20if=20a=20sh?= =?UTF-8?q?ared=20API=20Gateway=20has=20been=20configured=20in=20a=20diffe?= =?UTF-8?q?rent=20CloudFormation=20stack,=20its=20RestApiId=20can=20be=20e?= =?UTF-8?q?xported=20and=20passed=20to=20this=20plugin=20as=20an=20input?= =?UTF-8?q?=20parameter.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++- src/ApiGatewayCachingSettings.js | 1 + src/apiGatewayCachingPlugin.js | 8 ++-- src/restApiId.js | 11 ++++- test/configuring-rest-api-id.js | 42 ++++++++++++++----- test/creating-plugin.js | 16 +++---- test/model/Serverless.js | 5 ++- ...cache-settings-for-additional-endpoints.js | 2 +- test/updating-stage-cache-settings.js | 10 ++--- 9 files changed, 68 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 60efa8c..af1300f 100644 --- a/README.md +++ b/README.md @@ -265,7 +265,9 @@ functions: Cache key parameters coming from multi-value query strings and multi-value headers are currently not supported. ## Configuring a shared API Gateway -This just means that no changes are applied to the root caching configuration of the API Gateway, however `ttlInSeconds`, `dataEncryption` and `perKeyInvalidation` are still applied to all functions, unless specifically overridden. +Setting `apiGatewayIsShared` to `true` means that no changes are applied to the root caching configuration of the API Gateway. However, `ttlInSeconds`, `dataEncryption` and `perKeyInvalidation` are still applied to all functions, unless specifically overridden. + +You can also optionally specify the `restApiId` of the shared API Gateway if you have exported that from a different CloudFormation stack. If a `restApiId` is not specified, the plugin will automatically try to find one in the stack that's being deployed. ```yml plugins: @@ -275,6 +277,7 @@ custom: apiGatewayCaching: enabled: true apiGatewayIsShared: true + restApiId: ${cf:api-gateway-${self:provider.stage}.RestApiId} clusterSize: '0.5' ttlInSeconds: 300 dataEncrypted: true @@ -295,7 +298,7 @@ resources: Properties: ParentId: Fn::GetAtt: - - ApiGatewayRestApi # the default Rest API logical ID + - ApiGatewayRestApi # the default REST API logical ID - RootResourceId PathPart: serverless # the endpoint in your API that is set as proxy RestApiId: diff --git a/src/ApiGatewayCachingSettings.js b/src/ApiGatewayCachingSettings.js index b5221fa..fb7d0cd 100644 --- a/src/ApiGatewayCachingSettings.js +++ b/src/ApiGatewayCachingSettings.js @@ -95,6 +95,7 @@ class ApiGatewayCachingSettings { const cachingSettings = serverless.service.custom.apiGatewayCaching; this.cachingEnabled = cachingSettings.enabled; this.apiGatewayIsShared = cachingSettings.apiGatewayIsShared; + this.restApiId = cachingSettings.restApiId; if (options) { this.stage = options.stage || serverless.service.provider.stage; diff --git a/src/apiGatewayCachingPlugin.js b/src/apiGatewayCachingPlugin.js index 15720bb..0b59307 100644 --- a/src/apiGatewayCachingPlugin.js +++ b/src/apiGatewayCachingPlugin.js @@ -24,9 +24,9 @@ class ApiGatewayCachingPlugin { } updateCloudFormationTemplate() { - this.thereIsARestApi = restApiExists(this.serverless); + this.thereIsARestApi = restApiExists(this.serverless, this.settings); if (!this.thereIsARestApi) { - this.serverless.cli.log(`[serverless-api-gateway-caching] No Rest API found. Caching settings will not be updated.`); + this.serverless.cli.log(`[serverless-api-gateway-caching] No REST API found. Caching settings will not be updated.`); return; } @@ -41,9 +41,9 @@ class ApiGatewayCachingPlugin { } updateStage() { - this.thereIsARestApi = restApiExists(this.serverless); + this.thereIsARestApi = restApiExists(this.serverless, this.settings); if (!this.thereIsARestApi) { - this.serverless.cli.log(`[serverless-api-gateway-caching] No Rest API found. Caching settings will not be updated.`); + this.serverless.cli.log(`[serverless-api-gateway-caching] No REST API found. Caching settings will not be updated.`); return; } diff --git a/src/restApiId.js b/src/restApiId.js index 8a86972..62b11c5 100644 --- a/src/restApiId.js +++ b/src/restApiId.js @@ -7,7 +7,10 @@ const getConfiguredRestApiId = (serverless) => { return get(serverless, 'service.provider.apiGateway.restApiId') } -const restApiExists = (serverless) => { +const restApiExists = (serverless, settings) => { + if (get(settings, 'restApiId')) { + return true; + } const configuredRestApiId = getConfiguredRestApiId(serverless); if (configuredRestApiId) { return true; @@ -24,12 +27,16 @@ const outputRestApiIdTo = (serverless) => { const autoGeneratedRestApiId = { Ref: 'ApiGatewayRestApi' }; serverless.service.provider.compiledCloudFormationTemplate.Outputs[REST_API_ID_KEY] = { - Description: 'Rest API Id', + Description: 'REST API ID', Value: configuredRestApiId || autoGeneratedRestApiId, }; }; const retrieveRestApiId = async (serverless, settings) => { + if (settings.restApiId) { + return settings.restApiId; + } + const stackName = serverless.providers.aws.naming.getStackName(settings.stage); const cloudFormation = await serverless.providers.aws.request('CloudFormation', 'describeStacks', { StackName: stackName }, diff --git a/test/configuring-rest-api-id.js b/test/configuring-rest-api-id.js index 76738dc..f49d3a7 100644 --- a/test/configuring-rest-api-id.js +++ b/test/configuring-rest-api-id.js @@ -2,33 +2,55 @@ const APP_ROOT = '..'; const given = require(`${APP_ROOT}/test/steps/given`); const expect = require('chai').expect; const { restApiExists } = require(`${APP_ROOT}/src/restApiId`); +const ApiGatewayCachingSettings = require(`${APP_ROOT}/src/ApiGatewayCachingSettings`); -describe('Finding the Rest API', () => { +describe('Finding the REST API', () => { let result; - describe('when the Rest API Id has already been defined in serverless configuration', () => { + + describe('when the REST API ID has been specified in the settings', () => { before(() => { - let serverless = given.a_serverless_instance() - .withPredefinedRestApiId(given.a_rest_api_id()); + let serverless = given + .a_serverless_instance() + .withApiGatewayCachingConfig({ restApiId: given.a_rest_api_id() }); + + let settings = new ApiGatewayCachingSettings(serverless); + + result = restApiExists(serverless, settings); + }); + + it('should return that the REST API exists', () => { + expect(result).to.be.true; + }); + }); + + describe('when the REST API ID has already been defined in serverless configuration', () => { + before(() => { + let serverless = given + .a_serverless_instance() + .withProviderRestApiId(given.a_rest_api_id()); + result = restApiExists(serverless); }); - it('should return that the Rest API exists', () => { + it('should return that the REST API exists', () => { expect(result).to.be.true; }); }); - describe('when the Rest API has not been defined in serverless configuration', () => { + describe('when the REST API has not been defined in serverless configuration', () => { describe('and there are HTTP handler functions', () => { before(() => { - let functionWithHttpEndpoint = given.a_serverless_function('get-cat-by-paw-id') + let functionWithHttpEndpoint = given + .a_serverless_function('get-cat-by-paw-id') .withHttpEndpoint('get', '/cat/{pawId}'); - serverless = given.a_serverless_instance() + serverless = given + .a_serverless_instance() .withFunction(functionWithHttpEndpoint); result = restApiExists(serverless); }); - it('should return that the Rest API does exist', () => { + it('should return that the REST API does exist', () => { expect(result).to.be.true; }); }); @@ -40,7 +62,7 @@ describe('Finding the Rest API', () => { result = restApiExists(serverless); }); - it('should return that the Rest API does not exist', () => { + it('should return that the REST API does not exist', () => { expect(result).to.be.false; }); }); diff --git a/test/creating-plugin.js b/test/creating-plugin.js index 5e357ac..2ddacdb 100644 --- a/test/creating-plugin.js +++ b/test/creating-plugin.js @@ -8,14 +8,14 @@ describe('Creating plugin', () => { describe('When updating the CloudFormation template', () => { let scenarios = [ { - description: 'there is no rest api', + description: 'there is no REST API', thereIsARestApi: false, - expectedLogMessage: '[serverless-api-gateway-caching] No Rest API found. Caching settings will not be updated.', + expectedLogMessage: '[serverless-api-gateway-caching] No REST API found. Caching settings will not be updated.', expectedToOutputRestApiId: false, expectedToAddPathParametersCacheConfig: false }, { - description: 'there is a rest api and caching is enabled', + description: 'there is a REST API and caching is enabled', cachingEnabled: true, thereIsARestApi: true, expectedLogMessage: undefined, @@ -23,7 +23,7 @@ describe('Creating plugin', () => { expectedToAddPathParametersCacheConfig: true, }, { - description: 'there is a rest api and caching is disabled', + description: 'there is a REST API and caching is disabled', cachingEnabled: false, thereIsARestApi: true, expectedLogMessage: undefined, @@ -55,7 +55,7 @@ describe('Creating plugin', () => { expect(logCalledWith).to.equal(scenario.expectedLogMessage); }); - it(`is expected to output rest api id: ${scenario.expectedToOutputRestApiId}`, () => { + it(`is expected to output REST API ID: ${scenario.expectedToOutputRestApiId}`, () => { expect(outputRestApiIdCalled).to.equal(scenario.expectedToOutputRestApiId); }); @@ -69,14 +69,14 @@ describe('Creating plugin', () => { describe('When updating the stage', () => { let scenarios = [ { - description: 'there is no rest api', + description: 'there is no REST API', thereIsARestApi: false, - expectedLogMessage: '[serverless-api-gateway-caching] No Rest API found. Caching settings will not be updated.', + expectedLogMessage: '[serverless-api-gateway-caching] No REST API found. Caching settings will not be updated.', expectedToUpdateStageCache: false, expectedToHaveSettings: false }, { - description: 'there is a rest api', + description: 'there is a REST API', thereIsARestApi: true, expectedLogMessage: undefined, expectedToUpdateStageCache: true, diff --git a/test/model/Serverless.js b/test/model/Serverless.js index 756d6f4..e810248 100644 --- a/test/model/Serverless.js +++ b/test/model/Serverless.js @@ -33,10 +33,11 @@ class Serverless { return this; } - withApiGatewayCachingConfig({ cachingEnabled = true, clusterSize = '0.5', ttlInSeconds = 45, perKeyInvalidation, dataEncrypted, apiGatewayIsShared } = {}) { + withApiGatewayCachingConfig({ cachingEnabled = true, clusterSize = '0.5', ttlInSeconds = 45, perKeyInvalidation, dataEncrypted, apiGatewayIsShared, restApiId } = {}) { this.service.custom.apiGatewayCaching = { enabled: cachingEnabled, apiGatewayIsShared, + restApiId, clusterSize, ttlInSeconds, perKeyInvalidation, @@ -70,7 +71,7 @@ class Serverless { return this; } - withPredefinedRestApiId(restApiId) { + withProviderRestApiId(restApiId) { if (!this.service.provider.apiGateway) { this.service.provider.apiGateway = {} } diff --git a/test/updating-stage-cache-settings-for-additional-endpoints.js b/test/updating-stage-cache-settings-for-additional-endpoints.js index f25b5cb..e5910d6 100644 --- a/test/updating-stage-cache-settings-for-additional-endpoints.js +++ b/test/updating-stage-cache-settings-for-additional-endpoints.js @@ -40,7 +40,7 @@ describe('Updating stage cache settings for additional endpoints defined as Clou apiGatewayRequest = requestsToAws.find(r => r.awsService == apiGatewayService && r.method == updateStageMethod); }); - it('should contain the Rest Api Id', () => { + it('should contain the REST API ID', () => { expect(apiGatewayRequest.properties.restApiId).to.equal(restApiId); }); diff --git a/test/updating-stage-cache-settings.js b/test/updating-stage-cache-settings.js index d999984..6b79f9a 100644 --- a/test/updating-stage-cache-settings.js +++ b/test/updating-stage-cache-settings.js @@ -57,7 +57,7 @@ describe('Updating stage cache settings', () => { expect(apiGatewayRequest.region).to.equal('someregion'); }); - it('should contain the Rest Api Id', () => { + it('should contain the REST API ID', () => { expect(apiGatewayRequest.properties.restApiId).to.equal(restApiId); }); @@ -132,7 +132,7 @@ describe('Updating stage cache settings', () => { apiGatewayRequest = requestsToAws.find(r => r.awsService == apiGatewayService && r.method == updateStageMethod); }); - it('should contain the Rest Api Id', () => { + it('should contain the REST API ID', () => { expect(apiGatewayRequest.properties.restApiId).to.equal(restApiId); }); @@ -240,7 +240,7 @@ describe('Updating stage cache settings', () => { apiGatewayRequest = requestsToAws.find(r => r.awsService == apiGatewayService && r.method == updateStageMethod); }); - it('should contain the Rest Api Id', () => { + it('should contain the REST API ID', () => { expect(apiGatewayRequest.properties.restApiId).to.equal(restApiId); }); @@ -318,7 +318,7 @@ describe('Updating stage cache settings', () => { apiGatewayRequest = requestsToAws.find(r => r.awsService == apiGatewayService && r.method == updateStageMethod); }); - it('should contain the Rest Api Id', () => { + it('should contain the REST API ID', () => { expect(apiGatewayRequest.properties.restApiId).to.equal(restApiId); }); @@ -702,7 +702,7 @@ describe('Updating stage cache settings', () => { secondRequestToUpdateStage = requestsToAwsToUpdateStage[1]; }); - it('should specify the Rest Api Id', () => { + it('should specify the REST API ID', () => { expect(firstRequestToUpdateStage.properties.restApiId).to.equal(restApiId); expect(secondRequestToUpdateStage.properties.restApiId).to.equal(restApiId); }); From 81bd0ec0b528a1e279abe51639dc62c058bc6b23 Mon Sep 17 00:00:00 2001 From: Scott Smethurst Date: Tue, 6 Apr 2021 21:32:22 +0100 Subject: [PATCH 2/5] =?UTF-8?q?Added=20an=20optional=20=E2=80=98basePath?= =?UTF-8?q?=E2=80=99=20setting=20for=20when=20a=20shared=20API=20Gateway?= =?UTF-8?q?=20has=20a=20default=20base=20path=20that=20is=20not=20part=20o?= =?UTF-8?q?f=20the=20endpoint=20configuration.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 ++- src/ApiGatewayCachingSettings.js | 9 +++++ test/configuring-a-default-base-path.js | 54 +++++++++++++++++++++++++ test/configuring-path-parameters.js | 2 +- test/model/Serverless.js | 3 +- 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 test/configuring-a-default-base-path.js diff --git a/README.md b/README.md index af1300f..cc760dc 100644 --- a/README.md +++ b/README.md @@ -267,7 +267,9 @@ Cache key parameters coming from multi-value query strings and multi-value heade ## Configuring a shared API Gateway Setting `apiGatewayIsShared` to `true` means that no changes are applied to the root caching configuration of the API Gateway. However, `ttlInSeconds`, `dataEncryption` and `perKeyInvalidation` are still applied to all functions, unless specifically overridden. -You can also optionally specify the `restApiId` of the shared API Gateway if you have exported that from a different CloudFormation stack. If a `restApiId` is not specified, the plugin will automatically try to find one in the stack that's being deployed. +If the shared API Gateway is in a different CloudFormation stack, you'll need to export its `RestApiId` and pass it to the plugin via the optional `restApiId` setting. If the gateway is part of the stack you are deploying, you don't need to do this; the plugin will find the `RestApiId` automatically. + +If the shared gateway has a default base path that is not part of your endpoint configuration, you can specify it using the optional `basePath` setting. ```yml plugins: @@ -278,6 +280,7 @@ custom: enabled: true apiGatewayIsShared: true restApiId: ${cf:api-gateway-${self:provider.stage}.RestApiId} + basePath: /animals clusterSize: '0.5' ttlInSeconds: 300 dataEncrypted: true diff --git a/src/ApiGatewayCachingSettings.js b/src/ApiGatewayCachingSettings.js index fb7d0cd..1238ab4 100644 --- a/src/ApiGatewayCachingSettings.js +++ b/src/ApiGatewayCachingSettings.js @@ -57,6 +57,14 @@ class ApiGatewayEndpointCachingSettings { this.path = this.path.slice(0, -1); } + let { basePath } = globalSettings; + if (basePath) { + if (!basePath.endsWith('/')) { + basePath = basePath.concat('/'); + } + this.path = basePath.concat(this.path); + } + if (!event.http.caching) { this.cachingEnabled = false; return; @@ -96,6 +104,7 @@ class ApiGatewayCachingSettings { this.cachingEnabled = cachingSettings.enabled; this.apiGatewayIsShared = cachingSettings.apiGatewayIsShared; this.restApiId = cachingSettings.restApiId; + this.basePath = cachingSettings.basePath; if (options) { this.stage = options.stage || serverless.service.provider.stage; diff --git a/test/configuring-a-default-base-path.js b/test/configuring-a-default-base-path.js new file mode 100644 index 0000000..2bd0009 --- /dev/null +++ b/test/configuring-a-default-base-path.js @@ -0,0 +1,54 @@ +const APP_ROOT = '..'; +const given = require(`${APP_ROOT}/test/steps/given`); +const expect = require('chai').expect; +const ApiGatewayCachingSettings = require(`${APP_ROOT}/src/ApiGatewayCachingSettings`); + +describe('Configuring a default base path', () => { + const serviceName = 'cat-api'; + const basePath = '/animals'; + const endpointPath = '/cat/{pawId}'; + const functionName = 'get-cat-by-paw-id'; + + let settings; + + describe('when a base path is specified in the global settings', () => { + before(() => { + const endpoint = given.a_serverless_function(functionName) + .withHttpEndpoint('get', endpointPath, { enabled: true }); + + const serverless = given.a_serverless_instance(serviceName) + .withApiGatewayCachingConfig({ basePath: '/animals' }) + .withFunction(endpoint); + + settings = new ApiGatewayCachingSettings(serverless); + }); + + it('should be prepended to each endpoint path', () => { + expect(path_of(functionName, settings)).to.equal(`${basePath}/${endpointPath}`); + }); + }); + + describe('when no base path is specified', () => { + before(() => { + const endpoint = given.a_serverless_function(functionName) + .withHttpEndpoint('get', endpointPath, { enabled: true }); + + const serverless = given.a_serverless_instance(serviceName) + .withApiGatewayCachingConfig() + .withFunction(endpoint); + + settings = new ApiGatewayCachingSettings(serverless); + }); + + it('should be prepended to each endpoint path', () => { + expect(path_of(functionName, settings)).to.equal(endpointPath); + }); + }); +}); + +const path_of = (functionName, settings) => { + return settings + .endpointSettings + .find(x => x.functionName === functionName) + .path; +} diff --git a/test/configuring-path-parameters.js b/test/configuring-path-parameters.js index 4029426..b814872 100644 --- a/test/configuring-path-parameters.js +++ b/test/configuring-path-parameters.js @@ -634,7 +634,7 @@ describe('Configuring path parameter caching', () => { expect(method.Properties.Integration.CacheNamespace).to.exist; }); }); - }) + }); }); const when_configuring_path_parameters = (serverless) => { diff --git a/test/model/Serverless.js b/test/model/Serverless.js index e810248..6cd0b75 100644 --- a/test/model/Serverless.js +++ b/test/model/Serverless.js @@ -33,11 +33,12 @@ class Serverless { return this; } - withApiGatewayCachingConfig({ cachingEnabled = true, clusterSize = '0.5', ttlInSeconds = 45, perKeyInvalidation, dataEncrypted, apiGatewayIsShared, restApiId } = {}) { + withApiGatewayCachingConfig({ cachingEnabled = true, clusterSize = '0.5', ttlInSeconds = 45, perKeyInvalidation, dataEncrypted, apiGatewayIsShared, restApiId, basePath } = {}) { this.service.custom.apiGatewayCaching = { enabled: cachingEnabled, apiGatewayIsShared, restApiId, + basePath, clusterSize, ttlInSeconds, perKeyInvalidation, From 7351a210c27787536f36f18a894f654b985c21c1 Mon Sep 17 00:00:00 2001 From: Scott Smethurst Date: Tue, 6 Apr 2021 21:39:28 +0100 Subject: [PATCH 3/5] Fixed test description. --- test/configuring-a-default-base-path.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/configuring-a-default-base-path.js b/test/configuring-a-default-base-path.js index 2bd0009..51a3120 100644 --- a/test/configuring-a-default-base-path.js +++ b/test/configuring-a-default-base-path.js @@ -40,7 +40,7 @@ describe('Configuring a default base path', () => { settings = new ApiGatewayCachingSettings(serverless); }); - it('should be prepended to each endpoint path', () => { + it('should just use the endpoint path', () => { expect(path_of(functionName, settings)).to.equal(endpointPath); }); }); From 18e9dbe734147529e38dc6967bc1bcfd0fe92b0c Mon Sep 17 00:00:00 2001 From: Scott Smethurst Date: Wed, 7 Apr 2021 14:00:52 +0100 Subject: [PATCH 4/5] Fixed a bug related to prepending a base path to endpoint paths, and extended the unit tests to provide coverage. --- src/ApiGatewayCachingSettings.js | 7 ++- test/configuring-a-default-base-path.js | 61 +++++++++++++++++-------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/ApiGatewayCachingSettings.js b/src/ApiGatewayCachingSettings.js index 1238ab4..a133fbb 100644 --- a/src/ApiGatewayCachingSettings.js +++ b/src/ApiGatewayCachingSettings.js @@ -59,8 +59,11 @@ class ApiGatewayEndpointCachingSettings { let { basePath } = globalSettings; if (basePath) { - if (!basePath.endsWith('/')) { - basePath = basePath.concat('/'); + if (!basePath.startsWith('/')) { + basePath = '/'.concat(basePath); + } + if (basePath.endsWith('/')) { + basePath = basePath.slice(0, -1); } this.path = basePath.concat(this.path); } diff --git a/test/configuring-a-default-base-path.js b/test/configuring-a-default-base-path.js index 51a3120..f44e59e 100644 --- a/test/configuring-a-default-base-path.js +++ b/test/configuring-a-default-base-path.js @@ -5,35 +5,56 @@ const ApiGatewayCachingSettings = require(`${APP_ROOT}/src/ApiGatewayCachingSett describe('Configuring a default base path', () => { const serviceName = 'cat-api'; - const basePath = '/animals'; const endpointPath = '/cat/{pawId}'; const functionName = 'get-cat-by-paw-id'; - let settings; - - describe('when a base path is specified in the global settings', () => { - before(() => { - const endpoint = given.a_serverless_function(functionName) - .withHttpEndpoint('get', endpointPath, { enabled: true }); - - const serverless = given.a_serverless_instance(serviceName) - .withApiGatewayCachingConfig({ basePath: '/animals' }) - .withFunction(endpoint); - - settings = new ApiGatewayCachingSettings(serverless); - }); - - it('should be prepended to each endpoint path', () => { - expect(path_of(functionName, settings)).to.equal(`${basePath}/${endpointPath}`); - }); + describe('when a base path is specified', () => { + const scenarios = [ + { + description: 'does not start with a forward slash', + basePath: 'animals' + }, + { + description: 'starts with a forward slash', + basePath: '/animals' + }, + { + description: 'has a trailing slash', + basePath: 'animals/' + } + ]; + let settings; + + for (scenario of scenarios) { + describe(`and ${scenario.description}`, () => { + before(() => { + const endpoint = given + .a_serverless_function(functionName) + .withHttpEndpoint('get', endpointPath, { enabled: true }); + + const serverless = given + .a_serverless_instance(serviceName) + .withApiGatewayCachingConfig({ basePath: scenario.basePath }) + .withFunction(endpoint); + + settings = new ApiGatewayCachingSettings(serverless); + }); + + it('should be prepended to each endpoint and form a valid path', () => { + expect(path_of(functionName, settings)).to.equal(`/animals${endpointPath}`); + }); + }); + } }); describe('when no base path is specified', () => { before(() => { - const endpoint = given.a_serverless_function(functionName) + const endpoint = given + .a_serverless_function(functionName) .withHttpEndpoint('get', endpointPath, { enabled: true }); - const serverless = given.a_serverless_instance(serviceName) + const serverless = given + .a_serverless_instance(serviceName) .withApiGatewayCachingConfig() .withFunction(endpoint); From e16b0476fb02e6dcb52265eab1881f651ebc698a Mon Sep 17 00:00:00 2001 From: Diana Ionita Date: Wed, 7 Apr 2021 14:19:57 +0100 Subject: [PATCH 5/5] Version++ --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2f79a85..81f98a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "serverless-api-gateway-caching", - "version": "1.6.1", + "version": "1.7.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1158,9 +1158,9 @@ "dev": true }, "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.2.tgz", + "integrity": "sha512-DnBDwcL54b5xWMM/7RfFg4xs5amYxq2ot49aUfLjQSAracXkGvlZq0txzqr3Pa6Q0ayuCxBcwTzrPUScKY0O8w==", "dev": true }, "yargs": { diff --git a/package.json b/package.json index 4e17d0a..28f8b9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "serverless-api-gateway-caching", - "version": "1.6.1", + "version": "1.7.0", "description": "A plugin for the serverless framework which helps with configuring caching for API Gateway endpoints.", "main": "src/apiGatewayCachingPlugin.js", "scripts": {