@@ -5,7 +5,9 @@ import LiveMonitoringSessionHandler from '../../../src/sessions/live-monitoring-
55import * as utils from '../../../src/utils' ;
66import BaseSessionHandler from "../../../src/sessions/base-session-handler" ;
77import * as mediaUtils from "../../../src/media/media-utils" ;
8- import { IExtendedMediaSession , LiveScreenMonitoringSession , VideoMediaSession } from "../../../src" ;
8+ import {
9+ LiveScreenMonitoringSession ,
10+ } from "../../../src" ;
911
1012let handler : LiveMonitoringSessionHandler ;
1113let mockSdk : GenesysCloudWebrtcSdk ;
@@ -54,15 +56,32 @@ describe('handlePropose', () => {
5456 expect ( superSpy ) . not . toHaveBeenCalled ( ) ;
5557 } ) ;
5658
57- it ( 'should not accept session if not autoAcceptPendingLiveScreenMonitoringRequests ' , async ( ) => {
59+ it ( 'should auto- accept as target when current user is the fromUserId ' , async ( ) => {
5860 const proceedSpy = jest . spyOn ( handler , 'proceedWithSession' ) . mockResolvedValue ( null ) ;
5961 const superSpy = jest . spyOn ( BaseSessionHandler . prototype , 'handlePropose' ) . mockResolvedValue ( null ) ;
6062
6163 mockSdk . _config . autoAcceptPendingLiveScreenMonitoringRequests = false ;
62- await handler . handlePropose ( { } as any ) ;
64+ const pendingSession = { fromUserId : 'user123' } as any ;
65+
66+ await handler . handlePropose ( pendingSession ) ;
67+
68+ expect ( handler . _liveMonitoringObserver ) . toBe ( false ) ;
69+ expect ( proceedSpy ) . toHaveBeenCalledWith ( pendingSession ) ;
70+ expect ( superSpy ) . not . toHaveBeenCalled ( ) ;
71+ } ) ;
6372
73+ it ( 'should not accept session if not autoAcceptPendingLiveScreenMonitoringRequests and user is not observer' , async ( ) => {
74+ const proceedSpy = jest . spyOn ( handler , 'proceedWithSession' ) . mockResolvedValue ( null ) ;
75+ const superSpy = jest . spyOn ( BaseSessionHandler . prototype , 'handlePropose' ) . mockResolvedValue ( null ) ;
76+
77+ mockSdk . _config . autoAcceptPendingLiveScreenMonitoringRequests = false ;
78+ const pendingSession = { fromUserId : 'different-user' } as any ;
79+
80+ await handler . handlePropose ( pendingSession ) ;
81+
82+ expect ( handler . _liveMonitoringObserver ) . toBe ( false ) ;
6483 expect ( proceedSpy ) . not . toHaveBeenCalled ( ) ;
65- expect ( superSpy ) . toHaveBeenCalled ( ) ;
84+ expect ( superSpy ) . toHaveBeenCalledWith ( pendingSession ) ;
6685 } ) ;
6786} ) ;
6887
@@ -103,14 +122,15 @@ describe('acceptSession', () => {
103122 expect ( superAcceptSessionSpy ) . toHaveBeenCalledWith ( session , params ) ;
104123 } ) ;
105124
106- it ( 'should default liveMonitoringObserver to false when not provided ' , async ( ) => {
125+ it ( 'should preserve liveMonitoringObserver flag set in handlePropose ' , async ( ) => {
107126 const params = { conversationId : session . conversationId } ;
127+ handler . _liveMonitoringObserver = true ; // Simulate flag set in handlePropose
108128
109129 await handler . acceptSession ( session as any , params ) ;
110130
111- expect ( handler . _liveMonitoringObserver ) . toBe ( false ) ;
112- expect ( acceptSessionForTargetSpy ) . toHaveBeenCalledWith ( session , params ) ;
113- expect ( acceptSessionForObserverSpy ) . not . toHaveBeenCalled ( ) ;
131+ expect ( handler . _liveMonitoringObserver ) . toBe ( true ) ;
132+ expect ( acceptSessionForObserverSpy ) . toHaveBeenCalledWith ( session , params ) ;
133+ expect ( acceptSessionForTargetSpy ) . not . toHaveBeenCalled ( ) ;
114134 expect ( superAcceptSessionSpy ) . toHaveBeenCalledWith ( session , params ) ;
115135 } ) ;
116136} ) ;
0 commit comments