Skip to content

Commit a8e5b96

Browse files
authored
A Few Additional Tests for RTDB Support (#131)
* Importing RTDB code via @firebase/database * Further tests and code cleanup * More tests and code clean up * Upgraded to @firebase/database 0.1.3 * Fixing initStandalone import * Code cleanup * Minor improvements to test * Updated type definition for multi DB support * Adding some more sanity checks and type defs * Adding NL at the end of file
1 parent 2353966 commit a8e5b96

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

src/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ declare namespace admin.database {
303303
export import enableLogging = _rtdb.enableLogging;
304304
export import OnDisconnect = _rtdb.OnDisconnect;
305305
export import DataSnapshot = _rtdb.DataSnapshot;
306+
307+
type EventType = 'value' | 'child_added' | 'child_changed' | 'child_moved' | 'child_removed';
306308
}
307309

308310
declare namespace admin.firestore {

test/integration/database.js

+18
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,23 @@ function test(utils) {
4949
});
5050
}
5151

52+
function testDatabaseWithUrl() {
53+
let app = admin.app()
54+
let url = app.options.databaseURL;
55+
let refFromApp = app.database(url).ref(ref.path);
56+
return refFromApp.once('value')
57+
.then((snapshot) => {
58+
var value = snapshot.val();
59+
utils.assert(
60+
value.success === true && typeof value.timestamp === 'number',
61+
'app.database(url).ref().once()',
62+
'Snapshot has unexpected value'
63+
);
64+
}).catch((error) => {
65+
utils.logFailure('app.database(url).ref().once()', error)
66+
});
67+
}
68+
5269
function testChild() {
5370
return ref.child('timestamp').once('value')
5471
.then((snapshot) => {
@@ -74,6 +91,7 @@ function test(utils) {
7491
return Promise.resolve()
7592
.then(testSet)
7693
.then(testOnce)
94+
.then(testDatabaseWithUrl)
7795
.then(testChild)
7896
.then(testRemove);
7997
};

test/integration/typescript/src/example.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ describe('Init App', () => {
3434
const db = admin.database(app);
3535
expect(db).to.be.instanceOf(admin.database.Database);
3636
});
37+
38+
it('Should return a Database client for URL', () => {
39+
const db = app.database('https://other-mock.firebaseio.com');
40+
expect(db).to.be.instanceOf(admin.database.Database);
41+
});
42+
3743
it('Should return a Database ServerValue', () => {
3844
const serverValue = admin.database.ServerValue;
3945
expect(serverValue).to.not.be.null;
@@ -48,10 +54,12 @@ describe('Init App', () => {
4854
const firestore: Firestore = app.firestore();
4955
expect(firestore).to.be.instanceOf(admin.firestore.Firestore);
5056
});
57+
5158
it('Should return a Firestore client', () => {
5259
const firestore: Firestore = admin.firestore(app);
5360
expect(firestore).to.be.instanceOf(admin.firestore.Firestore);
5461
});
62+
5563
it('Should return a Firestore FieldValue', () => {
5664
const fieldValue = admin.firestore.FieldValue;
5765
expect(fieldValue).to.not.be.null;

test/integration/typescript/src/example.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ export function initApp(serviceAcct: any, name: string) {
2323
}, name);
2424
}
2525

26-
export default initApp;
26+
export function addValueEventListener(
27+
// Check for type compilation
28+
db: firebase.database.Database,
29+
callback: (s: firebase.database.DataSnapshot) => any) {
30+
let eventType: firebase.database.EventType = 'value';
31+
db.ref().on(eventType, callback);
32+
}
33+
34+
export default initApp;

test/unit/firebase-app.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ describe('FirebaseApp', () => {
283283
const app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName);
284284
const db1: Database = app.database();
285285
const db2: Database = app.database();
286+
const db3: Database = app.database(mocks.appOptions.databaseURL);
286287
expect(db1).to.equal(db2);
288+
expect(db1).to.equal(db3);
287289
expect(db1.ref().toString()).to.equal('https://databasename.firebaseio.com/');
288290
});
289291

0 commit comments

Comments
 (0)