@@ -416,19 +416,8 @@ describe('lambda2samCoreLogic', function () {
416416
417417 describe ( 'deployCfnTemplate' , function ( ) {
418418 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 ( )
432421
433422 // Setup Lambda node
434423 const lambdaNode = mockLambdaNode ( )
@@ -472,19 +461,8 @@ describe('lambda2samCoreLogic', function () {
472461 } )
473462
474463 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 ( )
488466
489467 // Setup Lambda node
490468 const lambdaNode = mockLambdaNode ( )
@@ -523,12 +501,7 @@ describe('lambda2samCoreLogic', function () {
523501 sandbox . stub ( authUtils , 'getIAMConnection' ) . resolves ( mockConnection )
524502
525503 // 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 )
532505
533506 // Setup CloudFormation client to return ARN in ResourceIdentifier
534507 cfnClientStub . describeGeneratedTemplate . resolves ( {
@@ -568,12 +541,7 @@ describe('lambda2samCoreLogic', function () {
568541 sandbox . stub ( authUtils , 'getIAMConnection' ) . resolves ( mockConnection )
569542
570543 // 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 )
577545
578546 // Setup CloudFormation client to return plain function name
579547 cfnClientStub . describeGeneratedTemplate . resolves ( {
@@ -606,12 +574,7 @@ describe('lambda2samCoreLogic', function () {
606574 sandbox . stub ( authUtils , 'getIAMConnection' ) . resolves ( mockConnection )
607575
608576 // 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 )
615578
616579 // Setup CloudFormation client to return mixed resource types
617580 cfnClientStub . describeGeneratedTemplate . resolves ( {
@@ -762,4 +725,30 @@ describe('lambda2samCoreLogic', function () {
762725 endpointUrl : undefined ,
763726 }
764727 }
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+ }
765754} )
0 commit comments