Skip to content

Commit

Permalink
add support and test coverage for interactiveMessageResponse content …
Browse files Browse the repository at this point in the history
…type (#113)
  • Loading branch information
Spencer Lepine authored Feb 23, 2023
1 parent 4cb7c38 commit d85c517
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.3.4]
### Added
- Throttle typing event. Throttle wait time is set to 10 seconds.
- add interactiveMessageResponse as a supported ContentType.

## [1.3.3]
### Changed
- fix unsafe-eval usage in code by updating webpack config.
Expand Down
2 changes: 1 addition & 1 deletion dist/amazon-connect-chat.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/amazon-connect-chat.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "amazon-connect-chatjs",
"version": "1.3.3",
"version": "1.3.4",
"main": "dist/amazon-connect-chat.js",
"types": "src/index.d.ts",
"engines": {
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const CONTENT_TYPE = {
transferFailed: "application/vnd.amazonaws.connect.event.transfer.failed",
chatEnded: "application/vnd.amazonaws.connect.event.chat.ended",
interactiveMessage: "application/vnd.amazonaws.connect.message.interactive",
interactiveMessageResponse: "application/vnd.amazonaws.connect.message.interactive.response",
readReceipt: "application/vnd.amazonaws.connect.event.message.read",
deliveredReceipt: "application/vnd.amazonaws.connect.event.message.delivered",
participantIdle: "application/vnd.amazonaws.connect.event.participant.idle",
Expand Down
36 changes: 22 additions & 14 deletions src/core/chatController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,28 @@ describe("ChatController", () => {
expect(flag).toEqual(true);
});

test("sendMessage works as expected", async () => {
const args = {
metadata: "metadata",
message: "message",
contentType: CONTENT_TYPE.textPlain
};
const chatController = getChatController();
await chatController.connect();
const response = await chatController.sendMessage(args);
expect(chatClient.sendMessage).toHaveBeenCalledWith("token", "message", CONTENT_TYPE.textPlain);
expect(csmService.addCountAndErrorMetric).toHaveBeenCalledWith(ACPS_METHODS.SEND_MESSAGE, CSM_CATEGORY.API, false, [{name: "ContentType", value: CONTENT_TYPE.textPlain}]);
expect(csmService.addLatencyMetricWithStartTime).toHaveBeenCalledWith(ACPS_METHODS.SEND_MESSAGE, expect.anything(), CSM_CATEGORY.API, [{name: "ContentType", value: CONTENT_TYPE.textPlain}]);
expect(response.metadata).toBe("metadata");
expect(response.testField).toBe("test");
const chatMessageContentTypes = [
CONTENT_TYPE.textPlain,
CONTENT_TYPE.applicationJson,
CONTENT_TYPE.interactiveMessageResponse
];
test("sendMessage works as expected for all chatMessage content-types", async () => {
for(const chatMessageContentType of chatMessageContentTypes) {
const args = {
metadata: "metadata",
message: "message",
contentType: chatMessageContentType
};
const chatController = getChatController();
await chatController.connect();
const response = await chatController.sendMessage(args);
expect(chatClient.sendMessage).toHaveBeenCalledWith("token", "message", chatMessageContentType);
expect(csmService.addCountAndErrorMetric).toHaveBeenCalledWith(ACPS_METHODS.SEND_MESSAGE, CSM_CATEGORY.API, false, [{name: "ContentType", value: chatMessageContentType}]);
expect(csmService.addLatencyMetricWithStartTime).toHaveBeenCalledWith(ACPS_METHODS.SEND_MESSAGE, expect.anything(), CSM_CATEGORY.API, [{name: "ContentType", value: chatMessageContentType}]);
expect(response.metadata).toBe("metadata");
expect(response.testField).toBe("test");

}
});

test("sendMessage throws an error", async () => {
Expand Down

0 comments on commit d85c517

Please sign in to comment.