@@ -9,7 +9,10 @@ import {
9
9
fuiSignInAnonymously ,
10
10
fuiSendPasswordResetEmail ,
11
11
fuiSignInWithOAuth ,
12
+ fuiCompleteEmailLinkSignIn ,
13
+ fuiConfirmPhoneNumber ,
12
14
} from '../../src/auth' ;
15
+ import { FirebaseUIError } from '../../src/errors' ;
13
16
14
17
describe ( 'Firebase UI Auth Integration' , ( ) => {
15
18
let auth : Auth ;
@@ -101,24 +104,29 @@ describe('Firebase UI Auth Integration', () => {
101
104
} ) ;
102
105
103
106
describe ( 'Email Link Authentication' , ( ) => {
104
- it ( 'should initiate email link sign in' , async ( ) => {
107
+ it ( 'should manage email storage for email link sign in' , async ( ) => {
105
108
const email = getUniqueEmail ( ) ;
106
- await expect ( fuiSendSignInLinkToEmail ( auth , email ) ) . resolves . not . toThrow ( ) ;
107
109
110
+ // Should store email
111
+ await fuiSendSignInLinkToEmail ( auth , email ) ;
108
112
expect ( window . localStorage . getItem ( 'emailForSignIn' ) ) . toBe ( email ) ;
109
- } ) ;
110
113
111
- // Note: Full email link sign-in flow can't be tested in integration tests
112
- // as it requires clicking the email link
113
- } ) ;
114
+ // Should store anonymous upgrade flag - first sign in anonymously
115
+ await fuiSignInAnonymously ( auth ) ;
116
+ await fuiSendSignInLinkToEmail ( auth , email , { enableAutoUpgradeAnonymous : true } ) ;
117
+ expect ( window . localStorage . getItem ( 'emailLinkAnonymousUpgrade' ) ) . toBe ( 'true' ) ;
114
118
115
- describe ( 'OAuth Authentication' , ( ) => {
116
- it . skip ( 'should initiate OAuth sign in (skipped - requires user interaction)' , async ( ) => {
117
- const provider = new GoogleAuthProvider ( ) ;
118
- await fuiSignInWithOAuth ( auth , provider ) ;
119
+ // Should clean up storage after sign in attempt
120
+ window . localStorage . setItem ( 'emailForSignIn' , email ) ;
121
+ window . localStorage . setItem ( 'emailLinkAnonymousUpgrade' , 'true' ) ;
122
+ await fuiSendSignInLinkToEmail ( auth , email ) ;
123
+ expect ( window . localStorage . getItem ( 'emailForSignIn' ) ) . toBe ( email ) ;
124
+ expect ( window . localStorage . getItem ( 'emailLinkAnonymousUpgrade' ) ) . toBe ( null ) ;
119
125
} ) ;
126
+ } ) ;
120
127
121
- it . skip ( 'should handle OAuth for anonymous upgrade (skipped - requires user interaction)' , async ( ) => {
128
+ describe ( 'OAuth Authentication' , ( ) => {
129
+ it . skip ( 'should handle enableAutoUpgradeAnonymous flag for OAuth (skipped - requires user interaction)' , async ( ) => {
122
130
await fuiSignInAnonymously ( auth ) ;
123
131
const provider = new GoogleAuthProvider ( ) ;
124
132
await fuiSignInWithOAuth ( auth , provider , { enableAutoUpgradeAnonymous : true } ) ;
@@ -128,7 +136,6 @@ describe('Firebase UI Auth Integration', () => {
128
136
describe ( 'Error Handling' , ( ) => {
129
137
it ( 'should handle duplicate email registration' , async ( ) => {
130
138
const email = getUniqueEmail ( ) ;
131
-
132
139
await fuiCreateUserWithEmailAndPassword ( auth , email , testPassword ) ;
133
140
await signOut ( auth ) ;
134
141
@@ -140,8 +147,6 @@ describe('Firebase UI Auth Integration', () => {
140
147
await expect ( fuiSignInWithEmailAndPassword ( auth , email , 'password' ) ) . rejects . toThrow ( ) ;
141
148
} ) ;
142
149
143
- // Note: Firebase Auth has lenient email validation.
144
- // We test only definitely invalid email formats here.
145
150
it ( 'should handle invalid email formats' , async ( ) => {
146
151
const invalidEmails = [
147
152
'invalid' , // No @ symbol
@@ -155,15 +160,6 @@ describe('Firebase UI Auth Integration', () => {
155
160
}
156
161
} ) ;
157
162
158
- it ( 'should handle password requirements' , async ( ) => {
159
- const email = getUniqueEmail ( ) ;
160
- const weakPasswords = [ '' , '123' , 'short' ] ;
161
-
162
- for ( const password of weakPasswords ) {
163
- await expect ( fuiCreateUserWithEmailAndPassword ( auth , email , password ) ) . rejects . toThrow ( ) ;
164
- }
165
- } ) ;
166
-
167
163
it ( 'should handle multiple anonymous account upgrades' , async ( ) => {
168
164
const email = getUniqueEmail ( ) ;
169
165
@@ -203,4 +199,53 @@ describe('Firebase UI Auth Integration', () => {
203
199
expect ( results . every ( ( result ) => result . user . email === email ) ) . toBe ( true ) ;
204
200
} ) ;
205
201
} ) ;
202
+
203
+ describe ( 'Anonymous User Upgrade' , ( ) => {
204
+ it ( 'should maintain user data when upgrading anonymous account' , async ( ) => {
205
+ // First create an anonymous user
206
+ const anonResult = await fuiSignInAnonymously ( auth ) ;
207
+ const anonUid = anonResult . user . uid ;
208
+
209
+ // Upgrade to email/password
210
+ const email = getUniqueEmail ( ) ;
211
+ const result = await fuiCreateUserWithEmailAndPassword ( auth , email , testPassword , {
212
+ enableAutoUpgradeAnonymous : true ,
213
+ } ) ;
214
+
215
+ // Verify it's the same user
216
+ expect ( result . user . uid ) . toBe ( anonUid ) ;
217
+ expect ( result . user . email ) . toBe ( email ) ;
218
+ expect ( result . user . isAnonymous ) . toBe ( false ) ;
219
+ } ) ;
220
+
221
+ it ( 'should handle enableAutoUpgradeAnonymous flag correctly' , async ( ) => {
222
+ // Create an anonymous user
223
+ await fuiSignInAnonymously ( auth ) ;
224
+ const email = getUniqueEmail ( ) ;
225
+
226
+ // Try to create new user without upgrade flag
227
+ const result = await fuiCreateUserWithEmailAndPassword ( auth , email , testPassword , {
228
+ enableAutoUpgradeAnonymous : false ,
229
+ } ) ;
230
+
231
+ // Should be a new user, not an upgrade
232
+ expect ( result . user . isAnonymous ) . toBe ( false ) ;
233
+ expect ( result . user . email ) . toBe ( email ) ;
234
+ } ) ;
235
+ } ) ;
236
+
237
+ describe ( 'Email Link Authentication State Management' , ( ) => {
238
+ it ( 'should handle multiple email link requests properly' , async ( ) => {
239
+ const email1 = getUniqueEmail ( ) ;
240
+ const email2 = getUniqueEmail ( ) ;
241
+
242
+ // First email link request
243
+ await fuiSendSignInLinkToEmail ( auth , email1 ) ;
244
+ expect ( window . localStorage . getItem ( 'emailForSignIn' ) ) . toBe ( email1 ) ;
245
+
246
+ // Second email link request should override the first
247
+ await fuiSendSignInLinkToEmail ( auth , email2 ) ;
248
+ expect ( window . localStorage . getItem ( 'emailForSignIn' ) ) . toBe ( email2 ) ;
249
+ } ) ;
250
+ } ) ;
206
251
} ) ;
0 commit comments