@@ -29,18 +29,22 @@ import { browserLocalPersistence } from '../persistence/browser';
29
29
import { inMemoryPersistence } from '../persistence/in_memory' ;
30
30
import { PersistenceUserManager } from '../persistence/persistence_user_manager' ;
31
31
import { ClientPlatform , getClientVersion } from '../util/version' ;
32
- import { DEFAULT_API_HOST , DEFAULT_API_SCHEME , initializeAuth } from './auth_impl' ;
32
+ import {
33
+ DEFAULT_API_HOST ,
34
+ DEFAULT_API_SCHEME ,
35
+ initializeAuth
36
+ } from './auth_impl' ;
33
37
34
38
use ( sinonChai ) ;
35
39
36
40
const FAKE_APP : FirebaseApp = {
37
41
name : 'test-app' ,
38
42
options : {
39
43
apiKey : 'api-key' ,
40
- authDomain : 'auth-domain' ,
44
+ authDomain : 'auth-domain'
41
45
} ,
42
46
automaticDataCollectionEnabled : false ,
43
- async delete ( ) { } ,
47
+ async delete ( ) { }
44
48
} ;
45
49
46
50
describe ( 'AuthImpl' , ( ) => {
@@ -49,7 +53,7 @@ describe('AuthImpl', () => {
49
53
50
54
beforeEach ( ( ) => {
51
55
persistenceStub = sinon . stub ( inMemoryPersistence ) ;
52
- auth = initializeAuth ( FAKE_APP , { persistence : inMemoryPersistence } ) ;
56
+ auth = initializeAuth ( FAKE_APP , { persistence : inMemoryPersistence } ) ;
53
57
} ) ;
54
58
55
59
afterEach ( sinon . restore ) ;
@@ -77,7 +81,7 @@ describe('AuthImpl', () => {
77
81
for ( let i = 0 ; i < 10 ; i ++ ) {
78
82
expect ( persistenceStub . set . getCall ( i ) ) . to . have . been . calledWith (
79
83
sinon . match . any ,
80
- users [ i ] . toPlainObject ( ) ,
84
+ users [ i ] . toPlainObject ( )
81
85
) ;
82
86
}
83
87
} ) ;
@@ -101,14 +105,16 @@ describe('AuthImpl', () => {
101
105
it ( 'swaps underlying persistence' , async ( ) => {
102
106
const newPersistence = browserLocalPersistence ;
103
107
const newStub = sinon . stub ( newPersistence ) ;
104
- persistenceStub . get . returns ( Promise . resolve ( testUser ( 'test' ) . toPlainObject ( ) ) ) ;
108
+ persistenceStub . get . returns (
109
+ Promise . resolve ( testUser ( 'test' ) . toPlainObject ( ) )
110
+ ) ;
105
111
106
112
await auth . setPersistence ( newPersistence ) ;
107
113
expect ( persistenceStub . get ) . to . have . been . called ;
108
114
expect ( persistenceStub . remove ) . to . have . been . called ;
109
115
expect ( newStub . set ) . to . have . been . calledWith (
110
116
sinon . match . any ,
111
- testUser ( 'test' ) . toPlainObject ( ) ,
117
+ testUser ( 'test' ) . toPlainObject ( )
112
118
) ;
113
119
} ) ;
114
120
} ) ;
@@ -118,10 +124,15 @@ describe('initializeAuth', () => {
118
124
afterEach ( sinon . restore ) ;
119
125
120
126
it ( 'throws an API error if key not provided' , ( ) => {
121
- expect ( ( ) => initializeAuth ( {
122
- ...FAKE_APP ,
123
- options : { } , // apiKey is missing
124
- } ) ) . to . throw ( FirebaseError , 'Firebase: Your API key is invalid]: please check you have copied it correctly. (auth/invalid-api-key).' ) ;
127
+ expect ( ( ) =>
128
+ initializeAuth ( {
129
+ ...FAKE_APP ,
130
+ options : { } // apiKey is missing
131
+ } )
132
+ ) . to . throw (
133
+ FirebaseError ,
134
+ 'Firebase: Your API key is invalid]: please check you have copied it correctly. (auth/invalid-api-key).'
135
+ ) ;
125
136
} ) ;
126
137
127
138
describe ( 'persistence manager creation' , ( ) => {
@@ -130,8 +141,10 @@ describe('initializeAuth', () => {
130
141
createManagerStub = sinon . spy ( PersistenceUserManager , 'create' ) ;
131
142
} ) ;
132
143
133
- async function initAndWait ( persistence : Persistence | Persistence [ ] ) : Promise < Auth > {
134
- const auth = initializeAuth ( FAKE_APP , { persistence} ) ;
144
+ async function initAndWait (
145
+ persistence : Persistence | Persistence [ ]
146
+ ) : Promise < Auth > {
147
+ const auth = initializeAuth ( FAKE_APP , { persistence } ) ;
135
148
// Auth initializes async. We can make sure the initialization is
136
149
// flushed by awaiting a method on the queue.
137
150
await auth . setPersistence ( inMemoryPersistence ) ;
@@ -140,20 +153,28 @@ describe('initializeAuth', () => {
140
153
141
154
it ( 'converts single persistence to array' , async ( ) => {
142
155
const auth = await initAndWait ( inMemoryPersistence ) ;
143
- expect ( createManagerStub ) . to . have . been . calledWith ( auth , [ inMemoryPersistence ] ) ;
156
+ expect ( createManagerStub ) . to . have . been . calledWith ( auth , [
157
+ inMemoryPersistence
158
+ ] ) ;
144
159
} ) ;
145
160
146
161
it ( 'pulls the user from storage' , async ( ) => {
147
- sinon . stub ( inMemoryPersistence , 'get' ) . returns (
148
- Promise . resolve ( testUser ( 'uid' ) . toPlainObject ( ) )
149
- ) ;
162
+ sinon
163
+ . stub ( inMemoryPersistence , 'get' )
164
+ . returns ( Promise . resolve ( testUser ( 'uid' ) . toPlainObject ( ) ) ) ;
150
165
const auth = await initAndWait ( inMemoryPersistence ) ;
151
166
expect ( auth . currentUser ! . uid ) . to . eq ( 'uid' ) ;
152
167
} ) ;
153
168
154
169
it ( 'calls create with the persistence in order' , async ( ) => {
155
- const auth = await initAndWait ( [ inMemoryPersistence , browserLocalPersistence ] ) ;
156
- expect ( createManagerStub ) . to . have . been . calledWith ( auth , [ inMemoryPersistence , browserLocalPersistence ] ) ;
170
+ const auth = await initAndWait ( [
171
+ inMemoryPersistence ,
172
+ browserLocalPersistence
173
+ ] ) ;
174
+ expect ( createManagerStub ) . to . have . been . calledWith ( auth , [
175
+ inMemoryPersistence ,
176
+ browserLocalPersistence
177
+ ] ) ;
157
178
} ) ;
158
179
159
180
it ( 'sets auth name and config' , async ( ) => {
@@ -164,8 +185,8 @@ describe('initializeAuth', () => {
164
185
authDomain : FAKE_APP . options . authDomain ,
165
186
apiHost : DEFAULT_API_HOST ,
166
187
apiScheme : DEFAULT_API_SCHEME ,
167
- sdkClientVersion : getClientVersion ( ClientPlatform . BROWSER ) ,
188
+ sdkClientVersion : getClientVersion ( ClientPlatform . BROWSER )
168
189
} ) ;
169
190
} ) ;
170
191
} ) ;
171
- } ) ;
192
+ } ) ;
0 commit comments