@@ -56,15 +56,32 @@ describe('handlePropose', () => {
5656 expect ( superSpy ) . not . toHaveBeenCalled ( ) ;
5757 } ) ;
5858
59- it ( 'should not accept session if not autoAcceptPendingLiveScreenMonitoringRequests ' , async ( ) => {
59+ it ( 'should auto- accept as observer when current user is the fromUserId ' , async ( ) => {
6060 const proceedSpy = jest . spyOn ( handler , 'proceedWithSession' ) . mockResolvedValue ( null ) ;
6161 const superSpy = jest . spyOn ( BaseSessionHandler . prototype , 'handlePropose' ) . mockResolvedValue ( null ) ;
6262
6363 mockSdk . _config . autoAcceptPendingLiveScreenMonitoringRequests = false ;
64- await handler . handlePropose ( { } as any ) ;
64+ const pendingSession = { fromUserId : 'user123' } as any ;
65+
66+ await handler . handlePropose ( pendingSession ) ;
67+
68+ expect ( handler . _liveMonitoringObserver ) . toBe ( true ) ;
69+ expect ( proceedSpy ) . toHaveBeenCalledWith ( pendingSession ) ;
70+ expect ( superSpy ) . not . toHaveBeenCalled ( ) ;
71+ } ) ;
6572
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 ) ;
6683 expect ( proceedSpy ) . not . toHaveBeenCalled ( ) ;
67- expect ( superSpy ) . toHaveBeenCalled ( ) ;
84+ expect ( superSpy ) . toHaveBeenCalledWith ( pendingSession ) ;
6885 } ) ;
6986} ) ;
7087
@@ -105,14 +122,15 @@ describe('acceptSession', () => {
105122 expect ( superAcceptSessionSpy ) . toHaveBeenCalledWith ( session , params ) ;
106123 } ) ;
107124
108- it ( 'should default liveMonitoringObserver to false when not provided ' , async ( ) => {
125+ it ( 'should preserve liveMonitoringObserver flag set in handlePropose ' , async ( ) => {
109126 const params = { conversationId : session . conversationId } ;
127+ handler . _liveMonitoringObserver = true ; // Simulate flag set in handlePropose
110128
111129 await handler . acceptSession ( session as any , params ) ;
112130
113- expect ( handler . _liveMonitoringObserver ) . toBe ( false ) ;
114- expect ( acceptSessionForTargetSpy ) . toHaveBeenCalledWith ( session , params ) ;
115- expect ( acceptSessionForObserverSpy ) . not . toHaveBeenCalled ( ) ;
131+ expect ( handler . _liveMonitoringObserver ) . toBe ( true ) ;
132+ expect ( acceptSessionForObserverSpy ) . toHaveBeenCalledWith ( session , params ) ;
133+ expect ( acceptSessionForTargetSpy ) . not . toHaveBeenCalled ( ) ;
116134 expect ( superAcceptSessionSpy ) . toHaveBeenCalledWith ( session , params ) ;
117135 } ) ;
118136} ) ;
0 commit comments