Skip to content

Commit 99cca66

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

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-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: 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)