Skip to content

Commit 759c0d7

Browse files
author
diana.ionita
committed
Merge branch 'release/1.2.2'
2 parents 162d771 + c0a74a0 commit 759c0d7

File tree

4 files changed

+63
-8
lines changed

4 files changed

+63
-8
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-api-gateway-caching",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "A plugin for the serverless framework which helps with configuring caching for API Gateway endpoints.",
55
"main": "src/apiGatewayCachingPlugin.js",
66
"scripts": {

src/pathParametersCache.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const getApiGatewayMethodNameFor = (path, httpMethod) => {
1515
let gatewayResourceName = pathElements
1616
.map(element => {
1717
element = element.toLowerCase();
18-
element = element.replace('+', '');
18+
element = element.replaceAll('+', '');
19+
element = element.replaceAll('_', '');
1920
if (element.startsWith('{')) {
2021
element = element.substring(element.indexOf('{') + 1, element.indexOf('}')) + "Var";
2122
}
@@ -37,11 +38,7 @@ const addPathParametersCacheConfig = (settings, serverless) => {
3738
if (!method) {
3839
serverless.cli.log(`[serverless-api-gateway-caching] The method ${resourceName} couldn't be found in the
3940
compiled CloudFormation template. Caching settings will not be updated for this endpoint.`);
40-
const index = settings.endpointSettings.indexOf(endpointSettings);
41-
if (index != -1) {
42-
settings.endpointSettings.splice(index, 1);
43-
}
44-
return;
41+
continue;
4542
}
4643
if (!method.Properties.Integration.CacheKeyParameters) {
4744
method.Properties.Integration.CacheKeyParameters = [];

test/configuring-path-parameters.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,64 @@ describe('Configuring path parameter caching', () => {
121121
});
122122
});
123123

124+
describe('when one endpoint has cache key parameters and a path parameter containing underscore', () => {
125+
let cacheKeyParameters, method;
126+
let functionWithoutCachingName, functionWithCachingName;
127+
before(() => {
128+
functionWithoutCachingName = 'list-all-cats';
129+
let functionWithoutCaching = given.a_serverless_function(functionWithoutCachingName)
130+
.withHttpEndpoint('get', '/cats');
131+
132+
functionWithCachingName = 'get-cat-by-paw-id';
133+
cacheKeyParameters = [{ name: 'request.path.paw_id' }, { name: 'request.header.Accept-Language' }];
134+
let functionWithCaching = given.a_serverless_function(functionWithCachingName)
135+
.withHttpEndpoint('get', '/cat/{paw_id}', { enabled: true, cacheKeyParameters });
136+
137+
serverless = given.a_serverless_instance(serviceName)
138+
.withApiGatewayCachingConfig(true, '0.5', 45)
139+
.forStage(stage)
140+
.withFunction(functionWithCaching)
141+
.withFunction(functionWithoutCaching);
142+
143+
when_configuring_path_parameters(serverless);
144+
});
145+
146+
describe('on the method corresponding with the endpoint with cache key parameters', () => {
147+
before(() => {
148+
method = serverless.getMethodResourceForFunction(functionWithCachingName);
149+
});
150+
151+
it('should configure them as request parameters', () => {
152+
for (let parameter of cacheKeyParameters) {
153+
expect(method.Properties.RequestParameters)
154+
.to.deep.include({
155+
[`method.${parameter.name}`]: {}
156+
});
157+
}
158+
});
159+
160+
it('should set integration request parameters', () => {
161+
for (let parameter of cacheKeyParameters) {
162+
expect(method.Properties.Integration.RequestParameters)
163+
.to.deep.include({
164+
[`integration.${parameter.name}`]: `method.${parameter.name}`
165+
});
166+
}
167+
});
168+
169+
it('should set integration cache key parameters', () => {
170+
for (let parameter of cacheKeyParameters) {
171+
expect(method.Properties.Integration.CacheKeyParameters)
172+
.to.include(`method.${parameter.name}`);
173+
}
174+
});
175+
176+
it('should set a cache namespace', () => {
177+
expect(method.Properties.Integration.CacheNamespace).to.exist;
178+
});
179+
});
180+
});
181+
124182
describe('when one endpoint has cache key parameters', () => {
125183
let cacheKeyParameters, functionWithCachingName;
126184
before(() => {

0 commit comments

Comments
 (0)