diff --git a/src/index.d.ts b/src/index.d.ts index 76c49c4292..4fa9f5548e 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -303,6 +303,8 @@ declare namespace admin.database { export import enableLogging = _rtdb.enableLogging; export import OnDisconnect = _rtdb.OnDisconnect; export import DataSnapshot = _rtdb.DataSnapshot; + + type EventType = 'value' | 'child_added' | 'child_changed' | 'child_moved' | 'child_removed'; } declare namespace admin.firestore { diff --git a/test/integration/database.js b/test/integration/database.js index 61b4769e8e..5aec3a3763 100644 --- a/test/integration/database.js +++ b/test/integration/database.js @@ -49,6 +49,23 @@ function test(utils) { }); } + function testDatabaseWithUrl() { + let app = admin.app() + let url = app.options.databaseURL; + let refFromApp = app.database(url).ref(ref.path); + return refFromApp.once('value') + .then((snapshot) => { + var value = snapshot.val(); + utils.assert( + value.success === true && typeof value.timestamp === 'number', + 'app.database(url).ref().once()', + 'Snapshot has unexpected value' + ); + }).catch((error) => { + utils.logFailure('app.database(url).ref().once()', error) + }); + } + function testChild() { return ref.child('timestamp').once('value') .then((snapshot) => { @@ -74,6 +91,7 @@ function test(utils) { return Promise.resolve() .then(testSet) .then(testOnce) + .then(testDatabaseWithUrl) .then(testChild) .then(testRemove); }; diff --git a/test/integration/typescript/src/example.test.ts b/test/integration/typescript/src/example.test.ts index b30f3d05c4..8f345bf113 100644 --- a/test/integration/typescript/src/example.test.ts +++ b/test/integration/typescript/src/example.test.ts @@ -34,6 +34,12 @@ describe('Init App', () => { const db = admin.database(app); expect(db).to.be.instanceOf(admin.database.Database); }); + + it('Should return a Database client for URL', () => { + const db = app.database('https://other-mock.firebaseio.com'); + expect(db).to.be.instanceOf(admin.database.Database); + }); + it('Should return a Database ServerValue', () => { const serverValue = admin.database.ServerValue; expect(serverValue).to.not.be.null; @@ -48,10 +54,12 @@ describe('Init App', () => { const firestore: Firestore = app.firestore(); expect(firestore).to.be.instanceOf(admin.firestore.Firestore); }); + it('Should return a Firestore client', () => { const firestore: Firestore = admin.firestore(app); expect(firestore).to.be.instanceOf(admin.firestore.Firestore); }); + it('Should return a Firestore FieldValue', () => { const fieldValue = admin.firestore.FieldValue; expect(fieldValue).to.not.be.null; diff --git a/test/integration/typescript/src/example.ts b/test/integration/typescript/src/example.ts index 7afb401d60..0de5332cc2 100644 --- a/test/integration/typescript/src/example.ts +++ b/test/integration/typescript/src/example.ts @@ -23,4 +23,12 @@ export function initApp(serviceAcct: any, name: string) { }, name); } -export default initApp; \ No newline at end of file +export function addValueEventListener( + // Check for type compilation + db: firebase.database.Database, + callback: (s: firebase.database.DataSnapshot) => any) { + let eventType: firebase.database.EventType = 'value'; + db.ref().on(eventType, callback); +} + +export default initApp; diff --git a/test/unit/firebase-app.spec.ts b/test/unit/firebase-app.spec.ts index a34e85fb90..85359a2e1e 100644 --- a/test/unit/firebase-app.spec.ts +++ b/test/unit/firebase-app.spec.ts @@ -283,7 +283,9 @@ describe('FirebaseApp', () => { const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName); const db1: Database = app.database(); const db2: Database = app.database(); + const db3: Database = app.database(mocks.appOptions.databaseURL); expect(db1).to.equal(db2); + expect(db1).to.equal(db3); expect(db1.ref().toString()).to.equal('https://databasename.firebaseio.com/'); });