@@ -152,6 +152,44 @@ describe('Testing Module Tests', function () {
152
152
) ;
153
153
} ) ;
154
154
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
+
155
193
it ( 'loadDatabaseRules() throws if no databaseName or rules' , async function ( ) {
156
194
// eslint-disable-next-line @typescript-eslint/no-explicit-any
157
195
await expect ( ( firebase as any ) . loadDatabaseRules . bind ( null , { } ) ) . to . throw (
0 commit comments