|
| 1 | +/*! |
| 2 | + * @license |
| 3 | + * Copyright 2025 Google LLC |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +'use strict'; |
| 19 | + |
| 20 | +import * as chai from 'chai'; |
| 21 | +import * as sinonChai from 'sinon-chai'; |
| 22 | +import * as chaiAsPromised from 'chai-as-promised'; |
| 23 | + |
| 24 | +import * as mocks from '../../resources/mocks'; |
| 25 | +import { App } from '../../../src/app/index'; |
| 26 | +import { getFirebasePnv, Fpnv } from '../../../src/fpnv/index'; |
| 27 | + |
| 28 | +chai.should(); |
| 29 | +chai.use(sinonChai); |
| 30 | +chai.use(chaiAsPromised); |
| 31 | + |
| 32 | +const expect = chai.expect; |
| 33 | + |
| 34 | +describe('Fpnv', () => { |
| 35 | + let mockApp: App; |
| 36 | + let mockCredentialApp: App; |
| 37 | + |
| 38 | + beforeEach(() => { |
| 39 | + mockApp = mocks.app(); |
| 40 | + mockCredentialApp = mocks.mockCredentialApp(); |
| 41 | + }); |
| 42 | + |
| 43 | + describe('getFirebasePnv()', () => { |
| 44 | + it('should throw when default app is not available', () => { |
| 45 | + expect(() => { |
| 46 | + return getFirebasePnv(); |
| 47 | + }).to.throw('The default Firebase app does not exist.'); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should not throw given a valid app', () => { |
| 51 | + expect(() => { |
| 52 | + return getFirebasePnv(mockApp); |
| 53 | + }).not.to.throw(); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should return the same instance for app instance', () => { |
| 57 | + const fpnvFirst: Fpnv = getFirebasePnv(mockApp); |
| 58 | + const fpnvSecond: Fpnv = getFirebasePnv(mockApp); |
| 59 | + expect(fpnvFirst).to.equal(fpnvSecond); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should not return the same instance when different configs are provided', () => { |
| 63 | + const fpnvFirst: Fpnv = getFirebasePnv(mockApp); |
| 64 | + const fpnvSecond: Fpnv = getFirebasePnv(mockCredentialApp); |
| 65 | + expect(fpnvFirst).to.not.equal(fpnvSecond); |
| 66 | + }); |
| 67 | + }); |
| 68 | +}); |
0 commit comments