|
| 1 | +/*! |
| 2 | + * @license |
| 3 | + * Copyright 2021 Google Inc. |
| 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 | +import { expect } from 'chai'; |
| 19 | + |
| 20 | +import { cert, deleteApp, initializeApp, App } from 'firebase-admin/app'; |
| 21 | +import { getAuth, Auth } from 'firebase-admin/auth'; |
| 22 | +import { getDatabase, getDatabaseWithUrl, Database, ServerValue } from 'firebase-admin/database'; |
| 23 | +import { getFirestore, DocumentReference, Firestore, FieldValue } from 'firebase-admin/firestore'; |
| 24 | +import { getInstanceId, InstanceId } from 'firebase-admin/instance-id'; |
| 25 | +import { getMachineLearning, MachineLearning } from 'firebase-admin/machine-learning'; |
| 26 | +import { getMessaging, Messaging } from 'firebase-admin/messaging'; |
| 27 | +import { getProjectManagement, ProjectManagement } from 'firebase-admin/project-management'; |
| 28 | +import { getRemoteConfig, RemoteConfig } from 'firebase-admin/remote-config'; |
| 29 | +import { getSecurityRules, SecurityRules } from 'firebase-admin/security-rules'; |
| 30 | +import { getStorage, Storage } from 'firebase-admin/storage'; |
| 31 | + |
| 32 | +import { Bucket } from '@google-cloud/storage'; |
| 33 | + |
| 34 | + |
| 35 | +// eslint-disable-next-line @typescript-eslint/no-var-requires |
| 36 | +const serviceAccount = require('../mock.key.json'); |
| 37 | + |
| 38 | +describe('Modular API', () => { |
| 39 | + let app: App; |
| 40 | + |
| 41 | + before(() => { |
| 42 | + app = initializeApp({ |
| 43 | + credential: cert(serviceAccount), |
| 44 | + databaseURL: 'https://mock.firebaseio.com' |
| 45 | + }, 'TestApp'); |
| 46 | + }); |
| 47 | + |
| 48 | + after(() => { |
| 49 | + return deleteApp(app); |
| 50 | + }); |
| 51 | + |
| 52 | + it('Should return an initialized App', () => { |
| 53 | + expect(app.name).to.equal('TestApp'); |
| 54 | + }); |
| 55 | + |
| 56 | + it('Should return an Auth client', () => { |
| 57 | + const client = getAuth(app); |
| 58 | + expect(client).to.be.instanceOf(Auth); |
| 59 | + }); |
| 60 | + |
| 61 | + it('Should return a Messaging client', () => { |
| 62 | + const client = getMessaging(app); |
| 63 | + expect(client).to.be.instanceOf(Messaging); |
| 64 | + }); |
| 65 | + |
| 66 | + it('Should return a ProjectManagement client', () => { |
| 67 | + const client = getProjectManagement(app); |
| 68 | + expect(client).to.be.instanceOf(ProjectManagement); |
| 69 | + }); |
| 70 | + |
| 71 | + it('Should return a SecurityRules client', () => { |
| 72 | + const client = getSecurityRules(app); |
| 73 | + expect(client).to.be.instanceOf(SecurityRules); |
| 74 | + }); |
| 75 | + |
| 76 | + it('Should return a Database client', () => { |
| 77 | + const db: Database = getDatabase(app); |
| 78 | + expect(db).to.be.not.undefined; |
| 79 | + expect(typeof db.getRules).to.equal('function'); |
| 80 | + }); |
| 81 | + |
| 82 | + it('Should return a Database client for URL', () => { |
| 83 | + const db: Database = getDatabaseWithUrl('https://other-mock.firebaseio.com', app); |
| 84 | + expect(db).to.be.not.undefined; |
| 85 | + expect(typeof db.getRules).to.equal('function'); |
| 86 | + }); |
| 87 | + |
| 88 | + it('Should return a Database ServerValue', () => { |
| 89 | + expect(ServerValue.increment(1)).to.be.not.undefined; |
| 90 | + }); |
| 91 | + |
| 92 | + it('Should return a Cloud Storage client', () => { |
| 93 | + const storage = getStorage(app); |
| 94 | + expect(storage).to.be.instanceOf(Storage) |
| 95 | + const bucket: Bucket = storage.bucket('TestBucket'); |
| 96 | + expect(bucket.name).to.equal('TestBucket'); |
| 97 | + }); |
| 98 | + |
| 99 | + it('Should return a Firestore client', () => { |
| 100 | + const firestore = getFirestore(app); |
| 101 | + expect(firestore).to.be.instanceOf(Firestore); |
| 102 | + }); |
| 103 | + |
| 104 | + it('Should return a Firestore FieldValue', () => { |
| 105 | + expect(FieldValue.increment(1)).to.be.not.undefined; |
| 106 | + }); |
| 107 | + |
| 108 | + it('Should return a DocumentReference', () => { |
| 109 | + const ref = getFirestore(app).collection('test').doc(); |
| 110 | + expect(ref).to.be.instanceOf(DocumentReference); |
| 111 | + }); |
| 112 | + |
| 113 | + it('Should return an InstanceId client', () => { |
| 114 | + const client = getInstanceId(app); |
| 115 | + expect(client).to.be.instanceOf(InstanceId); |
| 116 | + }); |
| 117 | + |
| 118 | + it('Should return a MachineLearning client', () => { |
| 119 | + const client = getMachineLearning(app); |
| 120 | + expect(client).to.be.instanceOf(MachineLearning); |
| 121 | + }); |
| 122 | + |
| 123 | + it('Should return a RemoteConfig client', () => { |
| 124 | + const client = getRemoteConfig(app); |
| 125 | + expect(client).to.be.instanceOf(RemoteConfig); |
| 126 | + }); |
| 127 | +}); |
0 commit comments