@@ -32,6 +32,7 @@ import {
3232 getChangeSetDeletionStatusHandler ,
3333 describeStackHandler ,
3434 describeChangeSetHandler ,
35+ describeEventsHandler ,
3536} from '../../../src/handlers/StackHandler' ;
3637import { analyzeCapabilities } from '../../../src/stacks/actions/CapabilityAnalyzer' ;
3738import { mapChangesToStackChanges } from '../../../src/stacks/actions/StackActionOperations' ;
@@ -51,6 +52,7 @@ import {
5152 DescribeStackResult ,
5253 DescribeChangeSetParams ,
5354 DescribeChangeSetResult ,
55+ DescribeEventsResult ,
5456} from '../../../src/stacks/StackRequestType' ;
5557import {
5658 createMockComponents ,
@@ -82,6 +84,7 @@ vi.mock('../../../src/stacks/actions/StackActionParser', () => ({
8284 parseListStackResourcesParams : vi . fn ( ( input ) => input ) ,
8385 parseDescribeStackParams : vi . fn ( ( input ) => input ) ,
8486 parseDescribeChangeSetParams : vi . fn ( ( input ) => input ) ,
87+ parseDescribeEventsParams : vi . fn ( ( input ) => input ) ,
8588} ) ) ;
8689
8790vi . mock ( '../../../src/utils/ZodErrorWrapper' , ( ) => ( {
@@ -922,4 +925,58 @@ describe('StackActionHandler', () => {
922925 await expect ( handler ( params , { } as any ) ) . rejects . toThrow ( 'ChangeSet not found' ) ;
923926 } ) ;
924927 } ) ;
928+
929+ describe ( 'describeEventsHandler' , ( ) => {
930+ it ( 'should return flat events from API' , async ( ) => {
931+ mockComponents . cfnService . describeEvents . resolves ( {
932+ OperationEvents : [
933+ { EventId : '1' , OperationId : 'op1' , Timestamp : new Date ( '2024-01-01' ) } ,
934+ { EventId : '2' , OperationId : 'op1' , Timestamp : new Date ( '2024-01-02' ) } ,
935+ { EventId : '3' , OperationId : 'op2' , Timestamp : new Date ( '2024-01-03' ) } ,
936+ ] ,
937+ $metadata : { } ,
938+ } ) ;
939+
940+ const handler = describeEventsHandler ( mockComponents ) ;
941+ const result = ( await handler ( { stackName : 'test-stack' } , CancellationToken . None ) ) as DescribeEventsResult ;
942+
943+ expect ( result . events ) . toHaveLength ( 3 ) ;
944+ expect ( result . events [ 0 ] . EventId ) . toBe ( '1' ) ;
945+ } ) ;
946+
947+ it ( 'should pass all parameters to API' , async ( ) => {
948+ mockComponents . cfnService . describeEvents . resolves ( { OperationEvents : [ ] , $metadata : { } } ) ;
949+
950+ const handler = describeEventsHandler ( mockComponents ) ;
951+ await handler (
952+ {
953+ stackName : 'test-stack' ,
954+ changeSetName : 'cs' ,
955+ operationId : 'op' ,
956+ failedEventsOnly : true ,
957+ nextToken : 'token' ,
958+ } ,
959+ CancellationToken . None ,
960+ ) ;
961+
962+ expect (
963+ mockComponents . cfnService . describeEvents . calledWith ( {
964+ StackName : 'test-stack' ,
965+ ChangeSetName : 'cs' ,
966+ OperationId : 'op' ,
967+ FailedEventsOnly : true ,
968+ NextToken : 'token' ,
969+ } ) ,
970+ ) . toBe ( true ) ;
971+ } ) ;
972+
973+ it ( 'should handle service errors' , async ( ) => {
974+ const serviceError = new Error ( 'Service error' ) ;
975+ mockComponents . cfnService . describeEvents . rejects ( serviceError ) ;
976+
977+ const handler = describeEventsHandler ( mockComponents ) ;
978+
979+ await expect ( handler ( { stackName : 'test-stack' } , CancellationToken . None ) ) . rejects . toThrow ( ) ;
980+ } ) ;
981+ } ) ;
925982} ) ;
0 commit comments