2222
2323import { expect } from 'chai' ;
2424import { apps as appsNamespace } from '../src/apps' ;
25+
2526import * as firebase from 'firebase-admin' ;
2627import * as _ from 'lodash' ;
2728import * as sinon from 'sinon' ;
2829
2930describe ( 'apps' , ( ) => {
3031 let apps : appsNamespace . Apps ;
3132 let claims ;
33+
3234 beforeEach ( ( ) => {
3335 apps = new appsNamespace . Apps ( ) ;
3436 // mock claims intentionally contains dots, square brackets, and nested paths
@@ -52,37 +54,37 @@ describe('apps', () => {
5254 clock . restore ( ) ;
5355 } ) ;
5456
55- it ( 'should retain/release ref counters appropriately' , function ( ) {
57+ it ( 'should retain/release ref counters appropriately' , ( ) => {
5658 apps . retain ( ) ;
57- expect ( apps [ '_refCounter' ] ) . to . deep . equal ( {
59+ expect ( _ . get ( apps , '_refCounter' ) ) . to . deep . equal ( {
5860 __admin__ : 1 ,
5961 } ) ;
6062 apps . release ( ) ;
6163 clock . tick ( appsNamespace . garbageCollectionInterval ) ;
6264 return Promise . resolve ( ) . then ( ( ) => {
63- expect ( apps [ '_refCounter' ] ) . to . deep . equal ( {
65+ expect ( _ . get ( apps , '_refCounter' ) ) . to . deep . equal ( {
6466 __admin__ : 0 ,
6567 } ) ;
6668 } ) ;
6769 } ) ;
6870
69- it ( 'should only decrement counter after garbageCollectionInterval is up' , function ( ) {
71+ it ( 'should only decrement counter after garbageCollectionInterval is up' , ( ) => {
7072 apps . retain ( ) ;
7173 apps . release ( ) ;
7274 clock . tick ( appsNamespace . garbageCollectionInterval / 2 ) ;
73- expect ( apps [ '_refCounter' ] ) . to . deep . equal ( {
75+ expect ( _ . get ( apps , '_refCounter' ) ) . to . deep . equal ( {
7476 __admin__ : 1 ,
7577 } ) ;
7678 clock . tick ( appsNamespace . garbageCollectionInterval / 2 ) ;
7779 return Promise . resolve ( ) . then ( ( ) => {
78- expect ( apps [ '_refCounter' ] ) . to . deep . equal ( {
80+ expect ( _ . get ( apps , '_refCounter' ) ) . to . deep . equal ( {
7981 __admin__ : 0 ,
8082 } ) ;
8183 } ) ;
8284 } ) ;
8385
84- it ( 'should call _destroyApp if app no longer used' , function ( ) {
85- let spy = sinon . spy ( apps , '_destroyApp' ) ;
86+ it ( 'should call _destroyApp if app no longer used' , ( ) => {
87+ const spy = sinon . spy ( apps , '_destroyApp' ) ;
8688 apps . retain ( ) ;
8789 apps . release ( ) ;
8890 clock . tick ( appsNamespace . garbageCollectionInterval ) ;
@@ -91,8 +93,8 @@ describe('apps', () => {
9193 } ) ;
9294 } ) ;
9395
94- it ( 'should not call _destroyApp if app used again while waiting for release' , function ( ) {
95- let spy = sinon . spy ( apps , '_destroyApp' ) ;
96+ it ( 'should not call _destroyApp if app used again while waiting for release' , ( ) => {
97+ const spy = sinon . spy ( apps , '_destroyApp' ) ;
9698 apps . retain ( ) ;
9799 apps . release ( ) ;
98100 clock . tick ( appsNamespace . garbageCollectionInterval / 2 ) ;
@@ -103,22 +105,22 @@ describe('apps', () => {
103105 } ) ;
104106 } ) ;
105107
106- it ( 'should increment ref counter for each subsequent retain' , function ( ) {
108+ it ( 'should increment ref counter for each subsequent retain' , ( ) => {
107109 apps . retain ( ) ;
108- expect ( apps [ '_refCounter' ] ) . to . deep . equal ( {
110+ expect ( _ . get ( apps , '_refCounter' ) ) . to . deep . equal ( {
109111 __admin__ : 1 ,
110112 } ) ;
111113 apps . retain ( ) ;
112- expect ( apps [ '_refCounter' ] ) . to . deep . equal ( {
114+ expect ( _ . get ( apps , '_refCounter' ) ) . to . deep . equal ( {
113115 __admin__ : 2 ,
114116 } ) ;
115117 apps . retain ( ) ;
116- expect ( apps [ '_refCounter' ] ) . to . deep . equal ( {
118+ expect ( _ . get ( apps , '_refCounter' ) ) . to . deep . equal ( {
117119 __admin__ : 3 ,
118120 } ) ;
119121 } ) ;
120122
121- it ( 'should work with staggering sets of retain/release' , function ( ) {
123+ it ( 'should work with staggering sets of retain/release' , ( ) => {
122124 apps . retain ( ) ;
123125 apps . release ( ) ;
124126 clock . tick ( appsNamespace . garbageCollectionInterval / 2 ) ;
@@ -128,14 +130,14 @@ describe('apps', () => {
128130 return Promise . resolve ( )
129131 . then ( ( ) => {
130132 // Counters are still 1 due second set of retain/release
131- expect ( apps [ '_refCounter' ] ) . to . deep . equal ( {
133+ expect ( _ . get ( apps , '_refCounter' ) ) . to . deep . equal ( {
132134 __admin__ : 1 ,
133135 } ) ;
134136 clock . tick ( appsNamespace . garbageCollectionInterval / 2 ) ;
135137 } )
136138 . then ( ( ) => {
137139 // It's now been a full interval since the second set of retain/release
138- expect ( apps [ '_refCounter' ] ) . to . deep . equal ( {
140+ expect ( _ . get ( apps , '_refCounter' ) ) . to . deep . equal ( {
139141 __admin__ : 0 ,
140142 } ) ;
141143 } ) ;
0 commit comments