Skip to content

Allow RTDB instance to be specified when using makeDataSnapshot #70

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 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions spec/providers/database.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,25 @@ describe('providers/database', () => {
expect(snapshot.val()).to.deep.equal(null);
expect(snapshot.ref.key).to.equal('path');
});

it('should use the default test apps databaseURL if no instance is specified in makeDataSnapshot', async () => {
const snapshot = makeDataSnapshot(null, 'path', null);

expect(snapshot.ref.toString()).to.equal(
'https://not-a-project.firebaseio.com/path'
);
});

it('should allow different DB instance to be specified in makeDataSnapshot', async () => {
const snapshot = makeDataSnapshot(
null,
'path',
null,
'https://another-instance.firebaseio.com'
);

expect(snapshot.ref.toString()).to.equal(
'https://another-instance.firebaseio.com/path'
);
});
});
10 changes: 8 additions & 2 deletions src/providers/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,18 @@ export function makeDataSnapshot(
* You do not need to supply this parameter if you supplied Firebase config values when initializing
* firebase-functions-test.
*/
firebaseApp?: app.App
firebaseApp?: app.App,
/**
* The RTDB instance to use when creating snapshot. This will override the `firebaseApp` parameter.
* If omitted the default RTDB instance is used.
*/
instance?: string
): database.DataSnapshot {
return new database.DataSnapshot(
val,
refPath,
firebaseApp || testApp().getApp()
firebaseApp || testApp().getApp(),
instance
);
}

Expand Down