Skip to content

Commit 3841cee

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

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

spec/providers/database.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,25 @@ 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(
40+
'https://not-a-project.firebaseio.com/path'
41+
);
42+
});
43+
44+
it('should allow different DB instance to be specified in makeDataSnapshot', async () => {
45+
const snapshot = makeDataSnapshot(
46+
null,
47+
'path',
48+
null,
49+
'https://another-instance.firebaseio.com'
50+
);
51+
52+
expect(snapshot.ref.toString()).to.equal(
53+
'https://another-instance.firebaseio.com/path'
54+
);
55+
});
3556
});

src/providers/database.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ 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+
/**
41+
* The RTDB instance to use when creating snapshot. This will override the `firebaseApp` parameter.
42+
* If omitted the default RTDB instance is used.
43+
*/
44+
instance?: string
4045
): database.DataSnapshot {
4146
return new database.DataSnapshot(
4247
val,
4348
refPath,
44-
firebaseApp || testApp().getApp()
49+
firebaseApp || testApp().getApp(),
50+
instance
4551
);
4652
}
4753

0 commit comments

Comments
 (0)