@@ -21,11 +21,13 @@ import {
21
21
EmailAuthProvider ,
22
22
linkWithCredential ,
23
23
OperationType ,
24
+ reload ,
24
25
signInAnonymously ,
25
26
signInWithCustomToken ,
26
27
signInWithEmailAndPassword ,
27
28
updateEmail ,
28
- updatePassword
29
+ updatePassword ,
30
+ updateProfile ,
29
31
// eslint-disable-next-line import/no-extraneous-dependencies
30
32
} from '@firebase/auth-exp' ;
31
33
import { FirebaseError } from '@firebase/util' ;
@@ -41,9 +43,18 @@ use(chaiAsPromised);
41
43
42
44
describe ( 'Integration test: custom auth' , ( ) => {
43
45
let auth : Auth ;
46
+ let customToken : string ;
47
+ let uid : string ;
44
48
45
49
beforeEach ( ( ) => {
46
50
auth = getTestInstance ( ) ;
51
+ uid = randomEmail ( ) ;
52
+ customToken = JSON . stringify ( {
53
+ uid,
54
+ claims : {
55
+ customClaim : 'some-claim' ,
56
+ }
57
+ } ) ;
47
58
48
59
if ( ! auth . emulatorConfig ) {
49
60
throw new Error ( 'Test can only be run against the emulator!' ) ;
@@ -57,17 +68,14 @@ describe('Integration test: custom auth', () => {
57
68
it ( 'signs in with custom token' , async ( ) => {
58
69
const cred = await signInWithCustomToken (
59
70
auth ,
60
- JSON . stringify ( {
61
- uid : 'custom-uid-yay' ,
62
- claims : { customClaim : 'some-claim' }
63
- } )
71
+ customToken
64
72
) ;
65
73
expect ( auth . currentUser ) . to . eq ( cred . user ) ;
66
74
expect ( cred . operationType ) . to . eq ( OperationType . SIGN_IN ) ;
67
75
68
76
const { user } = cred ;
69
77
expect ( user . isAnonymous ) . to . be . false ;
70
- expect ( user . uid ) . to . eq ( 'custom- uid-yay' ) ;
78
+ expect ( user . uid ) . to . eq ( uid ) ;
71
79
expect ( ( await user . getIdTokenResult ( false ) ) . claims . customClaim ) . to . eq (
72
80
'some-claim'
73
81
) ;
@@ -88,6 +96,54 @@ describe('Integration test: custom auth', () => {
88
96
expect ( customCred . user . isAnonymous ) . to . be . false ;
89
97
} ) ;
90
98
99
+ it ( 'allows the user to delete the account' , async ( ) => {
100
+ let { user } = await signInWithCustomToken (
101
+ auth ,
102
+ customToken
103
+ ) ;
104
+ await updateProfile ( user , { displayName : 'Display Name' } ) ;
105
+ expect ( user . displayName ) . to . eq ( 'Display Name' ) ;
106
+
107
+ await user . delete ( ) ;
108
+ await expect ( reload ( user ) ) . to . be . rejectedWith (
109
+ FirebaseError ,
110
+ 'auth/user-token-expired'
111
+ ) ;
112
+ expect ( auth . currentUser ) . to . be . null ;
113
+
114
+ ( { user} = await signInWithCustomToken ( auth , customToken ) ) ;
115
+ // New user in the system: the display name should be missing
116
+ expect ( user . displayName ) . to . be . null ;
117
+ } ) ;
118
+
119
+ it ( 'sign in can be called twice successively' , async ( ) => {
120
+ const { user : userA } = await signInWithCustomToken (
121
+ auth ,
122
+ customToken
123
+ ) ;
124
+ const { user : userB } = await signInWithCustomToken (
125
+ auth ,
126
+ customToken
127
+ ) ;
128
+ expect ( userA . uid ) . to . eq ( userB . uid ) ;
129
+ } ) ;
130
+
131
+ it ( 'allows user to update profile' , async ( ) => {
132
+ let { user } = await signInWithCustomToken ( auth , customToken ) ;
133
+ await updateProfile ( user , {
134
+ displayName : 'Display Name' ,
135
+ photoURL : 'photo-url'
136
+ } ) ;
137
+ expect ( user . displayName ) . to . eq ( 'Display Name' ) ;
138
+ expect ( user . photoURL ) . to . eq ( 'photo-url' ) ;
139
+
140
+ await auth . signOut ( ) ;
141
+
142
+ user = ( await signInWithCustomToken ( auth , customToken ) ) . user ;
143
+ expect ( user . displayName ) . to . eq ( 'Display Name' ) ;
144
+ expect ( user . photoURL ) . to . eq ( 'photo-url' ) ;
145
+ } ) ;
146
+
91
147
context ( 'email/password interaction' , ( ) => {
92
148
let email : string ;
93
149
let customToken : string ;
0 commit comments