1- import { Change , ChangeSetType , StackStatus } from '@aws-sdk/client-cloudformation' ;
1+ import { Change , ChangeSetType , StackStatus , OnStackFailure } from '@aws-sdk/client-cloudformation' ;
22import { WaiterState } from '@smithy/util-waiter' ;
33import { DateTime } from 'luxon' ;
44import { stubInterface } from 'ts-sinon' ;
@@ -18,12 +18,14 @@ import {
1818 parseValidationEvents ,
1919 publishValidationDiagnostics ,
2020 isStackInReview ,
21+ computeEligibleDeploymentMode ,
2122} from '../../../src/stacks/actions/StackActionOperations' ;
2223import {
2324 CreateValidationParams ,
2425 StackActionPhase ,
2526 StackActionState ,
2627 ValidationDetail ,
28+ DeploymentMode ,
2729} from '../../../src/stacks/actions/StackActionRequestType' ;
2830import { StackActionWorkflowState } from '../../../src/stacks/actions/StackActionWorkflowType' ;
2931import { ExtensionName } from '../../../src/utils/ExtensionConfig' ;
@@ -578,4 +580,63 @@ describe('StackActionWorkflowOperations', () => {
578580 expect ( result ) . toBe ( true ) ;
579581 } ) ;
580582 } ) ;
583+
584+ describe ( 'computeEligibleDeploymentMode' , ( ) => {
585+ it ( 'should return undefined when deploymentMode is not provided' , ( ) => {
586+ const result = computeEligibleDeploymentMode ( ChangeSetType . UPDATE , undefined ) ;
587+ expect ( result ) . toBeUndefined ( ) ;
588+ } ) ;
589+
590+ it ( 'should return deploymentMode when all conditions are met for REVERT_DRIFT' , ( ) => {
591+ const result = computeEligibleDeploymentMode (
592+ ChangeSetType . UPDATE ,
593+ DeploymentMode . REVERT_DRIFT ,
594+ false ,
595+ undefined ,
596+ false ,
597+ OnStackFailure . ROLLBACK ,
598+ ) ;
599+ expect ( result ) . toBe ( DeploymentMode . REVERT_DRIFT ) ;
600+ } ) ;
601+
602+ it ( 'should return undefined when changeSetType is CREATE' , ( ) => {
603+ const result = computeEligibleDeploymentMode ( ChangeSetType . CREATE , DeploymentMode . REVERT_DRIFT ) ;
604+ expect ( result ) . toBeUndefined ( ) ;
605+ } ) ;
606+
607+ it ( 'should return undefined when importExistingResources is true' , ( ) => {
608+ const result = computeEligibleDeploymentMode ( ChangeSetType . UPDATE , DeploymentMode . REVERT_DRIFT , true ) ;
609+ expect ( result ) . toBeUndefined ( ) ;
610+ } ) ;
611+
612+ it ( 'should return undefined when resourcesToImport has items' , ( ) => {
613+ const result = computeEligibleDeploymentMode ( ChangeSetType . UPDATE , DeploymentMode . REVERT_DRIFT , false , [
614+ { LogicalResourceId : 'test' , ResourceType : 'AWS::S3::Bucket' , ResourceIdentifier : { } } ,
615+ ] ) ;
616+ expect ( result ) . toBeUndefined ( ) ;
617+ } ) ;
618+
619+ it ( 'should return undefined when includeNestedStacks is true' , ( ) => {
620+ const result = computeEligibleDeploymentMode (
621+ ChangeSetType . UPDATE ,
622+ DeploymentMode . REVERT_DRIFT ,
623+ false ,
624+ undefined ,
625+ true ,
626+ ) ;
627+ expect ( result ) . toBeUndefined ( ) ;
628+ } ) ;
629+
630+ it ( 'should return undefined when onStackFailure is DO_NOTHING' , ( ) => {
631+ const result = computeEligibleDeploymentMode (
632+ ChangeSetType . UPDATE ,
633+ DeploymentMode . REVERT_DRIFT ,
634+ false ,
635+ undefined ,
636+ false ,
637+ OnStackFailure . DO_NOTHING ,
638+ ) ;
639+ expect ( result ) . toBeUndefined ( ) ;
640+ } ) ;
641+ } ) ;
581642} ) ;
0 commit comments