@@ -9,10 +9,32 @@ import { WorkflowStudioApiHandler } from '../../../stepFunctions/workflowStudio/
99import { MockDocument } from '../../fake/fakeDocument'
1010import { ApiAction , Command , MessageType , WebviewContext } from '../../../stepFunctions/workflowStudio/types'
1111import * as vscode from 'vscode'
12+ import { assertTelemetry } from '../../testUtil'
13+ import { DefaultStepFunctionsClient } from '../../../shared/clients/stepFunctionsClient'
14+ import { DefaultIamClient } from '../../../shared/clients/iamClient'
1215
1316describe ( 'WorkflowStudioApiHandler' , function ( ) {
1417 let postMessageStub : sinon . SinonStub
1518 let apiHandler : WorkflowStudioApiHandler
19+ let testState : sinon . SinonStub
20+
21+ async function assertTestApiResponse ( expectedResponse : any ) {
22+ await apiHandler . performApiCall ( {
23+ apiName : ApiAction . SFNTestState ,
24+ params : {
25+ definition : '' ,
26+ roleArn : '' ,
27+ } ,
28+ requestId : 'test-request-id' ,
29+ command : Command . API_CALL ,
30+ messageType : MessageType . REQUEST ,
31+ } )
32+
33+ assertTelemetry ( 'ui_click' , {
34+ elementId : 'stepfunctions_testState' ,
35+ } )
36+ assert ( postMessageStub . firstCall . calledWithExactly ( expectedResponse ) )
37+ }
1638
1739 beforeEach ( ( ) => {
1840 const panel = vscode . window . createWebviewPanel ( 'WorkflowStudioMock' , 'WorkflowStudioMockTitle' , {
@@ -34,68 +56,46 @@ describe('WorkflowStudioApiHandler', function () {
3456 fileId : '' ,
3557 }
3658
37- apiHandler = new WorkflowStudioApiHandler ( 'us-east-1' , context )
59+ const sfnClient = new DefaultStepFunctionsClient ( 'us-east-1' )
60+ apiHandler = new WorkflowStudioApiHandler ( 'us-east-1' , context , {
61+ sfn : sfnClient ,
62+ iam : new DefaultIamClient ( 'us-east-1' ) ,
63+ } )
64+
65+ testState = sinon . stub ( sfnClient , 'testState' )
3866 } )
3967
4068 it ( 'should handle request and response for success' , async function ( ) {
41- sinon . stub ( apiHandler , 'testState' ) . returns (
42- Promise . resolve ( {
43- output : 'Test state output' ,
44- } )
45- )
69+ testState . resolves ( {
70+ output : 'Test state output' ,
71+ } )
4672
47- await apiHandler . performApiCall ( {
73+ await assertTestApiResponse ( {
74+ messageType : MessageType . RESPONSE ,
75+ command : Command . API_CALL ,
4876 apiName : ApiAction . SFNTestState ,
49- params : {
50- definition : '' ,
51- roleArn : '' ,
77+ response : {
78+ output : 'Test state output' ,
5279 } ,
5380 requestId : 'test-request-id' ,
54- command : Command . API_CALL ,
55- messageType : MessageType . REQUEST ,
81+ isSuccess : true ,
5682 } )
57-
58- assert (
59- postMessageStub . firstCall . calledWithExactly ( {
60- messageType : MessageType . RESPONSE ,
61- command : Command . API_CALL ,
62- apiName : ApiAction . SFNTestState ,
63- response : {
64- output : 'Test state output' ,
65- } ,
66- requestId : 'test-request-id' ,
67- isSuccess : true ,
68- } )
69- )
7083 } )
7184
7285 it ( 'should handle request and response for error' , async function ( ) {
73- sinon . stub ( apiHandler , ' testState' ) . returns ( Promise . reject ( new Error ( 'Error testing state' ) ) )
86+ testState . rejects ( new Error ( 'Error testing state' ) )
7487
75- await apiHandler . performApiCall ( {
88+ await assertTestApiResponse ( {
89+ messageType : MessageType . RESPONSE ,
90+ command : Command . API_CALL ,
7691 apiName : ApiAction . SFNTestState ,
77- params : {
78- definition : '' ,
79- roleArn : '' ,
92+ error : {
93+ message : 'Error testing state' ,
94+ name : 'Error' ,
95+ stack : sinon . match . string ,
8096 } ,
97+ isSuccess : false ,
8198 requestId : 'test-request-id' ,
82- command : Command . API_CALL ,
83- messageType : MessageType . REQUEST ,
8499 } )
85-
86- assert (
87- postMessageStub . firstCall . calledWithExactly ( {
88- messageType : MessageType . RESPONSE ,
89- command : Command . API_CALL ,
90- apiName : ApiAction . SFNTestState ,
91- error : {
92- message : 'Error testing state' ,
93- name : 'Error' ,
94- stack : sinon . match . string ,
95- } ,
96- isSuccess : false ,
97- requestId : 'test-request-id' ,
98- } )
99- )
100100 } )
101101} )
0 commit comments