@@ -416,19 +416,8 @@ describe('lambda2samCoreLogic', function () {
416
416
417
417
describe ( 'deployCfnTemplate' , function ( ) {
418
418
it ( 'deploys a CloudFormation template and returns stack info' , async function ( ) {
419
- // Setup CloudFormation template - using 'as any' to bypass strict typing for tests
420
- const template : cloudFormation . Template = {
421
- AWSTemplateFormatVersion : '2010-09-09' ,
422
- Resources : {
423
- TestFunc : {
424
- Type : cloudFormation . LAMBDA_FUNCTION_TYPE ,
425
- Properties : {
426
- FunctionName : 'test-function' ,
427
- PackageType : 'Zip' ,
428
- } ,
429
- } ,
430
- } ,
431
- } as any
419
+ // Setup CloudFormation template
420
+ const template : cloudFormation . Template = mockCloudFormationTemplate ( )
432
421
433
422
// Setup Lambda node
434
423
const lambdaNode = mockLambdaNode ( )
@@ -472,19 +461,8 @@ describe('lambda2samCoreLogic', function () {
472
461
} )
473
462
474
463
it ( 'throws an error when change set creation fails' , async function ( ) {
475
- // Setup CloudFormation template - using 'as any' to bypass strict typing for tests
476
- const template : cloudFormation . Template = {
477
- AWSTemplateFormatVersion : '2010-09-09' ,
478
- Resources : {
479
- TestFunc : {
480
- Type : cloudFormation . LAMBDA_FUNCTION_TYPE ,
481
- Properties : {
482
- FunctionName : 'test-function' ,
483
- PackageType : 'Zip' ,
484
- } ,
485
- } ,
486
- } ,
487
- } as any
464
+ // Setup CloudFormation template
465
+ const template : cloudFormation . Template = mockCloudFormationTemplate ( )
488
466
489
467
// Setup Lambda node
490
468
const lambdaNode = mockLambdaNode ( )
@@ -523,12 +501,7 @@ describe('lambda2samCoreLogic', function () {
523
501
sandbox . stub ( authUtils , 'getIAMConnection' ) . resolves ( mockConnection )
524
502
525
503
// Mock fetch response
526
- const mockFetch = sandbox . stub ( global , 'fetch' ) . resolves ( {
527
- ok : true ,
528
- json : sandbox . stub ( ) . resolves ( {
529
- cloudFormationTemplateId : 'test-template-id' ,
530
- } ) ,
531
- } as any )
504
+ const mockFetch = mockFetchResponse ( sandbox )
532
505
533
506
// Setup CloudFormation client to return ARN in ResourceIdentifier
534
507
cfnClientStub . describeGeneratedTemplate . resolves ( {
@@ -568,12 +541,7 @@ describe('lambda2samCoreLogic', function () {
568
541
sandbox . stub ( authUtils , 'getIAMConnection' ) . resolves ( mockConnection )
569
542
570
543
// Mock fetch response
571
- sandbox . stub ( global , 'fetch' ) . resolves ( {
572
- ok : true ,
573
- json : sandbox . stub ( ) . resolves ( {
574
- cloudFormationTemplateId : 'test-template-id' ,
575
- } ) ,
576
- } as any )
544
+ mockFetchResponse ( sandbox )
577
545
578
546
// Setup CloudFormation client to return plain function name
579
547
cfnClientStub . describeGeneratedTemplate . resolves ( {
@@ -606,12 +574,7 @@ describe('lambda2samCoreLogic', function () {
606
574
sandbox . stub ( authUtils , 'getIAMConnection' ) . resolves ( mockConnection )
607
575
608
576
// Mock fetch response
609
- sandbox . stub ( global , 'fetch' ) . resolves ( {
610
- ok : true ,
611
- json : sandbox . stub ( ) . resolves ( {
612
- cloudFormationTemplateId : 'test-template-id' ,
613
- } ) ,
614
- } as any )
577
+ mockFetchResponse ( sandbox )
615
578
616
579
// Setup CloudFormation client to return mixed resource types
617
580
cfnClientStub . describeGeneratedTemplate . resolves ( {
@@ -762,4 +725,30 @@ describe('lambda2samCoreLogic', function () {
762
725
endpointUrl : undefined ,
763
726
}
764
727
}
728
+
729
+ function mockCloudFormationTemplate ( ) : cloudFormation . Template {
730
+ return {
731
+ AWSTemplateFormatVersion : '2010-09-09' ,
732
+ Resources : {
733
+ TestFunc : {
734
+ Type : cloudFormation . LAMBDA_FUNCTION_TYPE ,
735
+ Properties : {
736
+ FunctionName : 'test-function' ,
737
+ PackageType : 'Zip' ,
738
+ Handler : 'index.handler' ,
739
+ CodeUri : 's3://test-bucket/test-key' ,
740
+ } ,
741
+ } ,
742
+ } ,
743
+ }
744
+ }
745
+
746
+ function mockFetchResponse ( sandbox : sinon . SinonSandbox ) {
747
+ return sandbox . stub ( global , 'fetch' ) . resolves ( {
748
+ ok : true ,
749
+ json : sandbox . stub ( ) . resolves ( {
750
+ cloudFormationTemplateId : 'test-template-id' ,
751
+ } ) ,
752
+ } as any )
753
+ }
765
754
} )
0 commit comments