@@ -70,37 +70,72 @@ describe('shouldHandleSessionByJid()', () => {
7070} ) ;
7171
7272describe ( 'handlePropose()' , ( ) => {
73- it ( 'should emit pending session and proceed immediately if autoAnswer' , async ( ) => {
73+ it ( 'should ignore the propose if mediaHandling is "autoAnswerOnly" and autoAnswer is false ' , async ( ) => {
7474 const superSpyHandlePropose = jest . spyOn ( BaseSessionHandler . prototype , 'handlePropose' ) ;
7575 const superSpyProceed = jest . spyOn ( BaseSessionHandler . prototype , 'proceedWithSession' ) . mockImplementation ( ) ;
76+ const spy = jest . fn ( ) ;
77+ mockSdk . on ( 'pendingSession' , spy ) ;
78+ const pendingSession = createPendingSession ( SessionTypes . softphone ) ;
79+ pendingSession . autoAnswer = false ;
80+ mockSdk . _mediaHandling = MediaHandling . autoAnswerOnly ;
81+
82+ await handler . handlePropose ( pendingSession ) ;
83+
84+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
85+ expect ( superSpyHandlePropose ) . not . toHaveBeenCalled ( ) ;
86+ expect ( superSpyProceed ) . not . toHaveBeenCalled ( ) ;
87+ } ) ;
7688
89+ it ( 'should not autoAnswer if mediaHandling is "autoAnswerOnly", autoAnswer is true, but disableAutoAnswer is configured' , async ( ) => {
90+ const superSpyHandlePropose = jest . spyOn ( BaseSessionHandler . prototype , 'handlePropose' ) ;
91+ const superSpyProceed = jest . spyOn ( BaseSessionHandler . prototype , 'proceedWithSession' ) . mockImplementation ( ) ;
7792 const spy = jest . fn ( ) ;
7893 mockSdk . on ( 'pendingSession' , spy ) ;
94+ mockSdk . _config . disableAutoAnswer = true ;
95+ const pendingSession = createPendingSession ( SessionTypes . softphone ) ;
96+ pendingSession . autoAnswer = true ;
97+ mockSdk . _mediaHandling = MediaHandling . autoAnswerOnly ;
7998
80- mockSdk . _config . disableAutoAnswer = false ;
99+ await handler . handlePropose ( pendingSession ) ;
81100
101+ expect ( spy ) . toHaveBeenCalled ( ) ;
102+ expect ( superSpyHandlePropose ) . toHaveBeenCalled ( ) ;
103+ expect ( superSpyProceed ) . not . toHaveBeenCalled ( ) ;
104+ } ) ;
105+
106+ it ( 'should emit pending session and proceed immediately if mediaHandling is "autoAnswerOnly", autoAnswer is true, and disableAutoAnswer is not configured' , async ( ) => {
107+ const superSpyHandlePropose = jest . spyOn ( BaseSessionHandler . prototype , 'handlePropose' ) ;
108+ const superSpyProceed = jest . spyOn ( BaseSessionHandler . prototype , 'proceedWithSession' ) . mockImplementation ( ) ;
109+ const spy = jest . fn ( ) ;
110+ mockSdk . on ( 'pendingSession' , spy ) ;
111+ mockSdk . _config . disableAutoAnswer = false ;
82112 const pendingSession = createPendingSession ( SessionTypes . softphone ) ;
83113 pendingSession . autoAnswer = true ;
114+ mockSdk . _mediaHandling = MediaHandling . autoAnswerOnly ;
115+
84116 await handler . handlePropose ( pendingSession ) ;
85117
86118 expect ( spy ) . toHaveBeenCalled ( ) ;
87119 expect ( superSpyHandlePropose ) . toHaveBeenCalled ( ) ;
88120 expect ( superSpyProceed ) . toHaveBeenCalled ( ) ;
89121 } ) ;
90122
91- it ( 'should ignore the propose if mediaHandling is set to "noMedia" ' , async ( ) => {
123+ it ( 'should emit pending session and proceed immediately if autoAnswer ' , async ( ) => {
92124 const superSpyHandlePropose = jest . spyOn ( BaseSessionHandler . prototype , 'handlePropose' ) ;
93125 const superSpyProceed = jest . spyOn ( BaseSessionHandler . prototype , 'proceedWithSession' ) . mockImplementation ( ) ;
126+
94127 const spy = jest . fn ( ) ;
95128 mockSdk . on ( 'pendingSession' , spy ) ;
96- const pendingSession = createPendingSession ( SessionTypes . softphone ) ;
97- mockSdk . _mediaHandling = MediaHandling . noMedia ;
98129
130+ mockSdk . _config . disableAutoAnswer = false ;
131+
132+ const pendingSession = createPendingSession ( SessionTypes . softphone ) ;
133+ pendingSession . autoAnswer = true ;
99134 await handler . handlePropose ( pendingSession ) ;
100135
101- expect ( spy ) . not . toHaveBeenCalled ( ) ;
102- expect ( superSpyHandlePropose ) . not . toHaveBeenCalled ( ) ;
103- expect ( superSpyProceed ) . not . toHaveBeenCalled ( ) ;
136+ expect ( spy ) . toHaveBeenCalled ( ) ;
137+ expect ( superSpyHandlePropose ) . toHaveBeenCalled ( ) ;
138+ expect ( superSpyProceed ) . toHaveBeenCalled ( ) ;
104139 } ) ;
105140
106141 it ( 'should not auto answer if pending session is not autoAnswer' , async ( ) => {
0 commit comments