Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,39 @@
Type: "EVENT",
InitialContactId: ""
};

// Content types valid for sendMessage operations
export const SEND_MESSAGE_CONTENT_TYPES = [
CONTENT_TYPE.textPlain,

Check warning on line 206 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 4 spaces but found 2

Check warning on line 206 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 4 spaces but found 2

Check warning on line 206 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (19.x)

Expected indentation of 4 spaces but found 2
CONTENT_TYPE.textMarkdown,

Check warning on line 207 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 4 spaces but found 2

Check warning on line 207 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 4 spaces but found 2

Check warning on line 207 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (19.x)

Expected indentation of 4 spaces but found 2
CONTENT_TYPE.applicationJson,

Check warning on line 208 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 4 spaces but found 2

Check warning on line 208 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 4 spaces but found 2

Check warning on line 208 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (19.x)

Expected indentation of 4 spaces but found 2
CONTENT_TYPE.interactiveMessage,

Check warning on line 209 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 4 spaces but found 2

Check warning on line 209 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 4 spaces but found 2

Check warning on line 209 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (19.x)

Expected indentation of 4 spaces but found 2
CONTENT_TYPE.interactiveMessageResponse

Check warning on line 210 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 4 spaces but found 2

Check warning on line 210 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 4 spaces but found 2

Check warning on line 210 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (19.x)

Expected indentation of 4 spaces but found 2
];

// Content types valid for sendEvent operations
export const SEND_EVENT_CONTENT_TYPES = [
CONTENT_TYPE.typing,

Check warning on line 215 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 4 spaces but found 2

Check warning on line 215 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 4 spaces but found 2

Check warning on line 215 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (19.x)

Expected indentation of 4 spaces but found 2
CONTENT_TYPE.connectionAcknowledged,

Check warning on line 216 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 4 spaces but found 2

Check warning on line 216 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 4 spaces but found 2

Check warning on line 216 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (19.x)

Expected indentation of 4 spaces but found 2
CONTENT_TYPE.readReceipt,

Check warning on line 217 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 4 spaces but found 2

Check warning on line 217 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 4 spaces but found 2

Check warning on line 217 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (19.x)

Expected indentation of 4 spaces but found 2
CONTENT_TYPE.deliveredReceipt,

Check warning on line 218 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 4 spaces but found 2

Check warning on line 218 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 4 spaces but found 2

Check warning on line 218 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (19.x)

Expected indentation of 4 spaces but found 2
CONTENT_TYPE.participantIdle,

Check warning on line 219 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Expected indentation of 4 spaces but found 2

Check warning on line 219 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Expected indentation of 4 spaces but found 2

Check warning on line 219 in src/constants.js

View workflow job for this annotation

GitHub Actions / build (19.x)

Expected indentation of 4 spaces but found 2
CONTENT_TYPE.participantReturned,
CONTENT_TYPE.participantInactive,
CONTENT_TYPE.participantActive,
CONTENT_TYPE.participantJoined,
CONTENT_TYPE.participantLeft,
CONTENT_TYPE.chatEnded,
CONTENT_TYPE.transferSucceeded,
CONTENT_TYPE.transferFailed,
CONTENT_TYPE.autoDisconnection,
CONTENT_TYPE.authenticationInitiated,
CONTENT_TYPE.authenticationSuccessful,
CONTENT_TYPE.authenticationFailed,
CONTENT_TYPE.authenticationTimeout,
CONTENT_TYPE.authenticationExpired,
CONTENT_TYPE.authenticationCanceled,
CONTENT_TYPE.participantDisplayNameUpdated,
CONTENT_TYPE.chatRehydrated,
CONTENT_TYPE.participantInvited
];
14 changes: 11 additions & 3 deletions src/core/chatArgsValidator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Utils from "../utils";
import { IllegalArgumentException } from "./exceptions";
import { CONTENT_TYPE, SESSION_TYPES } from "../constants";
import { CONTENT_TYPE, SESSION_TYPES, SEND_MESSAGE_CONTENT_TYPES, SEND_EVENT_CONTENT_TYPES } from "../constants";

class ChatControllerArgsValidator {
/*eslint-disable no-unused-vars*/
Expand All @@ -13,7 +13,15 @@ class ChatControllerArgsValidator {
if (!Utils.isString(args.message)) {
throw new IllegalArgumentException(args.message + "is not a valid message");
}
this.validateContentType(args.contentType);
this.validateSendMessageContentType(args.contentType);
}

validateSendMessageContentType(contentType) {
Utils.assertIsEnum(contentType, SEND_MESSAGE_CONTENT_TYPES, "contentType for sendMessage");
}

validateSendEventContentType(contentType) {
Utils.assertIsEnum(contentType, SEND_EVENT_CONTENT_TYPES, "contentType for sendEvent");
}

validateContentType(contentType) {
Expand All @@ -39,7 +47,7 @@ class ChatControllerArgsValidator {
}

validateSendEvent(args) {
this.validateContentType(args.contentType);
this.validateSendEventContentType(args.contentType);
}

/*eslint-disable no-unused-vars*/
Expand Down
19 changes: 19 additions & 0 deletions src/core/chatArgsValidator.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CONTENT_TYPE } from "../constants";
import { ChatServiceArgsValidator } from "./chatArgsValidator";
import { IllegalArgumentException } from "./exceptions";

Expand Down Expand Up @@ -57,4 +58,22 @@ describe("ChatServiceArgsValidator", () => {
const validateCall = () => chatArgsValidator.validateSendEvent(sendEventRequest);
expect(validateCall).toThrow(IllegalArgumentException);
});

test("validateSendMessage only passes on valid content types", () => {
const sendMessageRequest = {
message: "Hello world",
contentType: CONTENT_TYPE.textPlain
};
const chatArgsValidator = getValidator();
chatArgsValidator.validateSendMessage(sendMessageRequest);

sendMessageRequest.contentType = CONTENT_TYPE.textMarkdown;
expect(() => chatArgsValidator.validateSendMessage(sendMessageRequest)).not.toThrow();

sendMessageRequest.contentType = CONTENT_TYPE.typing;
expect(() => chatArgsValidator.validateSendMessage(sendMessageRequest)).toThrow(IllegalArgumentException);

sendMessageRequest.contentType = "text/html";
expect(() => chatArgsValidator.validateSendMessage(sendMessageRequest)).toThrow(IllegalArgumentException);
});
});