1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
1
18
import { expect , use } from 'chai' ;
2
19
import * as chaiAsPromised from 'chai-as-promised' ;
3
20
4
21
import {
5
- createUserWithEmailAndPassword , EmailAuthProvider , linkWithCredential , signInAnonymously ,
6
- signInWithEmailAndPassword , updateEmail , updatePassword
22
+ createUserWithEmailAndPassword ,
23
+ EmailAuthProvider ,
24
+ linkWithCredential ,
25
+ signInAnonymously ,
26
+ signInWithEmailAndPassword ,
27
+ updateEmail ,
28
+ updatePassword
7
29
} from '@firebase/auth-exp/index.browser' ;
8
30
import { OperationType } from '@firebase/auth-types-exp' ;
9
31
import { FirebaseError } from '@firebase/util' ;
10
32
11
- import { initIntegrationTestContext , randomEmail } from '../../helpers/integration/helpers' ;
33
+ import {
34
+ initIntegrationTestContext ,
35
+ randomEmail
36
+ } from '../../helpers/integration/helpers' ;
12
37
13
38
use ( chaiAsPromised ) ;
14
39
15
40
describe ( 'Integration test: anonymous auth' , ( ) => {
16
41
const auth = initIntegrationTestContext ( ) ;
17
-
42
+
18
43
it ( 'signs in anonymously' , async ( ) => {
19
44
const userCred = await signInAnonymously ( auth ) ;
20
45
expect ( auth . currentUser ) . to . eq ( userCred . user ) ;
@@ -26,8 +51,8 @@ describe('Integration test: anonymous auth', () => {
26
51
} ) ;
27
52
28
53
it ( 'second sign in on the same device yields same user' , async ( ) => {
29
- const { user : userA } = await signInAnonymously ( auth ) ;
30
- const { user : userB } = await signInAnonymously ( auth ) ;
54
+ const { user : userA } = await signInAnonymously ( auth ) ;
55
+ const { user : userB } = await signInAnonymously ( auth ) ;
31
56
32
57
expect ( userA . uid ) . to . eq ( userB . uid ) ;
33
58
} ) ;
@@ -41,41 +66,56 @@ describe('Integration test: anonymous auth', () => {
41
66
42
67
it ( 'anonymous / email-password accounts remain independent' , async ( ) => {
43
68
let anonCred = await signInAnonymously ( auth ) ;
44
- const emailCred = await createUserWithEmailAndPassword ( auth , email , 'password' ) ;
69
+ const emailCred = await createUserWithEmailAndPassword (
70
+ auth ,
71
+ email ,
72
+ 'password'
73
+ ) ;
45
74
expect ( emailCred . user . uid ) . not . to . eql ( anonCred . user . uid ) ;
46
-
75
+
47
76
await auth . signOut ( ) ;
48
- anonCred = await signInAnonymously ( auth ) ;
49
- const emailSignIn = await signInWithEmailAndPassword ( auth , email , 'password' ) ;
77
+ anonCred = await signInAnonymously ( auth ) ;
78
+ const emailSignIn = await signInWithEmailAndPassword (
79
+ auth ,
80
+ email ,
81
+ 'password'
82
+ ) ;
50
83
expect ( emailCred . user . uid ) . to . eql ( emailSignIn . user . uid ) ;
51
84
expect ( emailSignIn . user . uid ) . not . to . eql ( anonCred . user . uid ) ;
52
85
} ) ;
53
-
86
+
54
87
it ( 'account can be upgraded by setting email and password' , async ( ) => {
55
- const { user} = await signInAnonymously ( auth ) ;
88
+ const { user } = await signInAnonymously ( auth ) ;
56
89
await updateEmail ( user , email ) ;
57
90
await updatePassword ( user , 'password' ) ;
58
-
91
+
59
92
const anonId = user . uid ;
60
93
await auth . signOut ( ) ;
61
- expect ( ( await signInWithEmailAndPassword ( auth , email , 'password' ) ) . user . uid ) . to . eq ( anonId ) ;
94
+ expect (
95
+ ( await signInWithEmailAndPassword ( auth , email , 'password' ) ) . user . uid
96
+ ) . to . eq ( anonId ) ;
62
97
} ) ;
63
-
98
+
64
99
it ( 'account can be linked using email and password' , async ( ) => {
65
- const { user} = await signInAnonymously ( auth ) ;
100
+ const { user } = await signInAnonymously ( auth ) ;
66
101
const cred = EmailAuthProvider . credential ( email , 'password' ) ;
67
102
const id = user . uid ;
68
103
await linkWithCredential ( user , cred ) ;
69
104
await auth . signOut ( ) ;
70
105
71
- expect ( ( await signInWithEmailAndPassword ( auth , email , 'password' ) ) . user . uid ) . to . eq ( id ) ;
106
+ expect (
107
+ ( await signInWithEmailAndPassword ( auth , email , 'password' ) ) . user . uid
108
+ ) . to . eq ( id ) ;
72
109
} ) ;
73
110
74
111
it ( 'account cannot be linked with existing email/password' , async ( ) => {
75
112
await createUserWithEmailAndPassword ( auth , email , 'password' ) ;
76
- const { user : anonUser } = await signInAnonymously ( auth ) ;
113
+ const { user : anonUser } = await signInAnonymously ( auth ) ;
77
114
const cred = EmailAuthProvider . credential ( email , 'password' ) ;
78
- await expect ( linkWithCredential ( anonUser , cred ) ) . to . be . rejectedWith ( FirebaseError , 'auth/email-already-in-use' ) ;
115
+ await expect ( linkWithCredential ( anonUser , cred ) ) . to . be . rejectedWith (
116
+ FirebaseError ,
117
+ 'auth/email-already-in-use'
118
+ ) ;
79
119
} ) ;
80
120
} ) ;
81
- } ) ;
121
+ } ) ;
0 commit comments