@@ -3,13 +3,11 @@ import { mediaSessionStore } from './MediaSessionStore';
33import { mediaSessionInstance } from './MediaSessionInstance' ;
44
55const mockCallStoreReset = jest . fn ( ) ;
6- const mockSyncTransientCallIdFromNativePending = jest . fn ( ) ;
76const mockUseCallStoreGetState = jest . fn ( ( ) => ( {
87 reset : mockCallStoreReset ,
98 setCall : jest . fn ( ) ,
109 setCallId : jest . fn ( ) ,
11- clearNativePendingAccept : jest . fn ( ) ,
12- syncTransientCallIdFromNativePending : mockSyncTransientCallIdFromNativePending ,
10+ resetNativeCallId : jest . fn ( ) ,
1311 call : null as unknown ,
1412 callId : null as string | null ,
1513 nativeAcceptedCallId : null as string | null
@@ -116,8 +114,7 @@ describe('MediaSessionInstance', () => {
116114 reset : mockCallStoreReset ,
117115 setCall : jest . fn ( ) ,
118116 setCallId : jest . fn ( ) ,
119- clearNativePendingAccept : jest . fn ( ) ,
120- syncTransientCallIdFromNativePending : mockSyncTransientCallIdFromNativePending ,
117+ resetNativeCallId : jest . fn ( ) ,
121118 call : null ,
122119 callId : null ,
123120 nativeAcceptedCallId : null
@@ -155,35 +152,6 @@ describe('MediaSessionInstance', () => {
155152 spy . mockRestore ( ) ;
156153 } ) ;
157154
158- it ( 'should sync transient callId from sticky native pending after reset inside init' , ( ) => {
159- mockUseCallStoreGetState . mockReturnValue ( {
160- reset : mockCallStoreReset ,
161- setCall : jest . fn ( ) ,
162- setCallId : jest . fn ( ) ,
163- clearNativePendingAccept : jest . fn ( ) ,
164- syncTransientCallIdFromNativePending : mockSyncTransientCallIdFromNativePending ,
165- call : null ,
166- callId : null ,
167- nativeAcceptedCallId : 'native-accepted-call-id'
168- } ) ;
169- mediaSessionInstance . init ( 'user-1' ) ;
170- expect ( mockSyncTransientCallIdFromNativePending ) . toHaveBeenCalledWith ( ) ;
171- } ) ;
172-
173- it ( 'should still invoke sync when store already has call object' , ( ) => {
174- mockUseCallStoreGetState . mockReturnValue ( {
175- reset : mockCallStoreReset ,
176- setCall : jest . fn ( ) ,
177- setCallId : jest . fn ( ) ,
178- clearNativePendingAccept : jest . fn ( ) ,
179- syncTransientCallIdFromNativePending : mockSyncTransientCallIdFromNativePending ,
180- call : { callId : 'x' } as any ,
181- callId : 'x' ,
182- nativeAcceptedCallId : 'native-accepted-call-id'
183- } ) ;
184- mediaSessionInstance . init ( 'user-1' ) ;
185- expect ( mockSyncTransientCallIdFromNativePending ) . toHaveBeenCalledWith ( ) ;
186- } ) ;
187155 } ) ;
188156
189157 describe ( 'teardown and user switch' , ( ) => {
@@ -251,16 +219,47 @@ describe('MediaSessionInstance', () => {
251219 answerSpy . mockRestore ( ) ;
252220 } ) ;
253221
254- it ( 'calls answerCall when native-accepted store callId matches signal and contract matches device ' , async ( ) => {
222+ it ( 'does not call answerCall when transient callId matches signal but nativeAcceptedCallId does not ' , async ( ) => {
255223 const answerSpy = jest . spyOn ( mediaSessionInstance , 'answerCall' ) . mockResolvedValue ( undefined ) ;
256224 mockUseCallStoreGetState . mockReturnValue ( {
257225 reset : mockCallStoreReset ,
258226 setCall : jest . fn ( ) ,
259227 setCallId : jest . fn ( ) ,
260- clearNativePendingAccept : jest . fn ( ) ,
261- syncTransientCallIdFromNativePending : mockSyncTransientCallIdFromNativePending ,
228+ resetNativeCallId : jest . fn ( ) ,
262229 call : null ,
263230 callId : 'from-signal' ,
231+ nativeAcceptedCallId : null
232+ } ) ;
233+ mediaSessionInstance . init ( 'user-1' ) ;
234+ const streamHandler = getStreamNotifyHandler ( ) ;
235+ streamHandler ( {
236+ msg : 'changed' ,
237+ fields : {
238+ eventName : 'uid/media-signal' ,
239+ args : [
240+ {
241+ type : 'notification' ,
242+ notification : 'accepted' ,
243+ signedContractId : 'test-device-id' ,
244+ callId : 'from-signal'
245+ }
246+ ]
247+ }
248+ } ) ;
249+ await Promise . resolve ( ) ;
250+ expect ( answerSpy ) . not . toHaveBeenCalled ( ) ;
251+ answerSpy . mockRestore ( ) ;
252+ } ) ;
253+
254+ it ( 'calls answerCall when nativeAcceptedCallId matches signal and contract matches device' , async ( ) => {
255+ const answerSpy = jest . spyOn ( mediaSessionInstance , 'answerCall' ) . mockResolvedValue ( undefined ) ;
256+ mockUseCallStoreGetState . mockReturnValue ( {
257+ reset : mockCallStoreReset ,
258+ setCall : jest . fn ( ) ,
259+ setCallId : jest . fn ( ) ,
260+ resetNativeCallId : jest . fn ( ) ,
261+ call : null ,
262+ callId : null ,
264263 nativeAcceptedCallId : 'from-signal'
265264 } ) ;
266265 mediaSessionInstance . init ( 'user-1' ) ;
@@ -284,14 +283,13 @@ describe('MediaSessionInstance', () => {
284283 answerSpy . mockRestore ( ) ;
285284 } ) ;
286285
287- it ( 'calls answerCall when only sticky native id matches (transient callId null)' , async ( ) => {
286+ it ( 'calls answerCall when only nativeAcceptedCallId matches (transient callId null)' , async ( ) => {
288287 const answerSpy = jest . spyOn ( mediaSessionInstance , 'answerCall' ) . mockResolvedValue ( undefined ) ;
289288 mockUseCallStoreGetState . mockReturnValue ( {
290289 reset : mockCallStoreReset ,
291290 setCall : jest . fn ( ) ,
292291 setCallId : jest . fn ( ) ,
293- clearNativePendingAccept : jest . fn ( ) ,
294- syncTransientCallIdFromNativePending : mockSyncTransientCallIdFromNativePending ,
292+ resetNativeCallId : jest . fn ( ) ,
295293 call : null ,
296294 callId : null ,
297295 nativeAcceptedCallId : 'sticky-only'
@@ -323,8 +321,7 @@ describe('MediaSessionInstance', () => {
323321 reset : mockCallStoreReset ,
324322 setCall : jest . fn ( ) ,
325323 setCallId : jest . fn ( ) ,
326- clearNativePendingAccept : jest . fn ( ) ,
327- syncTransientCallIdFromNativePending : mockSyncTransientCallIdFromNativePending ,
324+ resetNativeCallId : jest . fn ( ) ,
328325 call : { callId : 'from-signal' } as any ,
329326 callId : 'from-signal' ,
330327 nativeAcceptedCallId : 'from-signal'
0 commit comments