|
| 1 | +/*! |
| 2 | + * Copyright 2018 Google Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import * as admin from '../../lib/index'; |
| 18 | +import {expect} from 'chai'; |
| 19 | +import { |
| 20 | + defaultApp, nullApp, nonNullApp, databaseUrl, projectId, storageBucket, |
| 21 | +} from './setup'; |
| 22 | + |
| 23 | +describe('admin', () => { |
| 24 | + it('populates required test parameters', () => { |
| 25 | + expect(databaseUrl).to.be.not.empty; |
| 26 | + expect(projectId).to.be.not.empty; |
| 27 | + expect(storageBucket).to.be.not.empty; |
| 28 | + }); |
| 29 | + |
| 30 | + it('does not load Firestore by default', () => { |
| 31 | + let gcloud = require.cache[require.resolve('@google-cloud/firestore')]; |
| 32 | + expect(gcloud).to.be.undefined; |
| 33 | + }); |
| 34 | + |
| 35 | + it('loads Firestore when calling admin.firestore', () => { |
| 36 | + const firestoreNamespace = admin.firestore; |
| 37 | + expect(firestoreNamespace).to.not.be.null; |
| 38 | + let gcloud = require.cache[require.resolve('@google-cloud/firestore')]; |
| 39 | + expect(gcloud).to.not.be.undefined; |
| 40 | + }); |
| 41 | +}); |
| 42 | + |
| 43 | +describe('admin.app', () => { |
| 44 | + it('admin.app() returns the default App', () => { |
| 45 | + let app = admin.app(); |
| 46 | + expect(app).to.deep.equal(defaultApp); |
| 47 | + expect(app.name).to.equal('[DEFAULT]'); |
| 48 | + expect(app.options.databaseURL).to.equal(databaseUrl); |
| 49 | + expect(app.options.databaseAuthVariableOverride).to.be.undefined; |
| 50 | + expect(app.options.storageBucket).to.equal(storageBucket); |
| 51 | + }); |
| 52 | + |
| 53 | + it('admin.app("null") returns the App named "null"', () => { |
| 54 | + let app = admin.app('null'); |
| 55 | + expect(app).to.deep.equal(nullApp); |
| 56 | + expect(app.name).to.equal('null'); |
| 57 | + expect(app.options.databaseURL).to.equal(databaseUrl); |
| 58 | + expect(app.options.databaseAuthVariableOverride).to.be.null; |
| 59 | + expect(app.options.storageBucket).to.equal(storageBucket); |
| 60 | + }); |
| 61 | + |
| 62 | + it('admin.app("nonNull") returns the App named "nonNull"', () => { |
| 63 | + let app = admin.app('nonNull'); |
| 64 | + expect(app).to.deep.equal(nonNullApp); |
| 65 | + expect(app.name).to.equal('nonNull'); |
| 66 | + expect(app.options.databaseURL).to.equal(databaseUrl); |
| 67 | + expect((app.options.databaseAuthVariableOverride as any).uid).to.be.ok; |
| 68 | + expect(app.options.storageBucket).to.equal(storageBucket); |
| 69 | + }); |
| 70 | + |
| 71 | + it('namespace services are attached to the default App', () => { |
| 72 | + let app = admin.app(); |
| 73 | + expect(admin.auth(app).app).to.deep.equal(app); |
| 74 | + expect(admin.database(app).app).to.deep.equal(app); |
| 75 | + expect(admin.messaging(app).app).to.deep.equal(app); |
| 76 | + expect(admin.storage(app).app).to.deep.equal(app); |
| 77 | + }); |
| 78 | + |
| 79 | + it('namespace services are attached to the named App', () => { |
| 80 | + let app = admin.app('null'); |
| 81 | + expect(admin.auth(app).app).to.deep.equal(app); |
| 82 | + expect(admin.database(app).app).to.deep.equal(app); |
| 83 | + expect(admin.messaging(app).app).to.deep.equal(app); |
| 84 | + expect(admin.storage(app).app).to.deep.equal(app); |
| 85 | + }); |
| 86 | +}); |
0 commit comments