@webex/contact-center 3.12.0-next.122 → 3.12.0-next.124

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,10 @@ const dummyContact = {
46
46
  }),
47
47
  consultTransfer: jest.fn().mockResolvedValue('consultTransferred'),
48
48
  cancelTask: jest.fn().mockResolvedValue(undefined),
49
+ exitConference: jest.fn().mockResolvedValue({
50
+ trackingId: 'exit-tracking-id',
51
+ data: {},
52
+ }),
49
53
  } as any;
50
54
 
51
55
  const createBaseData = (overrides: Partial<TaskData> = {}): TaskData =>
@@ -594,6 +598,160 @@ describe('Voice Task', () => {
594
598
  });
595
599
  });
596
600
 
601
+ describe('exitConference()', () => {
602
+ const conferenceTaskData = () =>
603
+ createBaseData({
604
+ agentId: 'agent-1',
605
+ interaction: {
606
+ state: 'conference',
607
+ owner: 'agent-1',
608
+ mainInteractionId: 'int1',
609
+ interactionId: 'int1',
610
+ participants: {
611
+ 'agent-1': {id: 'agent-1', pType: 'Agent', type: 'Agent', hasJoined: true, hasLeft: false},
612
+ 'agent-2': {id: 'agent-2', pType: 'Agent', type: 'Agent', hasJoined: true, hasLeft: false},
613
+ c1: {id: 'c1', pType: 'Customer', type: 'Customer', hasJoined: true, hasLeft: false},
614
+ },
615
+ media: {
616
+ media1: {mediaResourceId: 'media1', isHold: false},
617
+ int1: {
618
+ mediaResourceId: 'int1',
619
+ mType: 'mainCall',
620
+ participants: ['agent-1', 'agent-2', 'c1'],
621
+ isHold: false,
622
+ },
623
+ },
624
+ } as any,
625
+ });
626
+
627
+ const primeConferencing = (voice: Voice, taskData: TaskData) => {
628
+ primeConnectedState(voice, taskData);
629
+ voice.stateMachineService?.send({type: TaskEvent.CONFERENCE_START, taskData});
630
+ expect(voice.stateMachineService?.getSnapshot().value).toBe(TaskState.CONFERENCING);
631
+ };
632
+
633
+ it('transitions to WRAPPING_UP after exitConference when the actor stays CONNECTED', async () => {
634
+ const taskData = conferenceTaskData();
635
+ const voice = new Voice(dummyContact, taskData, {}, undefined, 'agent-1');
636
+ primeConnectedState(voice, taskData);
637
+ expect(voice.stateMachineService?.getSnapshot().value).toBe(TaskState.CONNECTED);
638
+
639
+ await voice.exitConference();
640
+
641
+ expect(dummyContact.exitConference).toHaveBeenCalled();
642
+ expect(voice.stateMachineService?.getSnapshot().value).toBe(TaskState.WRAPPING_UP);
643
+ });
644
+
645
+ it('stamps wrapUpRequired on EXIT_CONFERENCE_SUCCESS when this agent should wrap', async () => {
646
+ const taskData = conferenceTaskData();
647
+ const voice = new Voice(dummyContact, taskData, {}, undefined, 'agent-1');
648
+ primeConferencing(voice, taskData);
649
+ const sendSpy = jest.spyOn(voice.stateMachineService as any, 'send');
650
+
651
+ await voice.exitConference();
652
+
653
+ const successEvent = sendSpy.mock.calls
654
+ .map((call) => call[0])
655
+ .find((event) => event?.type === TaskEvent.EXIT_CONFERENCE_SUCCESS);
656
+
657
+ expect(dummyContact.exitConference).toHaveBeenCalled();
658
+ expect(successEvent?.taskData.wrapUpRequired).toBe(true);
659
+ });
660
+
661
+ it('stamps wrapUpRequired false on EXIT_CONFERENCE_SUCCESS when this agent should not wrap', async () => {
662
+ const taskData = createBaseData({
663
+ agentId: 'agent-2',
664
+ isConsulted: true,
665
+ wrapUpRequired: false,
666
+ interaction: {
667
+ state: 'conference',
668
+ owner: 'agent-1',
669
+ mainInteractionId: 'int1',
670
+ interactionId: 'int1',
671
+ participants: {
672
+ 'agent-1': {id: 'agent-1', pType: 'Agent', type: 'Agent', hasJoined: true, hasLeft: false},
673
+ 'agent-2': {
674
+ id: 'agent-2',
675
+ pType: 'Agent',
676
+ type: 'Agent',
677
+ hasJoined: true,
678
+ hasLeft: false,
679
+ isWrapUp: false,
680
+ },
681
+ },
682
+ } as any,
683
+ });
684
+ const voice = new Voice(dummyContact, taskData, {}, undefined, 'agent-2');
685
+ primeConferencing(voice, taskData);
686
+ const sendSpy = jest.spyOn(voice.stateMachineService as any, 'send');
687
+
688
+ await voice.exitConference();
689
+
690
+ const successEvent = sendSpy.mock.calls
691
+ .map((call) => call[0])
692
+ .find((event) => event?.type === TaskEvent.EXIT_CONFERENCE_SUCCESS);
693
+
694
+ expect(successEvent?.taskData.wrapUpRequired).toBe(false);
695
+ });
696
+
697
+ it('stamps wrapUpRequired true on owner-changed exit when isConsulted is omitted', async () => {
698
+ const taskData = createBaseData({
699
+ agentId: 'agent-1',
700
+ wrapUpRequired: false,
701
+ interaction: {
702
+ state: 'conference',
703
+ owner: 'agent-2',
704
+ mainInteractionId: 'int1',
705
+ interactionId: 'int1',
706
+ participants: {
707
+ 'agent-1': {id: 'agent-1', pType: 'Agent', type: 'Agent', hasJoined: true, hasLeft: false},
708
+ 'agent-2': {id: 'agent-2', pType: 'Agent', type: 'Agent', hasJoined: true, hasLeft: false},
709
+ },
710
+ } as any,
711
+ });
712
+ const voice = new Voice(dummyContact, taskData, {}, undefined, 'agent-1');
713
+ primeConferencing(voice, taskData);
714
+ const sendSpy = jest.spyOn(voice.stateMachineService as any, 'send');
715
+
716
+ await voice.exitConference();
717
+
718
+ const successEvent = sendSpy.mock.calls
719
+ .map((call) => call[0])
720
+ .find((event) => event?.type === TaskEvent.EXIT_CONFERENCE_SUCCESS);
721
+
722
+ expect(successEvent?.taskData.wrapUpRequired).toBe(true);
723
+ });
724
+
725
+ it('ignores a stale cached pending list when the exit response omits it', async () => {
726
+ const taskData = createBaseData({
727
+ agentId: 'agent-1',
728
+ wrapUpRequired: false,
729
+ agentsPendingWrapUp: ['agent-2'],
730
+ interaction: {
731
+ state: 'conference',
732
+ owner: 'agent-2',
733
+ mainInteractionId: 'int1',
734
+ interactionId: 'int1',
735
+ participants: {
736
+ 'agent-1': {id: 'agent-1', pType: 'Agent', type: 'Agent', hasJoined: true, hasLeft: false},
737
+ 'agent-2': {id: 'agent-2', pType: 'Agent', type: 'Agent', hasJoined: true, hasLeft: false},
738
+ },
739
+ } as any,
740
+ });
741
+ const voice = new Voice(dummyContact, taskData, {}, undefined, 'agent-1');
742
+ primeConferencing(voice, taskData);
743
+ const sendSpy = jest.spyOn(voice.stateMachineService as any, 'send');
744
+
745
+ await voice.exitConference();
746
+
747
+ const successEvent = sendSpy.mock.calls
748
+ .map((call) => call[0])
749
+ .find((event) => event?.type === TaskEvent.EXIT_CONFERENCE_SUCCESS);
750
+
751
+ expect(successEvent?.taskData.wrapUpRequired).toBe(true);
752
+ });
753
+ });
754
+
597
755
  describe('consultConference()', () => {
598
756
  afterEach(() => {
599
757
  jest.restoreAllMocks();