@@ -86,6 +86,7 @@ describe('update lambda edge API', () => {
8686 fakeConfig = {
8787 awsRegion : undefined ,
8888 cfDistributionID : 'cloudfront' ,
89+ cacheBehaviorPath : 'default' ,
8990 autoIncrementVersion : true ,
9091 lambdaCodeS3Bucket : 'bucket' ,
9192 cfTriggers : [
@@ -316,8 +317,9 @@ describe('update lambda edge API', () => {
316317 } )
317318
318319 describe ( 'activateLambdas()' , ( ) => {
320+ let cloudFrontDistributionConfig
319321 beforeEach ( ( ) => {
320- cloudFrontGetDistributionConfigMock . mockResolvedValue ( {
322+ cloudFrontDistributionConfig = {
321323 ETag : 'etag' ,
322324 DistributionConfig : {
323325 DefaultCacheBehavior : {
@@ -341,9 +343,38 @@ describe('update lambda edge API', () => {
341343 }
342344 ]
343345 }
344- }
345- }
346- } )
346+ } ,
347+ CacheBehaviors : {
348+ Items : [
349+ {
350+ PathPattern : '/*' ,
351+ LambdaFunctionAssociations : {
352+ Items : [
353+ {
354+ EventType : 'viewer-request' ,
355+ LambdaFunctionARN : 'old-arn'
356+ } ,
357+ {
358+ EventType : 'origin-request' ,
359+ LambdaFunctionARN : 'old-arn'
360+ } ,
361+ {
362+ EventType : 'origin-response' ,
363+ LambdaFunctionARN : 'old-arn'
364+ } ,
365+ {
366+ EventType : 'viewer-response' ,
367+ LambdaFunctionARN : 'old-arn'
368+ }
369+ ]
370+ }
371+ }
372+ ]
373+ } ,
374+ } ,
375+ }
376+
377+ cloudFrontGetDistributionConfigMock . mockResolvedValue ( cloudFrontDistributionConfig )
347378
348379 lambdaListVersionsByFunctionMock . mockImplementation ( ( ) => ( {
349380 Versions : [
@@ -369,7 +400,7 @@ describe('update lambda edge API', () => {
369400 return expect ( activateLambdas ( fakeConfig ) ) . rejects . toThrow ( 'Invalid config.' )
370401 } )
371402
372- it ( 'should update the distribution config with the latest ARNs' , async ( ) => {
403+ it ( 'should update the default cache behavior with the latest ARNs' , async ( ) => {
373404 await activateLambdas ( fakeConfig )
374405
375406 expect ( cloudFrontUpdateDistributionMock ) . toHaveBeenCalledTimes ( 1 )
@@ -398,12 +429,101 @@ describe('update lambda edge API', () => {
398429 }
399430 ]
400431 }
432+ } ,
433+ CacheBehaviors : {
434+ Items : [
435+ {
436+ PathPattern : '/*' ,
437+ LambdaFunctionAssociations : {
438+ Items : [
439+ {
440+ EventType : 'viewer-request' ,
441+ LambdaFunctionARN : 'old-arn'
442+ } ,
443+ {
444+ EventType : 'origin-request' ,
445+ LambdaFunctionARN : 'old-arn'
446+ } ,
447+ {
448+ EventType : 'origin-response' ,
449+ LambdaFunctionARN : 'old-arn'
450+ } ,
451+ {
452+ EventType : 'viewer-response' ,
453+ LambdaFunctionARN : 'old-arn'
454+ }
455+ ]
456+ }
457+ }
458+ ]
401459 }
402460 }
403461 } )
404462 } )
405463
406- it ( 'should update the distribution config with specific version ARNs' , async ( ) => {
464+ it ( 'should update the specified cache behavior with the latest ARNs' , async ( ) => {
465+ fakeConfig . cacheBehaviorPath = '/*'
466+ await activateLambdas ( fakeConfig )
467+
468+ expect ( cloudFrontUpdateDistributionMock ) . toHaveBeenCalledTimes ( 1 )
469+ expect ( cloudFrontUpdateDistributionMock ) . toHaveBeenCalledWith ( {
470+ Id : 'cloudfront' ,
471+ IfMatch : 'etag' ,
472+ DistributionConfig : {
473+ DefaultCacheBehavior : {
474+ LambdaFunctionAssociations : {
475+ Items : [
476+ {
477+ EventType : 'viewer-request' ,
478+ LambdaFunctionARN : 'old-arn'
479+ } ,
480+ {
481+ EventType : 'origin-request' ,
482+ LambdaFunctionARN : 'old-arn'
483+ } ,
484+ {
485+ EventType : 'origin-response' ,
486+ LambdaFunctionARN : 'old-arn'
487+ } ,
488+ {
489+ EventType : 'viewer-response' ,
490+ LambdaFunctionARN : 'old-arn'
491+ }
492+ ]
493+ }
494+ } ,
495+ CacheBehaviors : {
496+ Items : [
497+ {
498+ PathPattern : '/*' ,
499+ LambdaFunctionAssociations : {
500+ Items : [
501+ {
502+ EventType : 'viewer-request' ,
503+ LambdaFunctionARN : 'arn-v3'
504+ } ,
505+ {
506+ EventType : 'origin-request' ,
507+ LambdaFunctionARN : 'arn-v3'
508+ } ,
509+ {
510+ EventType : 'origin-response' ,
511+ LambdaFunctionARN : 'arn-v3'
512+ } ,
513+ {
514+ EventType : 'viewer-response' ,
515+ LambdaFunctionARN : 'arn-v3'
516+ }
517+ ]
518+ }
519+ }
520+ ]
521+ }
522+ }
523+ } )
524+ } )
525+
526+ it ( 'should update the default cache behavior with specific version ARNs' , async ( ) => {
407527 fakeConfig . cfTriggers [ 0 ] . lambdaFunctionVersion = '1'
408528 fakeConfig . cfTriggers [ 1 ] . lambdaFunctionVersion = '2'
409529 fakeConfig . cfTriggers [ 2 ] . lambdaFunctionVersion = '3'
@@ -437,11 +557,50 @@ describe('update lambda edge API', () => {
437557 }
438558 ]
439559 }
440- }
560+ } ,
561+ CacheBehaviors : {
562+ Items : [
563+ {
564+ PathPattern : '/*' ,
565+ LambdaFunctionAssociations : {
566+ Items : [
567+ {
568+ EventType : 'viewer-request' ,
569+ LambdaFunctionARN : 'old-arn'
570+ } ,
571+ {
572+ EventType : 'origin-request' ,
573+ LambdaFunctionARN : 'old-arn'
574+ } ,
575+ {
576+ EventType : 'origin-response' ,
577+ LambdaFunctionARN : 'old-arn'
578+ } ,
579+ {
580+ EventType : 'viewer-response' ,
581+ LambdaFunctionARN : 'old-arn'
582+ }
583+ ]
584+ }
585+ }
586+ ]
587+ } ,
441588 }
442589 } )
443590 } )
444591
592+ it ( 'should not update anything if invalid cache behavior path is supplied' , async ( ) => {
593+ fakeConfig . cacheBehaviorPath = '/invalid/path/pattern/*'
594+ await activateLambdas ( fakeConfig )
595+
596+ expect ( cloudFrontUpdateDistributionMock ) . toHaveBeenCalledTimes ( 1 )
597+ expect ( cloudFrontUpdateDistributionMock ) . toHaveBeenCalledWith ( {
598+ Id : 'cloudfront' ,
599+ IfMatch : 'etag' ,
600+ DistributionConfig : cloudFrontDistributionConfig . DistributionConfig
601+ } )
602+ } )
603+
445604 it ( 'should not update the distribution config if it\'s a dry run' , async ( ) => {
446605 fakeConfig . dryRun = true
447606 await activateLambdas ( fakeConfig )
0 commit comments