@@ -169,6 +169,104 @@ describe('Configuring path parameter caching', () => {
169
169
} ) ;
170
170
}
171
171
} ) ;
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
+ } ) ;
172
270
} ) ;
173
271
174
272
const when_configuring_path_parameters = ( settings , serverless ) => {
0 commit comments