@@ -303,6 +303,8 @@ function disableRetries(messaging: Messaging) {
303303 ( messaging as any ) . messagingRequestHandler . httpClient . retry = null ;
304304}
305305
306+ class CustomArray extends Array { }
307+
306308describe ( 'Messaging' , ( ) => {
307309 let mockApp : FirebaseApp ;
308310 let messaging : Messaging ;
@@ -608,6 +610,40 @@ describe('Messaging', () => {
608610 } ) ;
609611 } ) ;
610612
613+ it ( 'should be fulfilled with a BatchResponse given array-like (issue #566)' , ( ) => {
614+ const messageIds = [
615+ 'projects/projec_id/messages/1' ,
616+ 'projects/projec_id/messages/2' ,
617+ 'projects/projec_id/messages/3' ,
618+ ] ;
619+ mockedRequests . push ( mockBatchRequest ( messageIds ) ) ;
620+ const message = {
621+ token : 'a' ,
622+ android : {
623+ ttl : 3600 ,
624+ } ,
625+ } ;
626+ const arrayLike = new CustomArray ( ) ;
627+ arrayLike . push ( message ) ;
628+ arrayLike . push ( message ) ;
629+ arrayLike . push ( message ) ;
630+ // Explicitly patch the constructor so that down compiling to ES5 doesn't affect the test.
631+ // See https://github.com/firebase/firebase-admin-node/issues/566#issuecomment-501974238
632+ // for more context.
633+ arrayLike . constructor = CustomArray ;
634+
635+ return messaging . sendAll ( arrayLike )
636+ . then ( ( response : BatchResponse ) => {
637+ expect ( response . successCount ) . to . equal ( 3 ) ;
638+ expect ( response . failureCount ) . to . equal ( 0 ) ;
639+ response . responses . forEach ( ( resp , idx ) => {
640+ expect ( resp . success ) . to . be . true ;
641+ expect ( resp . messageId ) . to . equal ( messageIds [ idx ] ) ;
642+ expect ( resp . error ) . to . be . undefined ;
643+ } ) ;
644+ } ) ;
645+ } ) ;
646+
611647 it ( 'should be fulfilled with a BatchResponse given valid messages in dryRun mode' , ( ) => {
612648 const messageIds = [
613649 'projects/projec_id/messages/1' ,
0 commit comments