Skip to content

Commit 02b8e3e

Browse files
committed
Adding Unit test for initializeAuth with TenantConfig dependency
1 parent 2d776b9 commit 02b8e3e

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
AuthProvider,
2727
Persistence as PersistencePublic,
2828
PopupRedirectResolver,
29+
TenantConfig,
2930
UserCredential
3031
} from '../../model/public_types';
3132
import { isNode } from '@firebase/util';
@@ -51,6 +52,7 @@ import { ClientPlatform, _getClientVersion } from '../util/version';
5152
import { initializeAuth } from './initialize';
5253
import { registerAuth } from './register';
5354
import { debugErrorMap, prodErrorMap } from '../errors';
55+
import { DefaultConfig } from './auth_impl';
5456

5557
describe('core/auth/initialize', () => {
5658
let fakeApp: FirebaseApp;
@@ -132,6 +134,8 @@ describe('core/auth/initialize', () => {
132134
const fakePopupRedirectResolver: PopupRedirectResolver =
133135
FakePopupRedirectResolver;
134136

137+
const fakeTenantConfig: TenantConfig = {'location': "us", 'tenantId': "tenant-1"};
138+
135139
before(() => {
136140
registerAuth(ClientPlatform.BROWSER);
137141
});
@@ -202,6 +206,15 @@ describe('core/auth/initialize', () => {
202206
);
203207
});
204208

209+
it('should set TenantConfig', async() => {
210+
const auth = initializeAuth(fakeApp, {
211+
tenantConfig: fakeTenantConfig
212+
}) as AuthInternal;
213+
await auth._initializationPromise;
214+
215+
expect(auth.config.apiHost).equal(DefaultConfig.REGIONAL_API_HOST);
216+
});
217+
205218
it('should abort initialization if deleted synchronously', async () => {
206219
const auth = initializeAuth(fakeApp, {
207220
popupRedirectResolver: fakePopupRedirectResolver
@@ -221,13 +234,15 @@ describe('core/auth/initialize', () => {
221234
const auth = initializeAuth(fakeApp, {
222235
errorMap: prodErrorMap,
223236
persistence: fakeSessionPersistence,
224-
popupRedirectResolver: fakePopupRedirectResolver
237+
popupRedirectResolver: fakePopupRedirectResolver,
238+
tenantConfig: fakeTenantConfig
225239
});
226240
expect(
227241
initializeAuth(fakeApp, {
228242
errorMap: prodErrorMap,
229243
persistence: fakeSessionPersistence,
230-
popupRedirectResolver: fakePopupRedirectResolver
244+
popupRedirectResolver: fakePopupRedirectResolver,
245+
tenantConfig: fakeTenantConfig
231246
})
232247
).to.equal(auth);
233248
});
@@ -264,5 +279,16 @@ describe('core/auth/initialize', () => {
264279
})
265280
).to.throw();
266281
});
282+
283+
it('should throw if called again with different params (TenantConfig)', () => {
284+
initializeAuth(fakeApp, {
285+
tenantConfig: fakeTenantConfig
286+
});
287+
expect(() =>
288+
initializeAuth(fakeApp, {
289+
tenantConfig: undefined
290+
})
291+
).to.throw();
292+
});
267293
});
268294
});

0 commit comments

Comments
 (0)