16
16
*/
17
17
18
18
import { FirebaseApp } from '@firebase/app-types-exp' ;
19
- import * as externs from '@firebase/auth-types-exp' ;
20
19
import { FirebaseError } from '@firebase/util' ;
21
20
import { expect , use } from 'chai' ;
22
21
import * as chaiAsPromised from 'chai-as-promised' ;
@@ -30,6 +29,7 @@ import { _getInstance } from '../util/instantiator';
30
29
import * as navigator from '../util/navigator' ;
31
30
import { ClientPlatform } from '../util/version' ;
32
31
import { _castAuth , _initializeAuthForClientPlatform } from './auth_impl' ;
32
+ import { Auth } from '../../model/auth' ;
33
33
34
34
use ( sinonChai ) ;
35
35
use ( chaiAsPromised ) ;
@@ -46,14 +46,16 @@ const FAKE_APP: FirebaseApp = {
46
46
const initializeAuth = _initializeAuthForClientPlatform ( ClientPlatform . BROWSER ) ;
47
47
48
48
describe ( 'core/auth/auth_impl' , ( ) => {
49
- let auth : externs . Auth ;
49
+ let auth : Auth ;
50
50
let persistenceStub : sinon . SinonStubbedInstance < Persistence > ;
51
51
52
52
beforeEach ( ( ) => {
53
53
persistenceStub = sinon . stub ( _getInstance ( inMemoryPersistence ) ) ;
54
- auth = initializeAuth ( FAKE_APP , {
55
- persistence : inMemoryPersistence
56
- } ) ;
54
+ auth = _castAuth (
55
+ initializeAuth ( FAKE_APP , {
56
+ persistence : inMemoryPersistence
57
+ } )
58
+ ) ;
57
59
} ) ;
58
60
59
61
afterEach ( sinon . restore ) ;
@@ -81,7 +83,7 @@ describe('core/auth/auth_impl', () => {
81
83
for ( let i = 0 ; i < 10 ; i ++ ) {
82
84
expect ( persistenceStub . set . getCall ( i ) ) . to . have . been . calledWith (
83
85
sinon . match . any ,
84
- users [ i ] . toPlainObject ( )
86
+ users [ i ] . toJSON ( )
85
87
) ;
86
88
}
87
89
} ) ;
@@ -126,28 +128,28 @@ describe('core/auth/auth_impl', () => {
126
128
127
129
it ( 'immediately calls authStateChange if initialization finished' , done => {
128
130
const user = testUser ( auth , 'uid' ) ;
129
- _castAuth ( auth ) . currentUser = user ;
130
- _castAuth ( auth ) . _isInitialized = true ;
131
- auth . onAuthStateChanged ( user => {
131
+ auth . currentUser = user ;
132
+ auth . _isInitialized = true ;
133
+ auth . _onAuthStateChanged ( user => {
132
134
expect ( user ) . to . eq ( user ) ;
133
135
done ( ) ;
134
136
} ) ;
135
137
} ) ;
136
138
137
139
it ( 'immediately calls idTokenChange if initialization finished' , done => {
138
140
const user = testUser ( auth , 'uid' ) ;
139
- _castAuth ( auth ) . currentUser = user ;
140
- _castAuth ( auth ) . _isInitialized = true ;
141
- auth . onIdTokenChanged ( user => {
141
+ auth . currentUser = user ;
142
+ auth . _isInitialized = true ;
143
+ auth . _onIdTokenChanged ( user => {
142
144
expect ( user ) . to . eq ( user ) ;
143
145
done ( ) ;
144
146
} ) ;
145
147
} ) ;
146
148
147
149
it ( 'immediate callback is done async' , ( ) => {
148
- _castAuth ( auth ) . _isInitialized = true ;
150
+ auth . _isInitialized = true ;
149
151
let callbackCalled = false ;
150
- auth . onIdTokenChanged ( ( ) => {
152
+ auth . _onIdTokenChanged ( ( ) => {
151
153
callbackCalled = true ;
152
154
} ) ;
153
155
@@ -167,8 +169,8 @@ describe('core/auth/auth_impl', () => {
167
169
168
170
context ( 'initially currentUser is null' , ( ) => {
169
171
beforeEach ( async ( ) => {
170
- auth . onAuthStateChanged ( authStateCallback ) ;
171
- auth . onIdTokenChanged ( idTokenCallback ) ;
172
+ auth . _onAuthStateChanged ( authStateCallback ) ;
173
+ auth . _onIdTokenChanged ( idTokenCallback ) ;
172
174
await auth . updateCurrentUser ( null ) ;
173
175
authStateCallback . resetHistory ( ) ;
174
176
idTokenCallback . resetHistory ( ) ;
@@ -187,8 +189,8 @@ describe('core/auth/auth_impl', () => {
187
189
188
190
context ( 'initially currentUser is user' , ( ) => {
189
191
beforeEach ( async ( ) => {
190
- auth . onAuthStateChanged ( authStateCallback ) ;
191
- auth . onIdTokenChanged ( idTokenCallback ) ;
192
+ auth . _onAuthStateChanged ( authStateCallback ) ;
193
+ auth . _onIdTokenChanged ( idTokenCallback ) ;
192
194
await auth . updateCurrentUser ( user ) ;
193
195
authStateCallback . resetHistory ( ) ;
194
196
idTokenCallback . resetHistory ( ) ;
@@ -226,8 +228,8 @@ describe('core/auth/auth_impl', () => {
226
228
it ( 'onAuthStateChange works for multiple listeners' , async ( ) => {
227
229
const cb1 = sinon . spy ( ) ;
228
230
const cb2 = sinon . spy ( ) ;
229
- auth . onAuthStateChanged ( cb1 ) ;
230
- auth . onAuthStateChanged ( cb2 ) ;
231
+ auth . _onAuthStateChanged ( cb1 ) ;
232
+ auth . _onAuthStateChanged ( cb2 ) ;
231
233
await auth . updateCurrentUser ( null ) ;
232
234
cb1 . resetHistory ( ) ;
233
235
cb2 . resetHistory ( ) ;
@@ -240,8 +242,8 @@ describe('core/auth/auth_impl', () => {
240
242
it ( 'onIdTokenChange works for multiple listeners' , async ( ) => {
241
243
const cb1 = sinon . spy ( ) ;
242
244
const cb2 = sinon . spy ( ) ;
243
- auth . onIdTokenChanged ( cb1 ) ;
244
- auth . onIdTokenChanged ( cb2 ) ;
245
+ auth . _onIdTokenChanged ( cb1 ) ;
246
+ auth . _onIdTokenChanged ( cb2 ) ;
245
247
await auth . updateCurrentUser ( null ) ;
246
248
cb1 . resetHistory ( ) ;
247
249
cb2 . resetHistory ( ) ;
0 commit comments