Skip to content

Commit 575d1af

Browse files
committed
Allow RTDB instance to be specified when using makeDataSnapshot
1 parent de23c0f commit 575d1af

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

spec/providers/database.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,16 @@ describe('providers/database', () => {
3232
expect(snapshot.val()).to.deep.equal(null);
3333
expect(snapshot.ref.key).to.equal('path');
3434
});
35+
36+
it('should use the default test apps databaseURL if no instance is specified in makeDataSnapshot', async () => {
37+
const snapshot = makeDataSnapshot(null, 'path', null);
38+
39+
expect(snapshot.ref.toString()).to.equal('https://not-a-project.firebaseio.com/path');
40+
});
41+
42+
it('should allow different DB instance to be specified in makeDataSnapshot', async () => {
43+
const snapshot = makeDataSnapshot(null, 'path', null, 'https://another-instance.firebaseio.com');
44+
45+
expect(snapshot.ref.toString()).to.equal('https://another-instance.firebaseio.com/path');
46+
});
3547
});

src/providers/database.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ export function makeDataSnapshot(
3636
* You do not need to supply this parameter if you supplied Firebase config values when initializing
3737
* firebase-functions-test.
3838
*/
39-
firebaseApp?: app.App
39+
firebaseApp?: app.App,
40+
/** The RTDB instance to use when creating snapshot. This will override the `firebaseApp` parameter. */
41+
instance?: string
4042
): database.DataSnapshot {
4143
return new database.DataSnapshot(
4244
val,
4345
refPath,
44-
firebaseApp || testApp().getApp()
46+
firebaseApp || testApp().getApp(),
47+
instance
4548
);
4649
}
4750

0 commit comments

Comments
 (0)