Skip to content

Commit c142c56

Browse files
committed
Add new unit test
1 parent 61e652d commit c142c56

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

packages/rules-unit-testing/test/database.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,44 @@ describe('Testing Module Tests', function () {
152152
);
153153
});
154154

155+
it('initializeAdminApp() and initializeTestApp() work together', async function () {
156+
await firebase.loadDatabaseRules({
157+
databaseName: 'foo',
158+
rules: JSON.stringify({
159+
'rules': {
160+
'public': { '.read': true, '.write': true },
161+
'private': { '.read': false, '.write': false }
162+
}
163+
})
164+
});
165+
166+
const adminApp = firebase.initializeAdminApp({
167+
projectId: 'foo',
168+
databaseName: 'foo'
169+
});
170+
171+
const testApp = firebase.initializeTestApp({
172+
projectId: 'foo',
173+
databaseName: 'foo'
174+
});
175+
176+
// Admin app can write anywhere
177+
await firebase.assertSucceeds(
178+
adminApp.database().ref().child('/public/doc').set({ hello: 'admin' })
179+
);
180+
await firebase.assertSucceeds(
181+
adminApp.database().ref().child('/private/doc').set({ hello: 'admin' })
182+
);
183+
184+
// Test app can only write to public, not to private
185+
await firebase.assertSucceeds(
186+
testApp.database().ref().child('/public/doc').set({ hello: 'test' })
187+
);
188+
await firebase.assertFails(
189+
testApp.database().ref().child('/private/doc').set({ hello: 'test' })
190+
);
191+
});
192+
155193
it('loadDatabaseRules() throws if no databaseName or rules', async function () {
156194
// eslint-disable-next-line @typescript-eslint/no-explicit-any
157195
await expect((firebase as any).loadDatabaseRules.bind(null, {})).to.throw(

0 commit comments

Comments
 (0)