|
15 | 15 | * limitations under the License.
|
16 | 16 | */
|
17 | 17 |
|
| 18 | +import { |
| 19 | + OperationType, |
| 20 | + ProviderId, |
| 21 | + SignInMethod |
| 22 | +} from '@firebase/auth-types-exp'; |
| 23 | +import { FirebaseError } from '@firebase/util'; |
18 | 24 | import { expect, use } from 'chai';
|
19 | 25 | import * as chaiAsPromised from 'chai-as-promised';
|
20 | 26 | import * as sinonChai from 'sinon-chai';
|
21 |
| - |
22 |
| -import { FirebaseError } from '@firebase/util'; |
23 |
| - |
24 | 27 | import { mockEndpoint } from '../../../test/api/helper';
|
25 | 28 | import { testAuth } from '../../../test/mock_auth';
|
26 | 29 | import * as mockFetch from '../../../test/mock_fetch';
|
27 | 30 | import { Endpoint } from '../../api';
|
| 31 | +import { APIUserInfo } from '../../api/account_management/account'; |
28 | 32 | import { ServerError } from '../../api/errors';
|
29 | 33 | import { Operation } from '../../model/action_code_info';
|
30 | 34 | import { Auth } from '../../model/auth';
|
31 | 35 | import {
|
32 | 36 | checkActionCode,
|
33 | 37 | confirmPasswordReset,
|
| 38 | + createUserWithEmailAndPassword, |
34 | 39 | sendPasswordResetEmail,
|
35 |
| - verifyPasswordResetCode, |
36 |
| - signInWithEmailAndPassword |
| 40 | + signInWithEmailAndPassword, |
| 41 | + verifyPasswordResetCode |
37 | 42 | } from './email_and_password';
|
38 |
| -import { APIUserInfo } from '../../api/account_management/account'; |
39 |
| -import { |
40 |
| - SignInMethod, |
41 |
| - OperationType, |
42 |
| - ProviderId |
43 |
| -} from '@firebase/auth-types-exp'; |
44 | 43 |
|
45 | 44 | use(chaiAsPromised);
|
46 | 45 | use(sinonChai);
|
@@ -324,6 +323,45 @@ describe('core/strategies/verifyPasswordResetCode', () => {
|
324 | 323 | });
|
325 | 324 | });
|
326 | 325 |
|
| 326 | +describe('core/strategies/email_and_password/createUserWithEmailAndPassword', () => { |
| 327 | + let auth: Auth; |
| 328 | + const serverUser: APIUserInfo = { |
| 329 | + localId: 'local-id' |
| 330 | + }; |
| 331 | + |
| 332 | + beforeEach(async () => { |
| 333 | + auth = await testAuth(); |
| 334 | + mockFetch.setUp(); |
| 335 | + mockEndpoint(Endpoint.SIGN_UP, { |
| 336 | + idToken: 'id-token', |
| 337 | + refreshToken: 'refresh-token', |
| 338 | + expiresIn: '1234', |
| 339 | + localId: serverUser.localId! |
| 340 | + }); |
| 341 | + mockEndpoint(Endpoint.GET_ACCOUNT_INFO, { |
| 342 | + users: [serverUser] |
| 343 | + }); |
| 344 | + }); |
| 345 | + afterEach(mockFetch.tearDown); |
| 346 | + |
| 347 | + it('should sign in the user', async () => { |
| 348 | + const { |
| 349 | + credential, |
| 350 | + user, |
| 351 | + operationType |
| 352 | + } = await createUserWithEmailAndPassword( |
| 353 | + auth, |
| 354 | + 'some-email', |
| 355 | + 'some-password' |
| 356 | + ); |
| 357 | + expect(credential!.providerId).to.eq(ProviderId.PASSWORD); |
| 358 | + expect(credential!.signInMethod).to.eq(SignInMethod.EMAIL_PASSWORD); |
| 359 | + expect(operationType).to.eq(OperationType.SIGN_IN); |
| 360 | + expect(user.uid).to.eq(serverUser.localId); |
| 361 | + expect(user.isAnonymous).to.be.false; |
| 362 | + }); |
| 363 | +}); |
| 364 | + |
327 | 365 | describe('core/strategies/email_and_password/signInWithEmailAndPassword', () => {
|
328 | 366 | let auth: Auth;
|
329 | 367 | const serverUser: APIUserInfo = {
|
@@ -351,8 +389,8 @@ describe('core/strategies/email_and_password/signInWithEmailAndPassword', () =>
|
351 | 389 | user,
|
352 | 390 | operationType
|
353 | 391 | } = await signInWithEmailAndPassword(auth, 'some-email', 'some-password');
|
354 |
| - expect(credential?.providerId).to.eq(ProviderId.PASSWORD); |
355 |
| - expect(credential?.signInMethod).to.eq(SignInMethod.EMAIL_PASSWORD); |
| 392 | + expect(credential!.providerId).to.eq(ProviderId.PASSWORD); |
| 393 | + expect(credential!.signInMethod).to.eq(SignInMethod.EMAIL_PASSWORD); |
356 | 394 | expect(operationType).to.eq(OperationType.SIGN_IN);
|
357 | 395 | expect(user.uid).to.eq(serverUser.localId);
|
358 | 396 | expect(user.isAnonymous).to.be.false;
|
|
0 commit comments