@@ -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
128174const when_configuring_path_parameters = ( settings , serverless ) => {
0 commit comments