Skip to content

Commit 27f837c

Browse files
committed
Update some stuff
1 parent 62392ed commit 27f837c

File tree

3 files changed

+67
-60
lines changed

3 files changed

+67
-60
lines changed

packages-exp/auth-exp/scripts/run-node-tests.js

Lines changed: 2 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages-exp/auth-exp/scripts/run-node-tests.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ let testConfig = [
4242

4343
if (argv.integration) {
4444
testConfig = ['test/integration/flows/{email,anonymous}.test.ts'];
45+
if (argv.local) {
46+
testConfig.push('test/integration/flows/*.local.test.ts');
47+
}
4548
}
4649

4750
let args = [

packages-exp/auth-exp/test/integration/flows/custom.local.test.ts

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import {
2121
EmailAuthProvider,
2222
linkWithCredential,
2323
OperationType,
24+
reload,
2425
signInAnonymously,
2526
signInWithCustomToken,
2627
signInWithEmailAndPassword,
2728
updateEmail,
28-
updatePassword
29+
updatePassword,
30+
updateProfile,
2931
// eslint-disable-next-line import/no-extraneous-dependencies
3032
} from '@firebase/auth-exp';
3133
import { FirebaseError } from '@firebase/util';
@@ -41,9 +43,18 @@ use(chaiAsPromised);
4143

4244
describe('Integration test: custom auth', () => {
4345
let auth: Auth;
46+
let customToken: string;
47+
let uid: string;
4448

4549
beforeEach(() => {
4650
auth = getTestInstance();
51+
uid = randomEmail();
52+
customToken = JSON.stringify({
53+
uid,
54+
claims: {
55+
customClaim: 'some-claim',
56+
}
57+
});
4758

4859
if (!auth.emulatorConfig) {
4960
throw new Error('Test can only be run against the emulator!');
@@ -57,17 +68,14 @@ describe('Integration test: custom auth', () => {
5768
it('signs in with custom token', async () => {
5869
const cred = await signInWithCustomToken(
5970
auth,
60-
JSON.stringify({
61-
uid: 'custom-uid-yay',
62-
claims: { customClaim: 'some-claim' }
63-
})
71+
customToken
6472
);
6573
expect(auth.currentUser).to.eq(cred.user);
6674
expect(cred.operationType).to.eq(OperationType.SIGN_IN);
6775

6876
const { user } = cred;
6977
expect(user.isAnonymous).to.be.false;
70-
expect(user.uid).to.eq('custom-uid-yay');
78+
expect(user.uid).to.eq(uid);
7179
expect((await user.getIdTokenResult(false)).claims.customClaim).to.eq(
7280
'some-claim'
7381
);
@@ -88,6 +96,54 @@ describe('Integration test: custom auth', () => {
8896
expect(customCred.user.isAnonymous).to.be.false;
8997
});
9098

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+
91147
context('email/password interaction', () => {
92148
let email: string;
93149
let customToken: string;

0 commit comments

Comments
 (0)