Skip to content

A Few Additional Tests for RTDB Support #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Nov 8, 2017
2 changes: 2 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions test/integration/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -74,6 +91,7 @@ function test(utils) {
return Promise.resolve()
.then(testSet)
.then(testOnce)
.then(testDatabaseWithUrl)
.then(testChild)
.then(testRemove);
};
Expand Down
8 changes: 8 additions & 0 deletions test/integration/typescript/src/example.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion test/integration/typescript/src/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ export function initApp(serviceAcct: any, name: string) {
}, name);
}

export default initApp;
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;
2 changes: 2 additions & 0 deletions test/unit/firebase-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/');
});

Expand Down