Skip to content

Commit a68634c

Browse files
committed
refactor(stepfunctions): use real code paths in test, address lint issues, adjust logger message
1 parent 7d9c7d7 commit a68634c

File tree

5 files changed

+60
-55
lines changed

5 files changed

+60
-55
lines changed

packages/core/src/shared/logger/logger.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55

66
import * as vscode from 'vscode'
77

8-
export type LogTopic = 'crashMonitoring' | 'dev/beta' | 'notifications' | 'test' | 'childProcess' | 'unknown'
8+
export type LogTopic =
9+
| 'crashMonitoring'
10+
| 'dev/beta'
11+
| 'notifications'
12+
| 'test'
13+
| 'childProcess'
14+
| 'unknown'
15+
| 'stepfunctions'
916

1017
class ErrorLog {
1118
constructor(

packages/core/src/stepFunctions/workflowStudio/handleMessage.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ async function autoSyncFileMessageHandler(request: SyncFileRequestMessage, conte
200200
* @param context The webview context used for returning the API response to the webview
201201
*/
202202
function apiCallMessageHandler(request: ApiCallRequestMessage, context: WebviewContext) {
203-
const logger = getLogger()
203+
const logger = getLogger('stepfunctions')
204204
const apiHandler = new WorkflowStudioApiHandler(globals.awsContext.getCredentialDefaultRegion(), context)
205-
apiHandler
206-
.performApiCall(request)
207-
.catch((error) => logger.error('StepFunctions %s API call failed: %O', request.apiName, error))
205+
apiHandler.performApiCall(request).catch((error) => logger.error('%s API call failed: %O', request.apiName, error))
208206
}

packages/core/src/stepFunctions/workflowStudio/workflowStudioApiHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IAM, StepFunctions } from 'aws-sdk'
77
import { DefaultIamClient } from '../../shared/clients/iamClient'
88
import { DefaultStepFunctionsClient } from '../../shared/clients/stepFunctionsClient'
99
import { ApiAction, ApiCallRequestMessage, Command, MessageType, WebviewContext } from './types'
10-
import { telemetry } from '../../shared/telemetry'
10+
import { telemetry } from '../../shared/telemetry/telemetry'
1111

1212
export class WorkflowStudioApiHandler {
1313
public constructor(

packages/core/src/stepFunctions/workflowStudio/workflowStudioEditor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ export class WorkflowStudioEditor {
182182
this.isPanelDisposed = true
183183
resolve()
184184
this.onVisualizationDisposeEmitter.fire()
185-
this.disposables.forEach((disposable) => {
185+
for (const disposable of this.disposables) {
186186
disposable.dispose()
187-
})
187+
}
188188
this.onVisualizationDisposeEmitter.dispose()
189189
})
190190
)

packages/core/src/test/stepFunctions/workflowStudio/workflowStudioApiHandler.test.ts

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,32 @@ import { WorkflowStudioApiHandler } from '../../../stepFunctions/workflowStudio/
99
import { MockDocument } from '../../fake/fakeDocument'
1010
import { ApiAction, Command, MessageType, WebviewContext } from '../../../stepFunctions/workflowStudio/types'
1111
import * as vscode from 'vscode'
12+
import { assertTelemetry } from '../../testUtil'
13+
import { DefaultStepFunctionsClient } from '../../../shared/clients/stepFunctionsClient'
14+
import { DefaultIamClient } from '../../../shared/clients/iamClient'
1215

1316
describe('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

Comments
 (0)