Skip to content

Commit f444170

Browse files
committed
update callback file
1 parent 1af0aa0 commit f444170

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

src/callback.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { v4 as uuidv4 } from 'uuid';
2+
import CloudFormation from 'aws-sdk/clients/cloudformation';
23

34
import {
45
SessionProxy,
56
} from './proxy';
67
import { BaseResourceModel, OperationStatus, Response } from './interface';
7-
import { KitchenSinkEncoder } from './utils';
88

99

1010
const LOG = console;
@@ -25,24 +25,27 @@ export async function reportProgress(options: ProgressOptions): Promise<void> {
2525
resourceModel,
2626
message,
2727
} = options;
28-
const client = session.client('CloudFormation');
28+
const client: CloudFormation = session.client('CloudFormation') as CloudFormation;
2929

30-
const request: { [key: string]: any; } = {
30+
const request: CloudFormation.RecordHandlerProgressInput = {
3131
BearerToken: bearerToken,
3232
OperationStatus: operationStatus,
3333
StatusMessage: message,
3434
ClientRequestToken: uuidv4(),
35-
};
35+
} as CloudFormation.RecordHandlerProgressInput;
3636
if (resourceModel) {
3737
request.ResourceModel = JSON.stringify(resourceModel);
3838
}
3939
if (errorCode) {
4040
request.ErrorCode = errorCode;
4141
}
4242
if (currentOperationStatus) {
43-
request['CurrentOperationStatus'] = currentOperationStatus;
44-
const response: { [key: string]: any; } = await client.makeRequest('recordHandlerProgress', request).promise()
45-
const requestId = response['ResponseMetadata']['RequestId'];
43+
request.CurrentOperationStatus = currentOperationStatus;
44+
const response: { [key: string]: any; } = await client.recordHandlerProgress(request).promise();
45+
let requestId: string = '';
46+
if (response['ResponseMetadata']) {
47+
requestId = response.ResponseMetadata.RequestId;
48+
}
4649
LOG.info(`Record Handler Progress with Request Id ${requestId} and Request: ${request}`);
4750
}
4851
}

src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export * from './callback';
2+
export * as exceptions from './exceptions';
3+
export * from './interface';
4+
export * from './log-delivery';
5+
export * from './metrics';
6+
export * from './proxy';
7+
export * from './resource';
8+
export * from './scheduler';
9+
export * from './utils';

tests/lib/callback.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,25 @@ describe('when getting callback', () => {
3030

3131
beforeEach(() => {
3232
recordHandlerProgress = mockResult({
33-
ResponseMetadata: {RequestId: 'mock_request'}
33+
ResponseMetadata: {RequestId: 'mock-request'}
3434
});
3535
const cfn = (CloudFormation as unknown) as jest.Mock;
3636
cfn.mockImplementation(() => {
37+
const returnValue = {
38+
recordHandlerProgress
39+
};
3740
return {
41+
...returnValue,
3842
makeRequest: (operation: string, params?: {[key: string]: any}) => {
39-
const returnValue = {
40-
recordHandlerProgress
41-
};
4243
return returnValue[operation](params);
4344
}
4445
};
4546
});
4647
session = new SessionProxy({});
47-
4848
});
4949

5050
afterEach(() => {
51+
jest.clearAllMocks();
5152
jest.restoreAllMocks();
5253
});
5354

0 commit comments

Comments
 (0)