@@ -2,7 +2,7 @@ import * as chai from "chai";
2
2
import * as nock from "nock" ;
3
3
import * as chaiAsPromised from "chai-as-promised" ;
4
4
5
- import { listEvents } from "./events" ;
5
+ import { listEvents , batchGetEvents } from "./events" ;
6
6
import { FirebaseError } from "../error" ;
7
7
import { crashlyticsApiOrigin } from "../api" ;
8
8
@@ -82,4 +82,54 @@ describe("events", () => {
82
82
) . to . be . rejectedWith ( FirebaseError , "Unable to get the projectId from the AppId." ) ;
83
83
} ) ;
84
84
} ) ;
85
+
86
+ describe ( "batchGetEvents" , ( ) => {
87
+ const eventNames = [
88
+ "projects/1234567890/apps/1:1234567890:android:abcdef1234567890/events/test_event_id_1" ,
89
+ "projects/1234567890/apps/1:1234567890:android:abcdef1234567890/events/test_event_id_2" ,
90
+ ] ;
91
+
92
+ it ( "should resolve with the response body on success" , async ( ) => {
93
+ const mockResponse = {
94
+ events : [ { id : "test_event_id_1" } , { id : "test_event_id_2" } ] ,
95
+ } ;
96
+
97
+ nock ( crashlyticsApiOrigin ( ) )
98
+ . get ( `/v1alpha/projects/${ requestProjectNumber } /apps/${ appId } /events:batchGet` )
99
+ . query ( {
100
+ "event.names" : eventNames ,
101
+ } )
102
+ . reply ( 200 , mockResponse ) ;
103
+
104
+ const result = await batchGetEvents ( appId , eventNames ) ;
105
+
106
+ expect ( result ) . to . deep . equal ( mockResponse ) ;
107
+ expect ( nock . isDone ( ) ) . to . be . true ;
108
+ } ) ;
109
+
110
+ it ( "should throw a FirebaseError if the API call fails" , async ( ) => {
111
+ nock ( crashlyticsApiOrigin ( ) )
112
+ . get ( `/v1alpha/projects/${ requestProjectNumber } /apps/${ appId } /events:batchGet` )
113
+ . query ( {
114
+ "event.names" : eventNames ,
115
+ } )
116
+ . reply ( 500 , { error : "Internal Server Error" } ) ;
117
+
118
+ await expect ( batchGetEvents ( appId , eventNames ) ) . to . be . rejectedWith (
119
+ FirebaseError ,
120
+ `Failed to batch get events for app_id ${ appId } .` ,
121
+ ) ;
122
+ } ) ;
123
+
124
+ it ( "should throw a FirebaseError if there are too many events" , async ( ) => {
125
+ const tooManyEventNames = Array . from ( Array ( 101 ) . keys ( ) ) . map (
126
+ ( i ) =>
127
+ `projects/1234567890/apps/1:1234567890:android:abcdef1234567890/events/test_event_id_${ i } ` ,
128
+ ) ;
129
+ await expect ( batchGetEvents ( appId , tooManyEventNames ) ) . to . be . rejectedWith (
130
+ FirebaseError ,
131
+ "Too many events in batchGet request" ,
132
+ ) ;
133
+ } ) ;
134
+ } ) ;
85
135
} ) ;
0 commit comments