Skip to content

Commit 41a1998

Browse files
author
diana.ionita
committed
Merge branch 'release/1.1.4'
2 parents df09eb6 + 1d0277a commit 41a1998

File tree

4 files changed

+58
-11
lines changed

4 files changed

+58
-11
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.1.3",
3+
"version": "1.1.4",
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ const addPathParametersCacheConfig = (settings, serverless) => {
4848
}
4949

5050
for (let cacheKeyParameter of endpointSettings.cacheKeyParameters) {
51-
method.resource.Properties.RequestParameters[`method.${cacheKeyParameter.name}`] = true;
51+
let existingValue = method.resource.Properties.RequestParameters[`method.${cacheKeyParameter.name}`];
52+
method.resource.Properties.RequestParameters[`method.${cacheKeyParameter.name}`] = (existingValue == null || existingValue == undefined) ? {} : existingValue;
5253
method.resource.Properties.Integration.RequestParameters[`integration.${cacheKeyParameter.name}`] = `method.${cacheKeyParameter.name}`;
5354
method.resource.Properties.Integration.CacheKeyParameters.push(`method.${cacheKeyParameter.name}`);
5455
}

test/configuring-path-parameters.js

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ describe('Configuring path parameter caching', () => {
7171
method = serverless.getMethodResourceForFunction(functionWithCachingName);
7272
});
7373

74-
it('should set that request parameters are part of the cache key', () => {
75-
for (let parameter of cacheKeyParameters) {
76-
expect(method.Properties.RequestParameters)
77-
.to.deep.include({
78-
[`method.${parameter.name}`]: true
79-
});
80-
}
74+
it('should configure them as request parameters', () => {
75+
for (let parameter of cacheKeyParameters) {
76+
expect(method.Properties.RequestParameters)
77+
.to.deep.include({
78+
[`method.${parameter.name}`]: {}
79+
});
80+
}
8181
});
8282

8383
it('should set integration request parameters', () => {
@@ -101,7 +101,7 @@ describe('Configuring path parameter caching', () => {
101101
});
102102
});
103103

104-
describe('on the method resource correspondin with the endpoint without cache key parameters', () => {
104+
describe('on the method resource corresponding with the endpoint without cache key parameters', () => {
105105
before(() => {
106106
method = serverless.getMethodResourceForFunction(functionWithoutCachingName);
107107
});
@@ -123,6 +123,52 @@ describe('Configuring path parameter caching', () => {
123123
});
124124
});
125125
});
126+
127+
describe('when one endpoint has cache key parameters', () => {
128+
let cacheKeyParameters, functionWithCachingName;
129+
before(() => {
130+
functionWithCachingName = 'get-cat-by-paw-id';
131+
cacheKeyParameters = [{ name: 'request.path.pawId' }, { name: 'request.header.Accept-Language' }];
132+
133+
let functionWithCaching = given.a_serverless_function(functionWithCachingName)
134+
.withHttpEndpoint('get', '/cat/{pawId}', { enabled: true, cacheKeyParameters });
135+
136+
serverless = given.a_serverless_instance(serviceName)
137+
.withApiGatewayCachingConfig(true, '0.5', 45)
138+
.forStage(stage)
139+
.withFunction(functionWithCaching);
140+
});
141+
142+
let alreadyConfiguredParamsScenarios = [
143+
{
144+
description: "required",
145+
isRequired: true
146+
},
147+
{
148+
description: "not required",
149+
isRequired: false
150+
}
151+
];
152+
for (let { description, isRequired } of alreadyConfiguredParamsScenarios) {
153+
describe(`and one of them has been already configured as ${description} for http request validation by another plugin`, () => {
154+
let method;
155+
before(() => {
156+
method = serverless.getMethodResourceForFunction(functionWithCachingName);
157+
method.Properties.RequestParameters[`method.${cacheKeyParameters[0].name}`] = isRequired;
158+
159+
cacheSettings = new ApiGatewayCachingSettings(serverless);
160+
when_configuring_path_parameters(cacheSettings, serverless)
161+
});
162+
163+
it('should keep configuration', () => {
164+
expect(method.Properties.RequestParameters)
165+
.to.deep.include({
166+
[`method.${cacheKeyParameters[0].name}`]: isRequired
167+
});
168+
});
169+
});
170+
}
171+
});
126172
});
127173

128174
const when_configuring_path_parameters = (settings, serverless) => {

0 commit comments

Comments
 (0)