-
Notifications
You must be signed in to change notification settings - Fork 68
fix(cc-store): hydrate engaged state on multi-login events #694
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
base: next
Are you sure you want to change the base?
Changes from all commits
57168f3
fe87147
267b456
c5f7419
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -824,6 +824,27 @@ class StoreWrapper implements IStoreWrapper { | |
| this.refreshTaskList(); | ||
| }; | ||
|
|
||
| handleMultiLoginHydrate = (event) => { | ||
| const task = event as ITask; | ||
| const interactionId = task?.data?.interactionId; | ||
| const interactionState = task?.data?.interaction?.state; | ||
| if (interactionId && this.store.taskList[interactionId] && interactionState === 'new') { | ||
| return; | ||
| } | ||
|
|
||
| if (!task) { | ||
| this.store.logger.warn('CC-Widgets: handleMultiLoginHydrate(): task payload missing', { | ||
| module: 'storeEventsWrapper.ts', | ||
| method: 'handleMultiLoginHydrate', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| this.registerTaskEventListeners(task); | ||
| this.refreshTaskList(); | ||
| this.handleTaskAssigned(task); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. function should mirror handleTaskHydrate's state-aware logic, including the consulting and isTerminated branches.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't registerTAsklistener setup Assigned event listener as well so as part of that handleTaskAssigned won't be invoked ? Why do we need to invoke it separately |
||
| }; | ||
|
|
||
| handleTaskHydrate = (event) => { | ||
| const task = event; | ||
|
|
||
|
|
@@ -1043,6 +1064,7 @@ class StoreWrapper implements IStoreWrapper { | |
| method: 'setupIncomingTaskHandler#addEventListeners', | ||
| }); | ||
| ccSDK.on(TASK_EVENTS.TASK_HYDRATE, this.handleTaskHydrate); | ||
| ccSDK.on(TASK_EVENTS.TASK_MULTI_LOGIN_HYDRATE, this.handleMultiLoginHydrate); | ||
| ccSDK.on(CC_EVENTS.AGENT_STATE_CHANGE, this.handleStateChange); | ||
| ccSDK.on(TASK_EVENTS.TASK_INCOMING, this.handleIncomingTask); | ||
| ccSDK.on(TASK_EVENTS.TASK_CAMPAIGN_PREVIEW_RESERVATION, this.handleIncomingCampaignPreview); | ||
|
|
@@ -1057,6 +1079,7 @@ class StoreWrapper implements IStoreWrapper { | |
| method: 'setupIncomingTaskHandler#removeEventListeners', | ||
| }); | ||
| ccSDK.off(TASK_EVENTS.TASK_HYDRATE, this.handleTaskHydrate); | ||
| ccSDK.off(TASK_EVENTS.TASK_MULTI_LOGIN_HYDRATE, this.handleMultiLoginHydrate); | ||
| ccSDK.off(CC_EVENTS.AGENT_STATE_CHANGE, this.handleStateChange); | ||
| ccSDK.off(TASK_EVENTS.TASK_INCOMING, this.handleIncomingTask); | ||
| ccSDK.off(TASK_EVENTS.TASK_CAMPAIGN_PREVIEW_RESERVATION, this.handleIncomingCampaignPreview); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1176,6 +1176,7 @@ describe('storeEventsWrapper', () => { | |
| }); | ||
|
|
||
| expect(onSpy).toHaveBeenCalledWith(TASK_EVENTS.TASK_HYDRATE, expect.any(Function)); | ||
| expect(onSpy).toHaveBeenCalledWith(TASK_EVENTS.TASK_MULTI_LOGIN_HYDRATE, expect.any(Function)); | ||
| expect(onSpy).toHaveBeenCalledWith(TASK_EVENTS.TASK_INCOMING, expect.any(Function)); | ||
| expect(onSpy).toHaveBeenCalledWith(TASK_EVENTS.TASK_MERGED, expect.any(Function)); | ||
| expect(onSpy).toHaveBeenCalledWith(CC_EVENTS.AGENT_STATE_CHANGE, expect.any(Function)); | ||
|
|
@@ -1601,6 +1602,50 @@ describe('storeEventsWrapper', () => { | |
| }); | ||
| }); | ||
|
|
||
| it('should skip multiLoginHydrate when interaction already exists in taskList with new state', () => { | ||
| const interactionId = 'multi-hydrate-skip-1'; | ||
| const task = { | ||
| data: { | ||
| interactionId, | ||
| interaction: {state: 'new'}, | ||
| }, | ||
| on: jest.fn(), | ||
| off: jest.fn(), | ||
| } as unknown as ITask; | ||
|
|
||
| storeWrapper['store'].taskList = {[interactionId]: task}; | ||
|
|
||
| const refreshSpy = jest.spyOn(storeWrapper, 'refreshTaskList'); | ||
| const assignedSpy = jest.spyOn(storeWrapper, 'handleTaskAssigned'); | ||
|
|
||
| storeWrapper.handleMultiLoginHydrate(task); | ||
|
|
||
| expect(refreshSpy).not.toHaveBeenCalled(); | ||
| expect(assignedSpy).not.toHaveBeenCalled(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we not checking number of times these spies are called ? Just a common practice we followed for all our unit tests so general comment to keep the pattern consistent if possible |
||
| }); | ||
|
|
||
| it('should process multiLoginHydrate when interaction state is connected', () => { | ||
| const interactionId = 'multi-hydrate-connected-1'; | ||
| const task = { | ||
| data: { | ||
| interactionId, | ||
| interaction: {state: 'connected'}, | ||
| }, | ||
| on: jest.fn(), | ||
| off: jest.fn(), | ||
| } as unknown as ITask; | ||
|
|
||
| storeWrapper['store'].taskList = {[interactionId]: task}; | ||
|
|
||
| const refreshSpy = jest.spyOn(storeWrapper, 'refreshTaskList'); | ||
| const assignedSpy = jest.spyOn(storeWrapper, 'handleTaskAssigned'); | ||
|
|
||
| storeWrapper.handleMultiLoginHydrate(task); | ||
|
|
||
| expect(refreshSpy).toHaveBeenCalled(); | ||
| expect(assignedSpy).toHaveBeenCalledWith(task); | ||
| }); | ||
|
|
||
| it('should handle hydrating the store with correct data', async () => { | ||
| const setCurrentTaskSpy = jest.spyOn(storeWrapper, 'setCurrentTask'); | ||
| const refreshTaskListSpy = jest.spyOn(storeWrapper, 'refreshTaskList'); | ||
|
|
@@ -1665,6 +1710,7 @@ describe('storeEventsWrapper', () => { | |
| }); | ||
|
|
||
| expect(storeWrapper['cc'].off).toHaveBeenCalledWith(TASK_EVENTS.TASK_HYDRATE, expect.any(Function)); | ||
| expect(storeWrapper['cc'].off).toHaveBeenCalledWith(TASK_EVENTS.TASK_MULTI_LOGIN_HYDRATE, expect.any(Function)); | ||
| expect(storeWrapper['cc'].off).toHaveBeenCalledWith(TASK_EVENTS.TASK_INCOMING, expect.any(Function)); | ||
| expect(storeWrapper['cc'].off).toHaveBeenCalledWith(TASK_EVENTS.TASK_MERGED, expect.any(Function)); | ||
| expect(storeWrapper['cc'].off).toHaveBeenCalledWith(CC_EVENTS.AGENT_STATE_CHANGE, expect.any(Function)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block should be the first block in the method and then the rest of the code since we are checking here the task object existing itself