@@ -171,7 +171,13 @@ describe('storeEventsWrapper', () => {
171171 interactionId : 'mockInteractionId' ,
172172 interaction : {
173173 state : 'connected' ,
174+ participants : {
175+ agent1 : {
176+ hasJoined : true ,
177+ } ,
178+ } ,
174179 } ,
180+ agentId : 'agent1' ,
175181 } ,
176182 } as ITask ;
177183 storeWrapper . setCurrentTask ( mockCurrentTask ) ;
@@ -470,7 +476,13 @@ describe('storeEventsWrapper', () => {
470476 interactionId : 'interaction1' ,
471477 interaction : {
472478 state : 'connected' ,
479+ participants : {
480+ agent1 : {
481+ hasJoined : true ,
482+ } ,
483+ } ,
473484 } ,
485+ agentId : 'agent1' ,
474486 } ,
475487 on : jest . fn ( ) ,
476488 off : jest . fn ( ) ,
@@ -510,13 +522,32 @@ describe('storeEventsWrapper', () => {
510522 interaction : {
511523 state : 'new' ,
512524 } ,
525+ agentId : 'agent1' ,
526+ // Note: mockTask2 doesn't have hasJoined: true to simulate an incoming task
513527 } ,
514528 on : jest . fn ( ) ,
515529 off : jest . fn ( ) ,
516530 } as unknown as ITask ;
517531
518- storeWrapper [ 'store' ] . taskList = { interaction2 : mockTask } ;
519- storeWrapper . setCurrentTask ( mockTask ) ;
532+ // Set up mockTask with hasJoined: true so it can be set as current task
533+ const mockTaskWithJoined = {
534+ ...mockTask ,
535+ data : {
536+ ...mockTask . data ,
537+ interaction : {
538+ ...mockTask . data . interaction ,
539+ participants : {
540+ agent1 : {
541+ hasJoined : true ,
542+ } ,
543+ } ,
544+ } ,
545+ agentId : 'agent1' ,
546+ } ,
547+ } ;
548+
549+ storeWrapper [ 'store' ] . taskList = { interaction2 : mockTaskWithJoined } ;
550+ storeWrapper . setCurrentTask ( mockTaskWithJoined ) ;
520551
521552 // Call the method under test
522553 storeWrapper . handleIncomingTask ( mockTask2 ) ;
@@ -1647,10 +1678,32 @@ describe('storeEventsWrapper', () => {
16471678
16481679 beforeEach ( ( ) => {
16491680 mockTaskA = {
1650- data : { interactionId : 'taskA' , interaction : { state : 'connected' } } ,
1681+ data : {
1682+ interactionId : 'taskA' ,
1683+ interaction : {
1684+ state : 'connected' ,
1685+ participants : {
1686+ agent1 : {
1687+ hasJoined : true ,
1688+ } ,
1689+ } ,
1690+ } ,
1691+ agentId : 'agent1' ,
1692+ } ,
16511693 } as ITask ;
16521694 mockTaskB = {
1653- data : { interactionId : 'taskB' , interaction : { state : 'connected' } } ,
1695+ data : {
1696+ interactionId : 'taskB' ,
1697+ interaction : {
1698+ state : 'connected' ,
1699+ participants : {
1700+ agent1 : {
1701+ hasJoined : true ,
1702+ } ,
1703+ } ,
1704+ } ,
1705+ agentId : 'agent1' ,
1706+ } ,
16541707 } as ITask ;
16551708 storeWrapper [ 'store' ] . consultCompleted = true ;
16561709 storeWrapper [ 'store' ] . consultInitiated = true ;
@@ -1695,5 +1748,59 @@ describe('storeEventsWrapper', () => {
16951748 storeWrapper . setCurrentTask ( null ) ;
16961749 expect ( storeWrapper . currentTask ) . toBeNull ( ) ;
16971750 } ) ;
1751+
1752+ it ( 'should not change currentTask when task is incoming (hasJoined is false)' , ( ) => {
1753+ // Set an initial task that can be set as current task
1754+ storeWrapper . setCurrentTask ( mockTaskA ) ;
1755+ expect ( storeWrapper . currentTask ) . toEqual ( mockTaskA ) ;
1756+
1757+ // Create an incoming task (without hasJoined: true)
1758+ const incomingTask : ITask = {
1759+ data : {
1760+ interactionId : 'incomingTask' ,
1761+ interaction : {
1762+ state : 'new' ,
1763+ // Note: no participants or hasJoined property to simulate incoming task
1764+ } ,
1765+ agentId : 'agent1' ,
1766+ } ,
1767+ } as ITask ;
1768+
1769+ // Try to set the incoming task as current task
1770+ storeWrapper . setCurrentTask ( incomingTask ) ;
1771+
1772+ // Current task should remain unchanged (still mockTaskA)
1773+ expect ( storeWrapper . currentTask ) . toEqual ( mockTaskA ) ;
1774+ expect ( storeWrapper . currentTask ) . not . toEqual ( incomingTask ) ;
1775+ } ) ;
1776+
1777+ it ( 'should not change currentTask when task has hasJoined false' , ( ) => {
1778+ // This is the case where we transfer the call but agent has not accepted it yet.
1779+ storeWrapper . setCurrentTask ( mockTaskA ) ;
1780+ expect ( storeWrapper . currentTask ) . toEqual ( mockTaskA ) ;
1781+
1782+ // Create a task with explicitly hasJoined: false
1783+ const taskWithoutJoined : ITask = {
1784+ data : {
1785+ interactionId : 'taskWithoutJoined' ,
1786+ interaction : {
1787+ state : 'connected' ,
1788+ participants : {
1789+ agent1 : {
1790+ hasJoined : false ,
1791+ } ,
1792+ } ,
1793+ } ,
1794+ agentId : 'agent1' ,
1795+ } ,
1796+ } as ITask ;
1797+
1798+ // Try to set the task without joined as current task
1799+ storeWrapper . setCurrentTask ( taskWithoutJoined ) ;
1800+
1801+ // Current task should remain unchanged (still mockTaskA)
1802+ expect ( storeWrapper . currentTask ) . toEqual ( mockTaskA ) ;
1803+ expect ( storeWrapper . currentTask ) . not . toEqual ( taskWithoutJoined ) ;
1804+ } ) ;
16981805 } ) ;
16991806} ) ;
0 commit comments