@@ -431,10 +431,7 @@ describe('lambda2samCoreLogic', function () {
431
431
} as any
432
432
433
433
// Setup Lambda node
434
- const lambdaNode = {
435
- name : 'test-function' ,
436
- regionCode : 'us-west-2' ,
437
- } as LambdaFunctionNode
434
+ const lambdaNode = mockLambdaNode ( )
438
435
439
436
const resourceToImport : ResourcesToImport = [
440
437
{
@@ -490,10 +487,7 @@ describe('lambda2samCoreLogic', function () {
490
487
} as any
491
488
492
489
// Setup Lambda node
493
- const lambdaNode = {
494
- name : 'test-function' ,
495
- regionCode : 'us-west-2' ,
496
- } as LambdaFunctionNode
490
+ const lambdaNode = mockLambdaNode ( )
497
491
498
492
// Make createChangeSet fail
499
493
cfnClientStub . createChangeSet . resolves ( { } ) // No Id
@@ -522,24 +516,10 @@ describe('lambda2samCoreLogic', function () {
522
516
describe ( 'callExternalApiForCfnTemplate' , function ( ) {
523
517
it ( 'extracts function name from ARN in ResourceIdentifier' , async function ( ) {
524
518
// Setup Lambda node
525
- const lambdaNode = {
526
- name : 'test-function' ,
527
- regionCode : 'us-east-2' ,
528
- arn : 'arn:aws:lambda:us-east-2:123456789012:function:test-function' ,
529
- } as LambdaFunctionNode
519
+ const lambdaNode = mockLambdaNode ( true )
530
520
531
521
// Mock IAM connection
532
- const mockConnection = {
533
- type : 'iam' as const ,
534
- id : 'test-connection' ,
535
- label : 'Test Connection' ,
536
- state : 'valid' as const ,
537
- getCredentials : sandbox . stub ( ) . resolves ( {
538
- accessKeyId : 'test-key' ,
539
- secretAccessKey : 'test-secret' ,
540
- } ) ,
541
- endpointUrl : undefined ,
542
- }
522
+ const mockConnection = mockIamConnection ( )
543
523
sandbox . stub ( authUtils , 'getIAMConnection' ) . resolves ( mockConnection )
544
524
545
525
// Mock fetch response
@@ -581,24 +561,10 @@ describe('lambda2samCoreLogic', function () {
581
561
582
562
it ( 'preserves function name when not an ARN' , async function ( ) {
583
563
// Setup Lambda node
584
- const lambdaNode = {
585
- name : 'test-function' ,
586
- regionCode : 'us-east-2' ,
587
- arn : 'arn:aws:lambda:us-east-2:123456789012:function:test-function' ,
588
- } as LambdaFunctionNode
564
+ const lambdaNode = mockLambdaNode ( true )
589
565
590
566
// Mock IAM connection
591
- const mockConnection = {
592
- type : 'iam' as const ,
593
- id : 'test-connection' ,
594
- label : 'Test Connection' ,
595
- state : 'valid' as const ,
596
- getCredentials : sandbox . stub ( ) . resolves ( {
597
- accessKeyId : 'test-key' ,
598
- secretAccessKey : 'test-secret' ,
599
- } ) ,
600
- endpointUrl : undefined ,
601
- }
567
+ const mockConnection = mockIamConnection ( )
602
568
sandbox . stub ( authUtils , 'getIAMConnection' ) . resolves ( mockConnection )
603
569
604
570
// Mock fetch response
@@ -633,24 +599,10 @@ describe('lambda2samCoreLogic', function () {
633
599
634
600
it ( 'handles non-Lambda resources without modification' , async function ( ) {
635
601
// Setup Lambda node
636
- const lambdaNode = {
637
- name : 'test-function' ,
638
- regionCode : 'us-east-2' ,
639
- arn : 'arn:aws:lambda:us-east-2:123456789012:function:test-function' ,
640
- } as LambdaFunctionNode
602
+ const lambdaNode = mockLambdaNode ( true )
641
603
642
604
// Mock IAM connection
643
- const mockConnection = {
644
- type : 'iam' as const ,
645
- id : 'test-connection' ,
646
- label : 'Test Connection' ,
647
- state : 'valid' as const ,
648
- getCredentials : sandbox . stub ( ) . resolves ( {
649
- accessKeyId : 'test-key' ,
650
- secretAccessKey : 'test-secret' ,
651
- } ) ,
652
- endpointUrl : undefined ,
653
- }
605
+ const mockConnection = mockIamConnection ( )
654
606
sandbox . stub ( authUtils , 'getIAMConnection' ) . resolves ( mockConnection )
655
607
656
608
// Mock fetch response
@@ -699,10 +651,7 @@ describe('lambda2samCoreLogic', function () {
699
651
describe ( 'lambdaToSam' , function ( ) {
700
652
it ( 'converts a Lambda function to a SAM project' , async function ( ) {
701
653
// Setup Lambda node
702
- const lambdaNode = {
703
- name : 'test-function' ,
704
- regionCode : 'us-west-2' ,
705
- } as LambdaFunctionNode
654
+ const lambdaNode = mockLambdaNode ( )
706
655
707
656
// Setup AWS Lambda client responses
708
657
lambdaClientStub . getFunction . resolves ( {
@@ -784,4 +733,33 @@ describe('lambda2samCoreLogic', function () {
784
733
)
785
734
} )
786
735
} )
736
+
737
+ function mockLambdaNode ( withArn : boolean = false ) {
738
+ if ( withArn ) {
739
+ return {
740
+ name : 'test-function' ,
741
+ regionCode : 'us-east-2' ,
742
+ arn : 'arn:aws:lambda:us-east-2:123456789012:function:test-function' ,
743
+ } as LambdaFunctionNode
744
+ } else {
745
+ return {
746
+ name : 'test-function' ,
747
+ regionCode : 'us-east-2' ,
748
+ } as LambdaFunctionNode
749
+ }
750
+ }
751
+
752
+ function mockIamConnection ( ) {
753
+ return {
754
+ type : 'iam' as const ,
755
+ id : 'test-connection' ,
756
+ label : 'Test Connection' ,
757
+ state : 'valid' as const ,
758
+ getCredentials : sandbox . stub ( ) . resolves ( {
759
+ accessKeyId : 'test-key' ,
760
+ secretAccessKey : 'test-secret' ,
761
+ } ) ,
762
+ endpointUrl : undefined ,
763
+ }
764
+ }
787
765
} )
0 commit comments