|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
17 | 17 |
|
| 18 | +import { FirebaseApp } from '@firebase/app-types-exp'; |
| 19 | +import * as externs from '@firebase/auth-types-exp'; |
| 20 | +import { FirebaseError } from '@firebase/util'; |
18 | 21 | import { expect, use } from 'chai';
|
19 | 22 | import * as chaiAsPromised from 'chai-as-promised';
|
20 | 23 | import * as sinon from 'sinon';
|
21 | 24 | import * as sinonChai from 'sinon-chai';
|
22 |
| - |
23 |
| -import { FirebaseApp } from '@firebase/app-types-exp'; |
24 |
| -import * as externs from '@firebase/auth-types-exp'; |
25 |
| -import { FirebaseError } from '@firebase/util'; |
26 |
| - |
27 | 25 | import { testUser } from '../../../test/helpers/mock_auth';
|
28 | 26 | import { User } from '../../model/user';
|
29 |
| -import { browserPopupRedirectResolver } from '../../platform_browser/popup_redirect'; |
30 |
| -import { AUTH_ERROR_FACTORY, AuthErrorCode } from '../errors'; |
| 27 | +import { browserLocalPersistence } from '../../platform_browser/persistence/browser'; |
31 | 28 | import { Persistence } from '../persistence';
|
32 |
| -import { |
33 |
| - browserLocalPersistence, |
34 |
| - browserSessionPersistence |
35 |
| -} from '../persistence/browser'; |
36 | 29 | import { inMemoryPersistence } from '../persistence/in_memory';
|
37 |
| -import { PersistenceUserManager } from '../persistence/persistence_user_manager'; |
38 |
| -import * as reload from '../user/reload'; |
39 | 30 | import { _getInstance } from '../util/instantiator';
|
40 | 31 | import * as navigator from '../util/navigator';
|
41 |
| -import { _getClientVersion, ClientPlatform } from '../util/version'; |
| 32 | +import { ClientPlatform } from '../util/version'; |
42 | 33 | import {
|
43 |
| - DEFAULT_API_HOST, |
44 |
| - DEFAULT_API_SCHEME, |
45 |
| - DEFAULT_TOKEN_API_HOST, |
46 | 34 | _castAuth,
|
47 | 35 | _initializeAuthForClientPlatform
|
48 | 36 | } from './auth_impl';
|
@@ -288,172 +276,3 @@ describe('core/auth/auth_impl', () => {
|
288 | 276 | });
|
289 | 277 | });
|
290 | 278 |
|
291 |
| -describe('core/auth/initializeAuth', () => { |
292 |
| - afterEach(sinon.restore); |
293 |
| - |
294 |
| - it('throws an API error if key not provided', () => { |
295 |
| - expect(() => |
296 |
| - initializeAuth({ |
297 |
| - ...FAKE_APP, |
298 |
| - options: {} // apiKey is missing |
299 |
| - }) |
300 |
| - ).to.throw( |
301 |
| - FirebaseError, |
302 |
| - 'Firebase: Your API key is invalid, please check you have copied it correctly. (auth/invalid-api-key).' |
303 |
| - ); |
304 |
| - }); |
305 |
| - |
306 |
| - describe('persistence manager creation', () => { |
307 |
| - let createManagerStub: sinon.SinonSpy; |
308 |
| - let reloadStub: sinon.SinonStub; |
309 |
| - |
310 |
| - beforeEach(() => { |
311 |
| - createManagerStub = sinon.spy(PersistenceUserManager, 'create'); |
312 |
| - reloadStub = sinon |
313 |
| - .stub(reload, '_reloadWithoutSaving') |
314 |
| - .returns(Promise.resolve()); |
315 |
| - }); |
316 |
| - |
317 |
| - async function initAndWait( |
318 |
| - persistence: externs.Persistence | externs.Persistence[], |
319 |
| - popupRedirectResolver?: externs.PopupRedirectResolver |
320 |
| - ): Promise<externs.Auth> { |
321 |
| - const auth = initializeAuth(FAKE_APP, { |
322 |
| - persistence, |
323 |
| - popupRedirectResolver |
324 |
| - }); |
325 |
| - // Auth initializes async. We can make sure the initialization is |
326 |
| - // flushed by awaiting a method on the queue. |
327 |
| - await auth.setPersistence(inMemoryPersistence); |
328 |
| - return auth; |
329 |
| - } |
330 |
| - |
331 |
| - it('converts single persistence to array', async () => { |
332 |
| - const auth = await initAndWait(inMemoryPersistence); |
333 |
| - expect(createManagerStub).to.have.been.calledWith(auth, [ |
334 |
| - _getInstance(inMemoryPersistence) |
335 |
| - ]); |
336 |
| - }); |
337 |
| - |
338 |
| - it('pulls the user from storage', async () => { |
339 |
| - sinon |
340 |
| - .stub(_getInstance<Persistence>(inMemoryPersistence), 'get') |
341 |
| - .returns(Promise.resolve(testUser({}, 'uid').toPlainObject())); |
342 |
| - const auth = await initAndWait(inMemoryPersistence); |
343 |
| - expect(auth.currentUser!.uid).to.eq('uid'); |
344 |
| - }); |
345 |
| - |
346 |
| - it('calls create with the persistence in order', async () => { |
347 |
| - const auth = await initAndWait([ |
348 |
| - inMemoryPersistence, |
349 |
| - browserLocalPersistence |
350 |
| - ]); |
351 |
| - expect(createManagerStub).to.have.been.calledWith(auth, [ |
352 |
| - _getInstance(inMemoryPersistence), |
353 |
| - _getInstance(browserLocalPersistence) |
354 |
| - ]); |
355 |
| - }); |
356 |
| - |
357 |
| - it('does not reload redirect users', async () => { |
358 |
| - const user = testUser({}, 'uid'); |
359 |
| - user._redirectEventId = 'event-id'; |
360 |
| - sinon |
361 |
| - .stub(_getInstance<Persistence>(inMemoryPersistence), 'get') |
362 |
| - .returns(Promise.resolve(user.toPlainObject())); |
363 |
| - sinon |
364 |
| - .stub(_getInstance<Persistence>(browserSessionPersistence), 'get') |
365 |
| - .returns(Promise.resolve(user.toPlainObject())); |
366 |
| - await initAndWait(inMemoryPersistence); |
367 |
| - expect(reload._reloadWithoutSaving).not.to.have.been.called; |
368 |
| - }); |
369 |
| - |
370 |
| - it('reloads non-redirect users', async () => { |
371 |
| - sinon |
372 |
| - .stub(_getInstance<Persistence>(inMemoryPersistence), 'get') |
373 |
| - .returns(Promise.resolve(testUser({}, 'uid').toPlainObject())); |
374 |
| - sinon |
375 |
| - .stub(_getInstance<Persistence>(browserSessionPersistence), 'get') |
376 |
| - .returns(Promise.resolve(null)); |
377 |
| - |
378 |
| - await initAndWait(inMemoryPersistence); |
379 |
| - expect(reload._reloadWithoutSaving).to.have.been.called; |
380 |
| - }); |
381 |
| - |
382 |
| - it('Does not reload if the event ids match', async () => { |
383 |
| - const user = testUser({}, 'uid'); |
384 |
| - user._redirectEventId = 'event-id'; |
385 |
| - |
386 |
| - sinon |
387 |
| - .stub(_getInstance<Persistence>(inMemoryPersistence), 'get') |
388 |
| - .returns(Promise.resolve(user.toPlainObject())); |
389 |
| - sinon |
390 |
| - .stub(_getInstance<Persistence>(browserSessionPersistence), 'get') |
391 |
| - .returns(Promise.resolve(user.toPlainObject())); |
392 |
| - |
393 |
| - await initAndWait(inMemoryPersistence, browserPopupRedirectResolver); |
394 |
| - expect(reload._reloadWithoutSaving).not.to.have.been.called; |
395 |
| - }); |
396 |
| - |
397 |
| - it('Reloads if the event ids do not match', async () => { |
398 |
| - const user = testUser({}, 'uid'); |
399 |
| - user._redirectEventId = 'event-id'; |
400 |
| - |
401 |
| - sinon |
402 |
| - .stub(_getInstance<Persistence>(inMemoryPersistence), 'get') |
403 |
| - .returns(Promise.resolve(user.toPlainObject())); |
404 |
| - |
405 |
| - user._redirectEventId = 'some-other-id'; |
406 |
| - sinon |
407 |
| - .stub(_getInstance<Persistence>(browserSessionPersistence), 'get') |
408 |
| - .returns(Promise.resolve(user.toPlainObject())); |
409 |
| - |
410 |
| - await initAndWait(inMemoryPersistence, browserPopupRedirectResolver); |
411 |
| - expect(reload._reloadWithoutSaving).to.have.been.called; |
412 |
| - }); |
413 |
| - |
414 |
| - it('Nulls out the current user if reload fails', async () => { |
415 |
| - const stub = sinon.stub(_getInstance<Persistence>(inMemoryPersistence)); |
416 |
| - stub.get.returns(Promise.resolve(testUser({}, 'uid').toPlainObject())); |
417 |
| - stub.remove.returns(Promise.resolve()); |
418 |
| - reloadStub.returns( |
419 |
| - Promise.reject( |
420 |
| - AUTH_ERROR_FACTORY.create(AuthErrorCode.TOKEN_EXPIRED, { |
421 |
| - appName: 'app' |
422 |
| - }) |
423 |
| - ) |
424 |
| - ); |
425 |
| - |
426 |
| - await initAndWait(inMemoryPersistence); |
427 |
| - expect(stub.remove).to.have.been.called; |
428 |
| - }); |
429 |
| - |
430 |
| - it('Keeps current user if reload fails with network error', async () => { |
431 |
| - const stub = sinon.stub(_getInstance<Persistence>(inMemoryPersistence)); |
432 |
| - stub.get.returns(Promise.resolve(testUser({}, 'uid').toPlainObject())); |
433 |
| - stub.remove.returns(Promise.resolve()); |
434 |
| - reloadStub.returns( |
435 |
| - Promise.reject( |
436 |
| - AUTH_ERROR_FACTORY.create(AuthErrorCode.NETWORK_REQUEST_FAILED, { |
437 |
| - appName: 'app' |
438 |
| - }) |
439 |
| - ) |
440 |
| - ); |
441 |
| - |
442 |
| - await initAndWait(inMemoryPersistence); |
443 |
| - expect(stub.remove).not.to.have.been.called; |
444 |
| - }); |
445 |
| - |
446 |
| - it('sets auth name and config', async () => { |
447 |
| - const auth = await initAndWait(inMemoryPersistence); |
448 |
| - expect(auth.name).to.eq(FAKE_APP.name); |
449 |
| - expect(auth.config).to.eql({ |
450 |
| - apiKey: FAKE_APP.options.apiKey, |
451 |
| - authDomain: FAKE_APP.options.authDomain, |
452 |
| - apiHost: DEFAULT_API_HOST, |
453 |
| - apiScheme: DEFAULT_API_SCHEME, |
454 |
| - tokenApiHost: DEFAULT_TOKEN_API_HOST, |
455 |
| - sdkClientVersion: _getClientVersion(ClientPlatform.BROWSER) |
456 |
| - }); |
457 |
| - }); |
458 |
| - }); |
459 |
| -}); |
0 commit comments