11import * as cxapi from '@aws-cdk/cx-api' ;
22import {
33 ContinueUpdateRollbackCommand ,
4+ DeleteChangeSetCommand ,
45 DescribeStackEventsCommand ,
56 DescribeStacksCommand ,
67 ListStackResourcesCommand ,
@@ -10,6 +11,7 @@ import {
1011 DescribeChangeSetCommand ,
1112 ChangeSetStatus ,
1213 CreateChangeSetCommand ,
14+ ChangeAction ,
1315} from '@aws-sdk/client-cloudformation' ;
1416import { GetParameterCommand } from '@aws-sdk/client-ssm' ;
1517import { CloudFormationStack } from '../../../lib/api/cloudformation' ;
@@ -1215,3 +1217,107 @@ function givenStacks(stacks: Record<string, { template: any; stackStatus?: strin
12151217 }
12161218 } ) ;
12171219}
1220+
1221+ describe ( 'describeChangeSet' , ( ) => {
1222+ it ( 'calls CloudFormation describeChangeSet with correct parameters' , async ( ) => {
1223+ // GIVEN
1224+ const changeSetName = 'test-changeset' ;
1225+ const stackName = 'test-stack' ;
1226+ const stack = testStack ( { stackName } ) ;
1227+ const mockChangeSetResponse = {
1228+ ChangeSetId : 'arn:aws:cloudformation:us-east-1:123456789012:changeSet/test-changeset/12345' ,
1229+ ChangeSetName : changeSetName ,
1230+ StackId : 'arn:aws:cloudformation:us-east-1:123456789012:stack/test-stack/12345' ,
1231+ Status : ChangeSetStatus . CREATE_COMPLETE ,
1232+ Changes : [ {
1233+ Type : 'Resource' as const ,
1234+ ResourceChange : {
1235+ Action : ChangeAction . Modify ,
1236+ LogicalResourceId : 'TestResource' ,
1237+ ResourceType : 'AWS::S3::Bucket' ,
1238+ } ,
1239+ } ] ,
1240+ } ;
1241+ mockCloudFormationClient . on ( DescribeChangeSetCommand ) . resolves ( mockChangeSetResponse ) ;
1242+
1243+ // WHEN
1244+ const result = await deployments . describeChangeSet ( stack , changeSetName ) ;
1245+
1246+ // THEN
1247+ expect ( result ) . toEqual ( mockChangeSetResponse ) ;
1248+ expect ( mockCloudFormationClient ) . toHaveReceivedCommandWith ( DescribeChangeSetCommand , {
1249+ StackName : stackName ,
1250+ ChangeSetName : changeSetName ,
1251+ } ) ;
1252+ } ) ;
1253+
1254+ it ( 'handles CloudFormation errors gracefully' , async ( ) => {
1255+ // GIVEN
1256+ const changeSetName = 'non-existent-changeset' ;
1257+ const stackName = 'test-stack' ;
1258+ const stack = testStack ( { stackName } ) ;
1259+ const error = new Error ( 'Change set not found' ) ;
1260+ mockCloudFormationClient . on ( DescribeChangeSetCommand ) . rejects ( error ) ;
1261+
1262+ // WHEN
1263+ const result = deployments . describeChangeSet ( stack , changeSetName ) ;
1264+
1265+ // THEN
1266+ await expect ( result ) . rejects . toThrow ( 'Change set not found' ) ;
1267+ } ) ;
1268+
1269+ it ( 'returns the change set' , async ( ) => {
1270+ // GIVEN
1271+ const changeSetName = 'empty-changeset' ;
1272+ const stackName = 'test-stack' ;
1273+ const stack = testStack ( { stackName } ) ;
1274+ const mockChangeSetResponse = {
1275+ ChangeSetId : 'arn:aws:cloudformation:us-east-1:123456789012:changeSet/empty-changeset/12345' ,
1276+ ChangeSetName : changeSetName ,
1277+ StackId : 'arn:aws:cloudformation:us-east-1:123456789012:stack/test-stack/12345' ,
1278+ Status : ChangeSetStatus . CREATE_COMPLETE ,
1279+ } ;
1280+
1281+ mockCloudFormationClient . on ( DescribeChangeSetCommand ) . resolves ( mockChangeSetResponse ) ;
1282+
1283+ // WHEN
1284+ const result = await deployments . describeChangeSet ( stack , changeSetName ) ;
1285+
1286+ // THEN
1287+ expect ( result ) . toEqual ( mockChangeSetResponse ) ;
1288+ } ) ;
1289+ } ) ;
1290+
1291+ describe ( 'deleteChangeSet' , ( ) => {
1292+ it ( 'calls CloudFormation deleteChangeSet with correct parameters' , async ( ) => {
1293+ // GIVEN
1294+ const changeSetName = 'test-changeset' ;
1295+ const stackName = 'test-stack' ;
1296+ const stack = testStack ( { stackName } ) ;
1297+ mockCloudFormationClient . on ( DeleteChangeSetCommand ) . resolves ( { } ) ;
1298+
1299+ // WHEN
1300+ await deployments . deleteChangeSet ( stack , changeSetName ) ;
1301+
1302+ // THEN
1303+ expect ( mockCloudFormationClient ) . toHaveReceivedCommandWith ( DeleteChangeSetCommand , {
1304+ StackName : stackName ,
1305+ ChangeSetName : changeSetName ,
1306+ } ) ;
1307+ } ) ;
1308+
1309+ it ( 'handles CloudFormation errors gracefully' , async ( ) => {
1310+ // GIVEN
1311+ const changeSetName = 'non-existent-changeset' ;
1312+ const stackName = 'test-stack' ;
1313+ const stack = testStack ( { stackName } ) ;
1314+ const error = new Error ( 'Change set not found' ) ;
1315+ mockCloudFormationClient . on ( DeleteChangeSetCommand ) . rejects ( error ) ;
1316+
1317+ // WHEN
1318+ const result = deployments . deleteChangeSet ( stack , changeSetName ) ;
1319+
1320+ // THEN
1321+ await expect ( result ) . rejects . toThrow ( 'Change set not found' ) ;
1322+ } ) ;
1323+ } ) ;
0 commit comments