Skip to content

Commit 205916f

Browse files
committed
Adding Unit test
1 parent c8d9cb5 commit 205916f

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

packages/auth/src/core/auth/firebase_internal.test.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import { FirebaseError } from '@firebase/util';
1919
import { expect, use } from 'chai';
2020
import * as sinon from 'sinon';
21+
import sinonChai from 'sinon-chai';
2122
import chaiAsPromised from 'chai-as-promised';
2223

2324
import {
@@ -29,6 +30,7 @@ import { AuthInternal } from '../../model/auth';
2930
import { UserInternal } from '../../model/user';
3031
import { AuthInterop } from './firebase_internal';
3132

33+
use(sinonChai);
3234
use(chaiAsPromised);
3335

3436
describe('core/auth/firebase_internal', () => {
@@ -240,29 +242,29 @@ describe('core/auth/firebase_internal - Regional Firebase Auth', () => {
240242

241243
context('getFirebaseToken', () => {
242244
it('returns null if firebase token is undefined', async () => {
243-
expect(await regionalAuthInternal.getFirebaseToken()).to.be.null;
245+
expect(await regionalAuthInternal.getToken()).to.be.null;
244246
});
245247

246248
it('returns the id token correctly', async () => {
247249
await regionalAuth._updateFirebaseToken({
248250
token: 'access-token',
249251
expirationTime: now + 300_000
250252
});
251-
expect(await regionalAuthInternal.getFirebaseToken()).to.eql({
253+
expect(await regionalAuthInternal.getToken()).to.eql({
252254
accessToken: 'access-token'
253255
});
254256
});
255257

256258
it('logs out the the id token expires in next 30 seconds', async () => {
257-
expect(await regionalAuthInternal.getFirebaseToken()).to.be.null;
259+
expect(await regionalAuthInternal.getToken()).to.be.null;
258260
});
259261

260262
it('logs out if token has expired', async () => {
261263
await regionalAuth._updateFirebaseToken({
262264
token: 'access-token',
263265
expirationTime: now - 5_000
264266
});
265-
expect(await regionalAuthInternal.getFirebaseToken()).to.null;
267+
expect(await regionalAuthInternal.getToken()).to.null;
266268
expect(regionalAuth.firebaseToken).to.null;
267269
});
268270

@@ -271,8 +273,23 @@ describe('core/auth/firebase_internal - Regional Firebase Auth', () => {
271273
token: 'access-token',
272274
expirationTime: now + 5_000
273275
});
274-
expect(await regionalAuthInternal.getFirebaseToken()).to.null;
276+
expect(await regionalAuthInternal.getToken()).to.null;
275277
expect(regionalAuth.firebaseToken).to.null;
276278
});
279+
280+
it('logs warning if getToken is called with forceRefresh true', async () => {
281+
sinon.stub(console, 'warn');
282+
await regionalAuth._updateFirebaseToken({
283+
token: 'access-token',
284+
expirationTime: now + 300_000
285+
});
286+
expect(await regionalAuthInternal.getToken(true)).to.eql({
287+
accessToken: 'access-token'
288+
});
289+
expect(console.warn).to.have.been.calledWith(
290+
sinon.match.string,
291+
sinon.match(/Refresh token is not a valid operation for Regional Auth instance initialized\./)
292+
);
293+
});
277294
});
278295
});

0 commit comments

Comments
 (0)