@@ -421,12 +421,25 @@ describe('chat service api', () => {
421421 const listener = {
422422 onIncomingMessage : sinon . stub ( ) ,
423423 onQueueEmpty : sinon . stub ( ) ,
424+ onReceivedAlerts : sinon . stub ( ) ,
424425 onConnectionInterrupted : sinon . stub ( ) ,
425426 } ;
427+
428+ // We have to set this up ahead of time because the callback is scheduled as part of the
429+ // connect action.
430+ const receivedAlerts = new CompletablePromise ( ) ;
431+ listener . onReceivedAlerts . callsFake ( receivedAlerts . resolve ) ;
432+
426433 const tokio = new TokioAsyncContext ( Native . TokioAsyncContext_new ( ) ) ;
427434 const [ _chat , fakeRemote ] = AuthenticatedChatConnection . fakeConnect (
428435 tokio ,
429- listener
436+ listener ,
437+ [ 'UPPERcase' , 'lowercase' ]
438+ ) ;
439+
440+ await receivedAlerts . done ( ) ;
441+ expect ( listener . onReceivedAlerts ) . to . have . been . calledOnceWith (
442+ sinon . match . array . deepEquals ( [ 'UPPERcase' , 'lowercase' ] )
430443 ) ;
431444
432445 // a helper function to check that the message has been passed to the listener
@@ -475,6 +488,9 @@ describe('chat service api', () => {
475488 onQueueEmpty ( ) : void {
476489 recordCall ( '_queue_empty' ) ;
477490 } ,
491+ onReceivedAlerts ( alerts : string [ ] ) : void {
492+ recordCall ( '_received_alerts' , alerts ) ;
493+ } ,
478494 onConnectionInterrupted ( cause : object | null ) : void {
479495 recordCall ( '_connection_interrupted' , cause ) ;
480496 } ,
@@ -499,6 +515,10 @@ describe('chat service api', () => {
499515 ] ;
500516 const callsReceived : [ string , ( object | null ) [ ] ] [ ] = [ ] ;
501517 const callsExpected : [ string , ( ( value : object | null ) => void ) [ ] ] [ ] = [
518+ [
519+ '_received_alerts' ,
520+ [ ( value : object | null ) => expect ( value ) . deep . equals ( [ ] ) ] ,
521+ ] ,
502522 [ '_incoming_message' , [ ] ] ,
503523 [ '_queue_empty' , [ ] ] ,
504524 [ '_incoming_message' , [ ] ] ,
@@ -550,6 +570,9 @@ describe('chat service api', () => {
550570 onQueueEmpty ( ) : void {
551571 fail ( 'unexpected call' ) ;
552572 } ,
573+ onReceivedAlerts ( _alerts : string [ ] ) : void {
574+ fail ( 'unexpected call' ) ;
575+ } ,
553576 onConnectionInterrupted ( cause : object | null ) : void {
554577 connectionInterruptedReasons . push ( cause ) ;
555578 completable . complete ( ) ;
@@ -571,6 +594,7 @@ describe('chat service api', () => {
571594 const [ chat , fakeRemote ] = AuthenticatedChatConnection . fakeConnect ( tokio , {
572595 onIncomingMessage : ( ) => { } ,
573596 onQueueEmpty : ( ) => { } ,
597+ onReceivedAlerts ( ) { } ,
574598 onConnectionInterrupted : ( ) => { } ,
575599 } ) ;
576600
0 commit comments