|
17 | 17 |
|
18 | 18 | 'use strict'; |
19 | 19 |
|
| 20 | +import http = require('http'); |
20 | 21 | import path = require('path'); |
21 | 22 |
|
22 | 23 | import * as _ from 'lodash'; |
@@ -89,6 +90,20 @@ const expect = chai.expect; |
89 | 90 | const DEFAULT_APP_NAME = '[DEFAULT]'; |
90 | 91 | const DEFAULT_APP_NOT_FOUND = 'The default Firebase app does not exist. Make sure you call initializeApp() ' |
91 | 92 | + 'before using any of the Firebase services.'; |
| 93 | +const INITIALIZE_APP_CREDENTIAL_EXISTANCE_MISMATCH = 'An existing app named "mock-app-name" already ' |
| 94 | + + 'exists with a different options configuration: Credential'; |
| 95 | +const INITIALIZE_APP_HTTP_AGENT_EXISTANCE_MISMATCH = 'An existing app named "mock-app-name" already ' |
| 96 | + + 'exists with a different options configuration: httpAgent'; |
| 97 | +const INITIALIZE_APP_NOT_IDEMPOTENT_CREDENTIAL = 'Firebase app named "mock-app-name" already exists and ' |
| 98 | + + 'initializeApp was invoked with an optional Credential. The SDK cannot confirm the equality ' |
| 99 | + + 'of Credential objects with the existing app. Please use getApp or getApps to reuse the ' |
| 100 | + + 'existing app instead.' |
| 101 | +const INITIALIZE_APP_NOT_IDEMPOTENT_HTTP_AGENT = 'Firebase app named "mock-app-name" already exists and ' |
| 102 | + + 'initializeApp was invoked with an optional http.Agent. The SDK cannot confirm the equality ' |
| 103 | + + 'of http.Agent objects with the existing app. Please use getApp or getApps to reuse the ' |
| 104 | + + 'existing app instead.' |
| 105 | + |
| 106 | + |
92 | 107 |
|
93 | 108 | describe('FirebaseNamespace', () => { |
94 | 109 | let firebaseNamespace: FirebaseNamespace; |
@@ -221,15 +236,80 @@ describe('FirebaseNamespace', () => { |
221 | 236 | let app1: App | undefined; |
222 | 237 | let app2: App | undefined; |
223 | 238 | expect(() => { |
224 | | - app1 = firebaseNamespace.initializeApp(mocks.appOptions); |
225 | | - app2 = firebaseNamespace.initializeApp(mocks.appOptions); |
| 239 | + app1 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential); |
| 240 | + app2 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential); |
226 | 241 | }).to.not.throw(); |
227 | 242 | expect(app1).to.equal(app2); |
| 243 | + }); |
228 | 244 |
|
| 245 | + it('should throw due to the Credential option being not supported by idemopotency', () => { |
| 246 | + let app1: App | undefined; |
| 247 | + let app2: App | undefined; |
229 | 248 | expect(() => { |
230 | | - app2 = firebaseNamespace.initializeApp(mocks.appOptions, DEFAULT_APP_NAME); |
231 | | - }).to.not.throw(); |
232 | | - expect(app1).to.equal(app2); |
| 249 | + app1 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); |
| 250 | + app2 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); |
| 251 | + }).to.throw(INITIALIZE_APP_NOT_IDEMPOTENT_CREDENTIAL); |
| 252 | + expect(app1).to.not.be.undefined; |
| 253 | + expect(app2).to.be.undefined; |
| 254 | + }); |
| 255 | + |
| 256 | + it('should throw due to idempotency check on Credential option on second app.', () => { |
| 257 | + let app1: App | undefined; |
| 258 | + let app2: App | undefined; |
| 259 | + expect(() => { |
| 260 | + app1 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); |
| 261 | + app2 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential, mocks.appName); |
| 262 | + }).to.throw(INITIALIZE_APP_CREDENTIAL_EXISTANCE_MISMATCH); |
| 263 | + expect(app1).to.not.be.undefined; |
| 264 | + expect(app2).to.be.undefined; |
| 265 | + }); |
| 266 | + |
| 267 | + it('should throw due to the httpAgent option being not supported by idemopotency', () => { |
| 268 | + let app1: App | undefined; |
| 269 | + let app2: App | undefined; |
| 270 | + const httpAgent = new http.Agent(); |
| 271 | + const appOptions = { |
| 272 | + ...mocks.appOptionsWithoutCredential, |
| 273 | + httpAgent |
| 274 | + } |
| 275 | + expect(() => { |
| 276 | + app1 = firebaseNamespace.initializeApp(appOptions, mocks.appName); |
| 277 | + app2 = firebaseNamespace.initializeApp(appOptions, mocks.appName); |
| 278 | + }).to.throw(INITIALIZE_APP_NOT_IDEMPOTENT_HTTP_AGENT); |
| 279 | + expect(app1).to.not.be.undefined; |
| 280 | + expect(app2).to.be.undefined; |
| 281 | + }); |
| 282 | + |
| 283 | + it('should throw due to idempotency check on httpAgent option on second app.', () => { |
| 284 | + let app1: App | undefined; |
| 285 | + let app2: App | undefined; |
| 286 | + const httpAgent = new http.Agent(); |
| 287 | + const appOptions = { |
| 288 | + ...mocks.appOptionsWithoutCredential, |
| 289 | + httpAgent |
| 290 | + } |
| 291 | + expect(() => { |
| 292 | + app1 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential, mocks.appName); |
| 293 | + app2 = firebaseNamespace.initializeApp(appOptions, mocks.appName); |
| 294 | + }).to.throw(INITIALIZE_APP_NOT_IDEMPOTENT_HTTP_AGENT); |
| 295 | + expect(app1).to.not.be.undefined; |
| 296 | + expect(app2).to.be.undefined; |
| 297 | + }); |
| 298 | + |
| 299 | + it('should throw due to idempotency check on httpAgent option on first app but not second app.', () => { |
| 300 | + let app1: App | undefined; |
| 301 | + let app2: App | undefined; |
| 302 | + const httpAgent = new http.Agent(); |
| 303 | + const appOptions = { |
| 304 | + ...mocks.appOptionsWithoutCredential, |
| 305 | + httpAgent |
| 306 | + } |
| 307 | + expect(() => { |
| 308 | + app1 = firebaseNamespace.initializeApp(appOptions, mocks.appName); |
| 309 | + app2 = firebaseNamespace.initializeApp(mocks.appOptionsWithoutCredential, mocks.appName); |
| 310 | + }).to.throw(INITIALIZE_APP_HTTP_AGENT_EXISTANCE_MISMATCH); |
| 311 | + expect(app1).to.not.be.undefined; |
| 312 | + expect(app2).to.be.undefined; |
233 | 313 | }); |
234 | 314 |
|
235 | 315 | it('should return a new app with the provided options and app name', () => { |
|
0 commit comments