@@ -5,20 +5,19 @@ const pathParams = require(`${APP_ROOT}/src/pathParametersCache`);
5
5
const expect = require ( 'chai' ) . expect ;
6
6
7
7
describe ( 'Configuring path parameter caching' , ( ) => {
8
- let serverless , cacheSettings ;
8
+ let serverless ;
9
9
let serviceName = 'cat-api' , stage = 'dev' ;
10
10
11
11
describe ( 'when there are no endpoints' , ( ) => {
12
12
before ( ( ) => {
13
13
serverless = given . a_serverless_instance ( serviceName )
14
14
. withApiGatewayCachingConfig ( true , '0.5' , 45 )
15
15
. forStage ( stage ) ;
16
- cacheSettings = new ApiGatewayCachingSettings ( serverless ) ;
17
16
} ) ;
18
17
19
18
it ( 'should do nothing to the serverless instance' , ( ) => {
20
19
let stringified = JSON . stringify ( serverless ) ;
21
- when_configuring_path_parameters ( cacheSettings , serverless ) ;
20
+ when_configuring_path_parameters ( serverless ) ;
22
21
let stringifiedAfter = JSON . stringify ( serverless ) ;
23
22
expect ( stringified ) . to . equal ( stringifiedAfter ) ;
24
23
} ) ;
@@ -32,12 +31,11 @@ describe('Configuring path parameter caching', () => {
32
31
. withApiGatewayCachingConfig ( true , '0.5' , 45 )
33
32
. forStage ( stage )
34
33
. withFunction ( endpoint ) ;
35
- cacheSettings = new ApiGatewayCachingSettings ( serverless ) ;
36
34
} ) ;
37
35
38
36
it ( 'should do nothing to the serverless instance' , ( ) => {
39
37
let stringified = JSON . stringify ( serverless ) ;
40
- when_configuring_path_parameters ( cacheSettings , serverless ) ;
38
+ when_configuring_path_parameters ( serverless ) ;
41
39
let stringifiedAfter = JSON . stringify ( serverless ) ;
42
40
expect ( stringified ) . to . equal ( stringifiedAfter ) ;
43
41
} ) ;
@@ -61,9 +59,8 @@ describe('Configuring path parameter caching', () => {
61
59
. forStage ( stage )
62
60
. withFunction ( functionWithCaching )
63
61
. withFunction ( functionWithoutCaching ) ;
64
- cacheSettings = new ApiGatewayCachingSettings ( serverless ) ;
65
62
66
- when_configuring_path_parameters ( cacheSettings , serverless ) ;
63
+ when_configuring_path_parameters ( serverless ) ;
67
64
} ) ;
68
65
69
66
describe ( 'on the method corresponding with the endpoint with cache key parameters' , ( ) => {
@@ -156,8 +153,7 @@ describe('Configuring path parameter caching', () => {
156
153
method = serverless . getMethodResourceForFunction ( functionWithCachingName ) ;
157
154
method . Properties . RequestParameters [ `method.${ cacheKeyParameters [ 0 ] . name } ` ] = isRequired ;
158
155
159
- cacheSettings = new ApiGatewayCachingSettings ( serverless ) ;
160
- when_configuring_path_parameters ( cacheSettings , serverless )
156
+ when_configuring_path_parameters ( serverless )
161
157
} ) ;
162
158
163
159
it ( 'should keep configuration' , ( ) => {
@@ -191,9 +187,7 @@ describe('Configuring path parameter caching', () => {
191
187
. withFunction ( firstFunctionWithCaching )
192
188
. withFunction ( secondFunctionWithCaching ) ;
193
189
194
- cacheSettings = new ApiGatewayCachingSettings ( serverless ) ;
195
-
196
- when_configuring_path_parameters ( cacheSettings , serverless ) ;
190
+ when_configuring_path_parameters ( serverless ) ;
197
191
} ) ;
198
192
199
193
describe ( 'on the method corresponding with the first endpoint with cache key parameters' , ( ) => {
@@ -267,26 +261,25 @@ describe('Configuring path parameter caching', () => {
267
261
} ) ;
268
262
} ) ;
269
263
} ) ;
264
+
270
265
describe ( 'when there are two endpoints with a cache key parameter on the same function' , ( ) => {
271
- let method , functionName , firstEndpointCacheKeyParameters , secondEndpointCacheKeyParameters ;
272
- before ( ( ) => {
273
- functionName = 'catpaw' ;
274
-
275
- firstEndpointCacheKeyParameters = [ { name : 'request.path.pawId' } ] ;
276
- secondEndpointCacheKeyParameters = [ { name : 'request.path.pawId' } ] ;
266
+ let method , functionName , firstEndpointCacheKeyParameters , secondEndpointCacheKeyParameters ;
267
+ before ( ( ) => {
268
+ functionName = 'catpaw' ;
277
269
278
- let firstFunctionWithCaching = given . a_serverless_function ( functionName )
279
- . withHttpEndpoint ( 'get' , '/cat/paw/{pawId}' , { enabled : true , cacheKeyParameters : firstEndpointCacheKeyParameters } )
280
- . withHttpEndpoint ( 'delete' , '/cat/paw/{pawId}' , { enabled : true , cacheKeyParameters : secondEndpointCacheKeyParameters } ) ;
281
- serverless = given . a_serverless_instance ( serviceName )
282
- . withApiGatewayCachingConfig ( true , '0.5' , 45 )
283
- . forStage ( stage )
284
- . withFunction ( firstFunctionWithCaching )
285
-
286
- cacheSettings = new ApiGatewayCachingSettings ( serverless ) ;
270
+ firstEndpointCacheKeyParameters = [ { name : 'request.path.pawId' } ] ;
271
+ secondEndpointCacheKeyParameters = [ { name : 'request.path.pawId' } ] ;
287
272
288
- when_configuring_path_parameters ( cacheSettings , serverless ) ;
289
- } ) ;
273
+ let firstFunctionWithCaching = given . a_serverless_function ( functionName )
274
+ . withHttpEndpoint ( 'get' , '/cat/paw/{pawId}' , { enabled : true , cacheKeyParameters : firstEndpointCacheKeyParameters } )
275
+ . withHttpEndpoint ( 'delete' , '/cat/paw/{pawId}' , { enabled : true , cacheKeyParameters : secondEndpointCacheKeyParameters } ) ;
276
+ serverless = given . a_serverless_instance ( serviceName )
277
+ . withApiGatewayCachingConfig ( true , '0.5' , 45 )
278
+ . forStage ( stage )
279
+ . withFunction ( firstFunctionWithCaching )
280
+
281
+ when_configuring_path_parameters ( serverless ) ;
282
+ } ) ;
290
283
291
284
describe ( 'on the method corresponding with the first endpoint with cache key parameters' , ( ) => {
292
285
before ( ( ) => {
@@ -324,7 +317,7 @@ describe('Configuring path parameter caching', () => {
324
317
} ) ;
325
318
326
319
describe ( 'on the method corresponding with the second endpoint with cache key parameters' , ( ) => {
327
- before ( ( ) => {
320
+ before ( ( ) => {
328
321
method = serverless . getMethodResourceForMethodName ( "ApiGatewayMethodCatPawPawidVarDelete" ) ;
329
322
} ) ;
330
323
@@ -349,7 +342,60 @@ describe('Configuring path parameter caching', () => {
349
342
it ( 'should set integration cache key parameters' , ( ) => {
350
343
for ( let parameter of secondEndpointCacheKeyParameters ) {
351
344
expect ( method . Properties . Integration . CacheKeyParameters )
352
- . to . include ( `method.${ parameter . name } ` ) ;
345
+ . to . include ( `method.${ parameter . name } ` ) ;
346
+ }
347
+ } ) ;
348
+
349
+ it ( 'should set a cache namespace' , ( ) => {
350
+ expect ( method . Properties . Integration . CacheNamespace ) . to . exist ;
351
+ } ) ;
352
+ } ) ;
353
+ } ) ;
354
+
355
+ describe ( 'when an http event path contains the \'+\' special character' , ( ) => {
356
+ let cacheKeyParameters , functionWithCachingName ;
357
+ before ( ( ) => {
358
+ functionWithCachingName = 'get-cat-by-paw-id' ;
359
+ cacheKeyParameters = [ { name : 'request.path.pawId' } , { name : 'request.header.Accept-Language' } ] ;
360
+
361
+ let functionWithCaching = given . a_serverless_function ( functionWithCachingName )
362
+ . withHttpEndpoint ( 'get' , '/cat/{pawId+}' , { enabled : true , cacheKeyParameters } ) ;
363
+
364
+ serverless = given . a_serverless_instance ( serviceName )
365
+ . withApiGatewayCachingConfig ( true , '0.5' , 45 )
366
+ . forStage ( stage )
367
+ . withFunction ( functionWithCaching ) ;
368
+
369
+ when_configuring_path_parameters ( serverless )
370
+ } ) ;
371
+
372
+ describe ( 'on the corresponding method' , ( ) => {
373
+ before ( ( ) => {
374
+ method = serverless . getMethodResourceForFunction ( functionWithCachingName ) ;
375
+ } ) ;
376
+
377
+ it ( 'should configure cache key parameters as request parameters' , ( ) => {
378
+ for ( let parameter of cacheKeyParameters ) {
379
+ expect ( method . Properties . RequestParameters )
380
+ . to . deep . include ( {
381
+ [ `method.${ parameter . name } ` ] : { }
382
+ } ) ;
383
+ }
384
+ } ) ;
385
+
386
+ it ( 'should set integration request parameters' , ( ) => {
387
+ for ( let parameter of cacheKeyParameters ) {
388
+ expect ( method . Properties . Integration . RequestParameters )
389
+ . to . deep . include ( {
390
+ [ `integration.${ parameter . name } ` ] : `method.${ parameter . name } `
391
+ } ) ;
392
+ }
393
+ } ) ;
394
+
395
+ it ( 'should set integration cache key parameters' , ( ) => {
396
+ for ( let parameter of cacheKeyParameters ) {
397
+ expect ( method . Properties . Integration . CacheKeyParameters )
398
+ . to . include ( `method.${ parameter . name } ` ) ;
353
399
}
354
400
} ) ;
355
401
@@ -360,6 +406,7 @@ describe('Configuring path parameter caching', () => {
360
406
} ) ;
361
407
} ) ;
362
408
363
- const when_configuring_path_parameters = ( settings , serverless ) => {
364
- return pathParams . addPathParametersCacheConfig ( settings , serverless ) ;
409
+ const when_configuring_path_parameters = ( serverless ) => {
410
+ let cacheSettings = new ApiGatewayCachingSettings ( serverless ) ;
411
+ return pathParams . addPathParametersCacheConfig ( cacheSettings , serverless ) ;
365
412
}
0 commit comments