Skip to content

Commit dacd06e

Browse files
author
diana.ionita
committed
Merge branch 'release/1.1.5'
2 parents 41a1998 + 5a0c7c9 commit dacd06e

5 files changed

+103
-5
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-api-gateway-caching",
3-
"version": "1.1.4",
3+
"version": "1.1.5",
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const getApiGatewayMethodFor = (functionName, stage, serverless) => {
2828
const methods = getResourcesByType('AWS::ApiGateway::Method', serverless);
2929
for (let method of methods) {
3030
let stringified = JSON.stringify(method);
31-
if (stringified.lastIndexOf(lambdaFunctionResource.name) != -1) {
31+
if (stringified.lastIndexOf(`"${lambdaFunctionResource.name}"`) != -1) {
3232
return method;
3333
}
3434
}

test/configuring-path-parameters.js

+98
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,104 @@ describe('Configuring path parameter caching', () => {
169169
});
170170
}
171171
});
172+
173+
describe('when there are two endpoints with a cache key parameter', () => {
174+
describe(`and the second endpoint's name is a substring of the first endpoint's name`, () => {
175+
let method, firstEndpointName, firstEndpointCacheKeyParameters, secondEndpointName, secondEndpointCacheKeyParameters;
176+
before(() => {
177+
firstEndpointName = 'catpaw';
178+
secondEndpointName = 'paw';
179+
firstEndpointCacheKeyParameters = [{ name: 'request.path.catPawId' }];
180+
secondEndpointCacheKeyParameters = [{ name: 'request.path.pawId' }];
181+
182+
let firstFunctionWithCaching = given.a_serverless_function(firstEndpointName)
183+
.withHttpEndpoint('get', '/cat/paw/{pawId}', { enabled: true, cacheKeyParameters: firstEndpointCacheKeyParameters });
184+
185+
let secondFunctionWithCaching = given.a_serverless_function(secondEndpointName)
186+
.withHttpEndpoint('get', '/paw/{catPawId}', { enabled: true, cacheKeyParameters: secondEndpointCacheKeyParameters });
187+
188+
serverless = given.a_serverless_instance(serviceName)
189+
.withApiGatewayCachingConfig(true, '0.5', 45)
190+
.forStage(stage)
191+
.withFunction(firstFunctionWithCaching)
192+
.withFunction(secondFunctionWithCaching);
193+
194+
cacheSettings = new ApiGatewayCachingSettings(serverless);
195+
196+
when_configuring_path_parameters(cacheSettings, serverless);
197+
});
198+
199+
describe('on the method corresponding with the first endpoint with cache key parameters', () => {
200+
before(() => {
201+
method = serverless.getMethodResourceForFunction(firstEndpointName);
202+
});
203+
204+
it('should configure them as request parameters', () => {
205+
for (let parameter of firstEndpointCacheKeyParameters) {
206+
expect(method.Properties.RequestParameters)
207+
.to.deep.include({
208+
[`method.${parameter.name}`]: {}
209+
});
210+
}
211+
});
212+
213+
it('should set integration request parameters', () => {
214+
for (let parameter of firstEndpointCacheKeyParameters) {
215+
expect(method.Properties.Integration.RequestParameters)
216+
.to.deep.include({
217+
[`integration.${parameter.name}`]: `method.${parameter.name}`
218+
});
219+
}
220+
});
221+
222+
it('should set integration cache key parameters', () => {
223+
for (let parameter of firstEndpointCacheKeyParameters) {
224+
expect(method.Properties.Integration.CacheKeyParameters)
225+
.to.include(`method.${parameter.name}`);
226+
}
227+
});
228+
229+
it('should set a cache namespace', () => {
230+
expect(method.Properties.Integration.CacheNamespace).to.exist;
231+
});
232+
});
233+
234+
describe('on the method corresponding with the second endpoint with cache key parameters', () => {
235+
before(() => {
236+
method = serverless.getMethodResourceForFunction(secondEndpointName);
237+
});
238+
239+
it('should configure them as request parameters', () => {
240+
for (let parameter of secondEndpointCacheKeyParameters) {
241+
expect(method.Properties.RequestParameters)
242+
.to.deep.include({
243+
[`method.${parameter.name}`]: {}
244+
});
245+
}
246+
});
247+
248+
it('should set integration request parameters', () => {
249+
for (let parameter of secondEndpointCacheKeyParameters) {
250+
expect(method.Properties.Integration.RequestParameters)
251+
.to.deep.include({
252+
[`integration.${parameter.name}`]: `method.${parameter.name}`
253+
});
254+
}
255+
});
256+
257+
it('should set integration cache key parameters', () => {
258+
for (let parameter of secondEndpointCacheKeyParameters) {
259+
expect(method.Properties.Integration.CacheKeyParameters)
260+
.to.include(`method.${parameter.name}`);
261+
}
262+
});
263+
264+
it('should set a cache namespace', () => {
265+
expect(method.Properties.Integration.CacheNamespace).to.exist;
266+
});
267+
});
268+
});
269+
});
172270
});
173271

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

test/model/Serverless.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ const addFunctionToCompiledCloudFormationTemplate = (functionName, serverless) =
112112
let { Resources } = serverless.service.provider.compiledCloudFormationTemplate;
113113
let functionTemplate = clone(require('./templates/aws-lambda-function'));
114114
functionTemplate.Properties.FunctionName = fullFunctionName;
115-
let functionResourceName = chance.word({ length: 10 });
115+
let functionResourceName = `${functionName}LambdaFunction`;
116116
Resources[functionResourceName] = functionTemplate;
117117

118118
let methodTemplate = clone(require('./templates/aws-api-gateway-method'));
119119
let stringifiedMethodTemplate = JSON.stringify(methodTemplate);
120120
stringifiedMethodTemplate = stringifiedMethodTemplate.replace('#{LAMBDA_RESOURCE_DEPENDENCY}', functionResourceName);
121121
methodTemplate = JSON.parse(stringifiedMethodTemplate);
122-
methodResourceName = chance.word({ length: 12 });
122+
methodResourceName = `ApiGatewayMethod${functionName}VarGet`;
123123
Resources[methodResourceName] = methodTemplate
124124
return { functionResourceName, methodResourceName }
125125
}

0 commit comments

Comments
 (0)