Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up event subscriptions for agent session when transfer.succeede… #241

Merged
merged 1 commit into from
Dec 13, 2024
Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

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

5 changes: 5 additions & 0 deletions src/core/chatController.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ class ChatController {
});
this.breakConnection();
}
if (incomingData.ContentType === CONTENT_TYPE.transferSucceeded && this.sessionType !== SESSION_TYPES.CUSTOMER) {
// calls LpcConnectionHelper to remove message subscriptions for agent and supervisor sessions in Agent transfer use case
// Customer SIM: https://t.corp.amazon.com/P149853425/communication
this.breakConnection();
}
} catch (e) {
this._sendInternalLogToServer(this.logger.error(
"Error occured while handling message from Connection. eventData:",
Expand Down
24 changes: 22 additions & 2 deletions src/core/chatController.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ describe("ChatController", () => {
let startResponse;
let endResponse;

function getChatController(shouldSendMessageReceipts = true) {
function getChatController(shouldSendMessageReceipts = true, sessionType = SESSION_TYPES.AGENT) {
if (!shouldSendMessageReceipts) {
GlobalConfig.removeFeatureFlag(FEATURES.MESSAGE_RECEIPTS_ENABLED);
}
GlobalConfig.updateThrottleTime(1000);

return new ChatController({
sessionType: SESSION_TYPES.AGENT,
sessionType: sessionType,
chatDetails: chatDetails,
chatClient: chatClient,
websocketManager: websocketManager,
Expand Down Expand Up @@ -121,6 +121,12 @@ describe("ChatController", () => {
Type: EVENT,
ContentType: CONTENT_TYPE.chatEnded
}));
},
$simulateConnectionTransferred: () => {
messageHandlers.forEach(f => f({
Type: EVENT,
ContentType: CONTENT_TYPE.transferSucceeded
}));
}
};
});
Expand Down Expand Up @@ -538,6 +544,20 @@ describe("ChatController", () => {
chatController.connectionHelper.$simulateConnectionEnding();
expect(breakConnectionSpy).toHaveBeenCalledTimes(1);
});
test("should call breakConnection for agent session method when transfer.succeeded event is received", async () => {
const chatController = getChatController();
const breakConnectionSpy = jest.spyOn(chatController, "breakConnection");
await chatController.connect();
chatController.connectionHelper.$simulateConnectionTransferred();
expect(breakConnectionSpy).toHaveBeenCalledTimes(1);
});
test("should not call breakConnection for customer session method when transfer.succeeded event is received", async () => {
const chatController = getChatController(true, SESSION_TYPES.CUSTOMER);
const breakConnectionSpy = jest.spyOn(chatController, "breakConnection");
await chatController.connect();
chatController.connectionHelper.$simulateConnectionTransferred();
expect(breakConnectionSpy).toHaveBeenCalledTimes(0);
});
test("should throttle sendEvent for MessageReceipts", done => {
jest.useRealTimers();
const args = {
Expand Down
Loading