|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
17 | 17 |
|
18 |
| -import { OperationType, ProviderId, SignInMethod } from '@firebase/auth-types-exp'; |
| 18 | +import { |
| 19 | + OperationType, |
| 20 | + ProviderId, |
| 21 | + SignInMethod |
| 22 | +} from '@firebase/auth-types-exp'; |
19 | 23 | import { expect } from 'chai';
|
20 | 24 | import { mockEndpoint } from '../../../test/api/helper';
|
21 |
| -import { mockAuth } from '../../../test/mock_auth'; |
| 25 | +import { mockAuth, testUser } from '../../../test/mock_auth'; |
22 | 26 | import * as mockFetch from '../../../test/mock_fetch';
|
23 | 27 | import { Endpoint } from '../../api';
|
24 | 28 | import { APIUserInfo } from '../../api/account_management/account';
|
@@ -55,8 +59,37 @@ describe('core/strategies/anonymous', () => {
|
55 | 59 | expect(user.isAnonymous).to.be.true;
|
56 | 60 | });
|
57 | 61 |
|
58 |
| - context('already signed in anonymousl', () => {}); |
| 62 | + context('already signed in anonymously', () => { |
| 63 | + it('should return the current user', async () => { |
| 64 | + const userCredential = await signInAnonymously(mockAuth); |
| 65 | + expect(userCredential.user.isAnonymous).to.be.true; |
59 | 66 |
|
60 |
| - context('already signed in with a non-anonymous account', () => {}); |
| 67 | + const { credential, user, operationType } = await signInAnonymously( |
| 68 | + mockAuth |
| 69 | + ); |
| 70 | + expect(credential?.providerId).to.eq(ProviderId.ANONYMOUS); |
| 71 | + expect(credential?.signInMethod).to.eq(SignInMethod.ANONYMOUS); |
| 72 | + expect(operationType).to.eq(OperationType.SIGN_IN); |
| 73 | + expect(user.uid).to.eq(userCredential.user.uid); |
| 74 | + expect(user.isAnonymous).to.be.true; |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + context('already signed in with a non-anonymous account', () => { |
| 79 | + it('should sign in as a new user user', async () => { |
| 80 | + const fakeUser = testUser('other-uid'); |
| 81 | + await mockAuth.updateCurrentUser(fakeUser); |
| 82 | + expect(fakeUser.isAnonymous).to.be.false; |
| 83 | + |
| 84 | + const { credential, user, operationType } = await signInAnonymously( |
| 85 | + mockAuth |
| 86 | + ); |
| 87 | + expect(credential?.providerId).to.eq(ProviderId.ANONYMOUS); |
| 88 | + expect(credential?.signInMethod).to.eq(SignInMethod.ANONYMOUS); |
| 89 | + expect(operationType).to.eq(OperationType.SIGN_IN); |
| 90 | + expect(user.uid).to.not.eq(fakeUser.uid); |
| 91 | + expect(user.isAnonymous).to.be.true; |
| 92 | + }); |
| 93 | + }); |
61 | 94 | });
|
62 | 95 | });
|
0 commit comments