@@ -213,6 +213,7 @@ describe('API tests', () => {
213
213
expect ( app ) . to . not . equal ( null ) ;
214
214
expect ( app . automaticDataCollectionEnabled ) . to . be . false ;
215
215
await deleteApp ( app ) ;
216
+ expect ( ( app as FirebaseServerAppImpl ) . isDeleted ) . to . be . true ;
216
217
} ) ;
217
218
218
219
it ( 'creates FirebaseServerApp with automaticDataCollectionEnabled' , async ( ) => {
@@ -233,6 +234,7 @@ describe('API tests', () => {
233
234
expect ( app ) . to . not . equal ( null ) ;
234
235
expect ( app . automaticDataCollectionEnabled ) . to . be . true ;
235
236
await deleteApp ( app ) ;
237
+ expect ( ( app as FirebaseServerAppImpl ) . isDeleted ) . to . be . true ;
236
238
} ) ;
237
239
238
240
it ( 'creates FirebaseServerApp with releaseOnDeref' , async ( ) => {
@@ -251,6 +253,7 @@ describe('API tests', () => {
251
253
expect ( app ) . to . not . equal ( null ) ;
252
254
expect ( app . automaticDataCollectionEnabled ) . to . be . false ;
253
255
await deleteApp ( app ) ;
256
+ expect ( ( app as FirebaseServerAppImpl ) . isDeleted ) . to . be . true ;
254
257
} ) ;
255
258
256
259
it ( 'creates FirebaseServerApp with FirebaseApp' , async ( ) => {
@@ -274,6 +277,7 @@ describe('API tests', () => {
274
277
expect ( app ) . to . not . equal ( null ) ;
275
278
expect ( app . options . apiKey ) . to . equal ( 'test1' ) ;
276
279
await deleteApp ( app ) ;
280
+ expect ( ( app as FirebaseServerAppImpl ) . isDeleted ) . to . be . true ;
277
281
} ) ;
278
282
} ) ;
279
283
@@ -285,8 +289,7 @@ describe('API tests', () => {
285
289
286
290
const options = { apiKey : 'APIKEY' } ;
287
291
const serverAppSettingsOne : FirebaseServerAppSettings = {
288
- automaticDataCollectionEnabled : false ,
289
- releaseOnDeref : options
292
+ automaticDataCollectionEnabled : true
290
293
} ;
291
294
292
295
const serverAppSettingsTwo : FirebaseServerAppSettings = {
@@ -295,12 +298,42 @@ describe('API tests', () => {
295
298
296
299
const appOne = initializeServerApp ( options , serverAppSettingsOne ) ;
297
300
expect ( appOne ) . to . not . equal ( null ) ;
298
- expect ( appOne . automaticDataCollectionEnabled ) . to . be . false ;
301
+ expect ( appOne . automaticDataCollectionEnabled ) . to . be . true ;
299
302
const appTwo = initializeServerApp ( options , serverAppSettingsTwo ) ;
300
303
expect ( appTwo ) . to . not . equal ( null ) ;
304
+ expect ( appTwo . automaticDataCollectionEnabled ) . to . be . false ;
301
305
expect ( appTwo ) . to . not . equal ( appOne ) ;
302
306
await deleteApp ( appOne ) ;
303
307
await deleteApp ( appTwo ) ;
308
+ expect ( ( appOne as FirebaseServerAppImpl ) . isDeleted ) . to . be . true ;
309
+ expect ( ( appTwo as FirebaseServerAppImpl ) . isDeleted ) . to . be . true ;
310
+ } ) ;
311
+
312
+ it ( 'create FirebaseServerApps with varying deleteOnDeref, and they still return same object ' , async ( ) => {
313
+ if ( isBrowser ( ) ) {
314
+ // FirebaseServerApp isn't supported for execution in browser enviornments.
315
+ return ;
316
+ }
317
+
318
+ const options = { apiKey : 'APIKEY' } ;
319
+ const serverAppSettingsOne : FirebaseServerAppSettings = {
320
+ automaticDataCollectionEnabled : false
321
+ } ;
322
+
323
+ const serverAppSettingsTwo : FirebaseServerAppSettings = {
324
+ automaticDataCollectionEnabled : false ,
325
+ releaseOnDeref : options
326
+ } ;
327
+
328
+ const appOne = initializeServerApp ( options , serverAppSettingsOne ) ;
329
+ expect ( appOne ) . to . not . equal ( null ) ;
330
+ expect ( appOne . automaticDataCollectionEnabled ) . to . be . false ;
331
+ const appTwo = initializeServerApp ( options , serverAppSettingsTwo ) ;
332
+ expect ( appTwo ) . to . not . equal ( null ) ;
333
+ expect ( appTwo . automaticDataCollectionEnabled ) . to . be . false ;
334
+ expect ( appTwo ) . to . equal ( appOne ) ;
335
+ await deleteApp ( appOne ) ;
336
+ await deleteApp ( appTwo ) ;
304
337
} ) ;
305
338
306
339
it ( 'create duplicate FirebaseServerApps returns the same object' , async ( ) => {
@@ -322,11 +355,40 @@ describe('API tests', () => {
322
355
expect ( appTwo ) . to . not . equal ( null ) ;
323
356
expect ( appTwo ) . to . equal ( appOne ) ;
324
357
await deleteApp ( appOne ) ;
358
+ await deleteApp ( appTwo ) ;
359
+ } ) ;
325
360
326
- // TODO: When Reference Counting works, update test. The following line should be false
327
- // until and the app should be deleted a second time.
361
+ it ( 'deleting FirebaseServerApps is ref counted' , async ( ) => {
362
+ if ( isBrowser ( ) ) {
363
+ // FirebaseServerApp isn't supported for execution in browser enviornments.
364
+ return ;
365
+ }
366
+
367
+ const options = { apiKey : 'APIKEY' } ;
368
+ const serverAppSettings : FirebaseServerAppSettings = {
369
+ automaticDataCollectionEnabled : false ,
370
+ releaseOnDeref : options
371
+ } ;
372
+
373
+ const appOne = initializeServerApp ( options , serverAppSettings ) ;
374
+ expect ( ( appOne as FirebaseServerAppImpl ) . refCount ) . to . equal ( 1 ) ;
375
+
376
+ const appTwo = initializeServerApp ( options , serverAppSettings ) ;
377
+ expect ( appTwo ) . to . equal ( appOne ) ;
378
+ expect ( ( appOne as FirebaseServerAppImpl ) . refCount ) . to . equal ( 2 ) ;
379
+ expect ( ( appTwo as FirebaseServerAppImpl ) . refCount ) . to . equal ( 2 ) ;
380
+
381
+ await deleteApp ( appOne ) ;
382
+ expect ( ( appOne as FirebaseServerAppImpl ) . refCount ) . to . equal ( 1 ) ;
383
+ expect ( ( appTwo as FirebaseServerAppImpl ) . refCount ) . to . equal ( 1 ) ;
384
+ expect ( ( appOne as FirebaseServerAppImpl ) . isDeleted ) . to . be . false ;
385
+ expect ( ( appTwo as FirebaseServerAppImpl ) . isDeleted ) . to . be . false ;
386
+
387
+ await deleteApp ( appTwo ) ;
388
+ expect ( ( appOne as FirebaseServerAppImpl ) . refCount ) . to . equal ( 0 ) ;
389
+ expect ( ( appTwo as FirebaseServerAppImpl ) . refCount ) . to . equal ( 0 ) ;
328
390
expect ( ( appOne as FirebaseServerAppImpl ) . isDeleted ) . to . be . true ;
329
- // await deleteApp( appTwo) ;
391
+ expect ( ( appTwo as FirebaseServerAppImpl ) . isDeleted ) . to . be . true ;
330
392
} ) ;
331
393
332
394
describe ( 'getApp' , ( ) => {
0 commit comments