Skip to content

Commit c2b10d3

Browse files
committed
Fix RUTv2 not setting RTDB namespace by default.
1 parent 20d10b3 commit c2b10d3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/rules-unit-testing/src/impl/test_environment.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,14 @@ class RulesTestContextImpl implements RulesTestContext {
192192
}
193193
database(databaseURL?: string): firebase.database.Database {
194194
assertEmulatorRunning(this.emulators, 'database');
195+
if (!databaseURL) {
196+
const url = makeUrl(this.emulators.database, '');
197+
// Make sure to set the namespace equal to projectId -- otherwise the RTDB SDK will by default
198+
// use `${projectId}-default-rtdb`, which is treated as a different DB by the RTDB emulator
199+
// (and thus WON'T apply any rules set for the `projectId` DB during initialization).
200+
url.searchParams.append('ns', this.projectId);
201+
databaseURL = url.toString();
202+
}
195203
const database = this.getApp().database(databaseURL);
196204
database.useEmulator(
197205
this.emulators.database.host,

0 commit comments

Comments
 (0)