Skip to content

Commit b0468f1

Browse files
committed
Cleanup & PR Feedback
1 parent ed5bcbc commit b0468f1

File tree

7 files changed

+70
-6
lines changed

7 files changed

+70
-6
lines changed

packages-exp/auth-exp/src/core/auth/auth_impl.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
import { FirebaseApp } from '@firebase/app-types-exp';
19+
import { FirebaseError } from '@firebase/util';
1820
import { expect, use } from 'chai';
1921
import * as sinon from 'sinon';
2022
import * as sinonChai from 'sinon-chai';

packages-exp/auth-exp/src/core/strategies/credential.test.ts

Whitespace-only changes.

packages-exp/auth-exp/src/core/strategies/credential.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ export async function signInWithCredential(
2626
): Promise<UserCredential> {
2727
// TODO: handle mfa by wrapping with callApiWithMfaContext
2828
const response = await credential._getIdTokenResponse(auth);
29-
return UserCredentialImpl._fromIdTokenResponse(
29+
const userCredential = await UserCredentialImpl._fromIdTokenResponse(
3030
auth,
3131
credential,
3232
OperationType.SIGN_IN,
3333
response
3434
);
35+
await auth.updateCurrentUser(userCredential.user);
36+
return userCredential;
3537
}

packages-exp/auth-exp/src/core/user/user_credential_impl.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,31 @@ import { OperationType } from '../../model/user_credential';
2424
import { ProviderId, SignInMethod } from '../providers';
2525
import { AuthCredentialImpl } from '../providers/auth_credential_impl';
2626
import { UserCredentialImpl } from './user_credential_impl';
27+
import { APIUserInfo } from '../../api/account_management/account';
28+
import { mockEndpoint } from '../../../test/api/helper';
29+
import { Endpoint } from '../../api';
2730

2831
use(chaiAsPromised);
2932

3033
describe('core/user/user_credential_impl', () => {
34+
const serverUser: APIUserInfo = {
35+
localId: 'localId',
36+
displayName: 'displayName',
37+
photoUrl: 'photoURL',
38+
email: 'email',
39+
emailVerified: true,
40+
phoneNumber: 'phoneNumber',
41+
tenantId: 'tenantId',
42+
createdAt: 123,
43+
lastLoginAt: 456
44+
};
45+
46+
beforeEach(() => {
47+
mockEndpoint(Endpoint.GET_ACCOUNT_INFO, {
48+
users: [serverUser]
49+
});
50+
});
51+
3152
describe('fromIdTokenResponse', () => {
3253
const idTokenResponse: IdTokenResponse = {
3354
idToken: 'my-id-token',
@@ -53,5 +74,9 @@ describe('core/user/user_credential_impl', () => {
5374
expect(userCredential.operationType).to.eq(OperationType.SIGN_IN);
5475
expect(userCredential.user.uid).to.eq('my-uid');
5576
});
77+
78+
it('should not trigger callbacks', () => {
79+
80+
});
5681
});
5782
});

packages-exp/auth-exp/src/core/user/user_credential_impl.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ export class UserCredentialImpl implements UserCredential {
3636
idTokenResponse: IdTokenResponse
3737
): Promise<UserCredential> {
3838
const user = await UserImpl._fromIdTokenResponse(auth, idTokenResponse);
39-
// TODO: Rebase and uncomment
40-
// await auth.updateCurrentUser(user);
4139
const userCred = new UserCredentialImpl(user, credential, operationType);
4240
// TODO: handle additional user info
4341
// updateAdditionalUserInfoFromIdTokenResponse(userCred, idTokenResponse);

packages-exp/auth-exp/src/core/user/user_impl.test.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ import { Endpoint } from '../../api';
3030
import { IdTokenResponse } from '../../model/id_token';
3131
import { StsTokenManager } from './token_manager';
3232
import { UserImpl } from './user_impl';
33+
import { mockEndpoint } from '../../../test/api/helper';
34+
import { Endpoint } from '../../api';
35+
import { APIUserInfo } from '../../api/account_management/account';
3336

3437
use(sinonChai);
3538
use(chaiAsPromised);
39+
use(sinonChai);
3640

3741
describe('core/user/user_impl', () => {
3842
const auth = mockAuth;
@@ -195,6 +199,24 @@ describe('core/user/user_impl', () => {
195199
kind: 'my-kind'
196200
};
197201

202+
const serverUser: APIUserInfo = {
203+
localId: 'local-id',
204+
displayName: 'display-name',
205+
photoUrl: 'photo-url',
206+
email: 'email',
207+
emailVerified: true,
208+
phoneNumber: 'phone-number',
209+
tenantId: 'tenant-id',
210+
createdAt: 123,
211+
lastLoginAt: 456
212+
};
213+
214+
beforeEach(() => {
215+
mockEndpoint(Endpoint.GET_ACCOUNT_INFO, {
216+
users: [serverUser]
217+
});
218+
});
219+
198220
it('should initialize a user', async () => {
199221
const user = await UserImpl._fromIdTokenResponse(
200222
mockAuth,
@@ -205,8 +227,23 @@ describe('core/user/user_impl', () => {
205227
expect(await user.getIdToken()).to.eq('my-id-token');
206228
});
207229

208-
it('should reload the user', () => {
209-
// TODO: need to wait for https://github.com/firebase/firebase-js-sdk/pull/2961
230+
it('should pull additional user info on the user', async () => {
231+
const user = await UserImpl._fromIdTokenResponse(
232+
mockAuth,
233+
idTokenResponse
234+
);
235+
expect(user.displayName).to.eq('display-name');
236+
expect(user.phoneNumber).to.eq('phone-number');
237+
});
238+
239+
it('should not trigger additional callbacks', async () => {
240+
const cb = sinon.spy();
241+
auth.onAuthStateChanged(cb);
242+
await UserImpl._fromIdTokenResponse(
243+
mockAuth,
244+
idTokenResponse
245+
);
246+
expect(cb).not.to.have.been.called;
210247
});
211248
});
212249
});

packages-exp/auth-exp/src/core/user/user_impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class UserImpl implements User {
175175
});
176176

177177
// Updates the user info and data and resolves with a user instance.
178-
await user.reload();
178+
await _reloadWithoutSaving(user);
179179
return user;
180180
}
181181
}

0 commit comments

Comments
 (0)