@@ -86,6 +86,7 @@ describe('update lambda edge API', () => {
86
86
fakeConfig = {
87
87
awsRegion : undefined ,
88
88
cfDistributionID : 'cloudfront' ,
89
+ cacheBehaviorPath : 'default' ,
89
90
autoIncrementVersion : true ,
90
91
lambdaCodeS3Bucket : 'bucket' ,
91
92
cfTriggers : [
@@ -316,8 +317,9 @@ describe('update lambda edge API', () => {
316
317
} )
317
318
318
319
describe ( 'activateLambdas()' , ( ) => {
320
+ let cloudFrontDistributionConfig
319
321
beforeEach ( ( ) => {
320
- cloudFrontGetDistributionConfigMock . mockResolvedValue ( {
322
+ cloudFrontDistributionConfig = {
321
323
ETag : 'etag' ,
322
324
DistributionConfig : {
323
325
DefaultCacheBehavior : {
@@ -341,9 +343,38 @@ describe('update lambda edge API', () => {
341
343
}
342
344
]
343
345
}
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 )
347
378
348
379
lambdaListVersionsByFunctionMock . mockImplementation ( ( ) => ( {
349
380
Versions : [
@@ -369,7 +400,7 @@ describe('update lambda edge API', () => {
369
400
return expect ( activateLambdas ( fakeConfig ) ) . rejects . toThrow ( 'Invalid config.' )
370
401
} )
371
402
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 ( ) => {
373
404
await activateLambdas ( fakeConfig )
374
405
375
406
expect ( cloudFrontUpdateDistributionMock ) . toHaveBeenCalledTimes ( 1 )
@@ -398,12 +429,101 @@ describe('update lambda edge API', () => {
398
429
}
399
430
]
400
431
}
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
+ ]
401
459
}
402
460
}
403
461
} )
404
462
} )
405
463
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 ( ) => {
407
527
fakeConfig . cfTriggers [ 0 ] . lambdaFunctionVersion = '1'
408
528
fakeConfig . cfTriggers [ 1 ] . lambdaFunctionVersion = '2'
409
529
fakeConfig . cfTriggers [ 2 ] . lambdaFunctionVersion = '3'
@@ -437,11 +557,50 @@ describe('update lambda edge API', () => {
437
557
}
438
558
]
439
559
}
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
+ } ,
441
588
}
442
589
} )
443
590
} )
444
591
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
+
445
604
it ( 'should not update the distribution config if it\'s a dry run' , async ( ) => {
446
605
fakeConfig . dryRun = true
447
606
await activateLambdas ( fakeConfig )
0 commit comments