@@ -858,6 +858,48 @@ describe("stack deletion", () => {
858858 } )
859859 } )
860860
861+ test ( "deletes PR stacks with multiple suffixes" , async ( ) => {
862+ const now = new Date ( )
863+ const twoDaysAgo = new Date ( now . getTime ( ) - 2 * 24 * 60 * 60 * 1000 )
864+
865+ mockListStacksSend . mockReturnValue ( {
866+ StackSummaries : [
867+ {
868+ StackName : `${ baseStackName } -pr-123-sandbox` ,
869+ StackStatus : "CREATE_COMPLETE" ,
870+ CreationTime : twoDaysAgo
871+ } ,
872+ {
873+ StackName : `${ baseStackName } -pr-123-front-door` ,
874+ StackStatus : "CREATE_COMPLETE" ,
875+ CreationTime : twoDaysAgo
876+ } ,
877+ {
878+ StackName : `${ baseStackName } -pr-123-stateful` ,
879+ StackStatus : "CREATE_COMPLETE" ,
880+ CreationTime : twoDaysAgo
881+ }
882+ ]
883+ } )
884+
885+ mockGetPRState . mockImplementation ( ( url : string ) => {
886+ if ( url . endsWith ( "/repos/NHSDigital/eps-cdk-utils/pulls/123" ) ) {
887+ return "closed"
888+ }
889+ throw new Error ( `Unexpected URL: ${ url } ` )
890+ } )
891+
892+ const promise = deleteUnusedPrStacks ( baseStackName , repoName , hostedZoneName )
893+ await vi . runAllTimersAsync ( )
894+ await promise
895+
896+ // One delete stack call for the PR stack
897+ expect ( mockDeleteStackSend ) . toHaveBeenCalledTimes ( 3 )
898+ expect ( mockDeleteStackSend ) . toHaveBeenCalledWith ( { StackName : `${ baseStackName } -pr-123-sandbox` } )
899+ expect ( mockDeleteStackSend ) . toHaveBeenCalledWith ( { StackName : `${ baseStackName } -pr-123-front-door` } )
900+ expect ( mockDeleteStackSend ) . toHaveBeenCalledWith ( { StackName : `${ baseStackName } -pr-123-stateful` } )
901+ } )
902+
861903 test ( "does not delete open PR stacks" , async ( ) => {
862904 const now = new Date ( )
863905 const twoDaysAgo = new Date ( now . getTime ( ) - 2 * 24 * 60 * 60 * 1000 )
0 commit comments