@@ -24,11 +24,14 @@ import {
2424 child ,
2525 get ,
2626 limitToFirst ,
27+ onChildAdded ,
2728 onValue ,
29+ orderByChild ,
2830 query ,
2931 refFromURL ,
3032 set ,
3133 startAt ,
34+ update ,
3235 orderByKey
3336} from '../../src/api/Reference_impl' ;
3437import {
@@ -117,6 +120,54 @@ describe('Database@exp Tests', () => {
117120 unsubscribe ( ) ;
118121 } ) ;
119122
123+ it ( 'can properly handle unknown deep merges' , async ( ) => {
124+ // Note: This test requires `testIndex` to be added as an index.
125+ // Please run `yarn test:setup` to ensure that this gets added.
126+ const database = getDatabase ( defaultApp ) ;
127+ const root = ref ( database , 'testing' ) ;
128+ await set ( root , { } ) ;
129+
130+ const q = query ( root , orderByChild ( 'testIndex' ) , limitToFirst ( 2 ) ) ;
131+
132+ const i1 = child ( root , 'i1' ) ;
133+ await set ( root , {
134+ i1 : {
135+ testIndex : 3 ,
136+ timestamp : Date . now ( ) ,
137+ action : 'test'
138+ } ,
139+ i2 : {
140+ testIndex : 1 ,
141+ timestamp : Date . now ( ) ,
142+ action : 'test'
143+ } ,
144+ i3 : {
145+ testIndex : 2 ,
146+ timestamp : Date . now ( ) ,
147+ action : 'test'
148+ }
149+ } ) ;
150+ const ec = EventAccumulatorFactory . waitsForExactCount ( 2 ) ;
151+ const onChildAddedCb = onChildAdded ( q , snap => {
152+ ec . addEvent ( snap ) ;
153+ } ) ;
154+ const onValueCb = onValue ( i1 , ( ) => {
155+ //no-op
156+ } ) ;
157+ await update ( i1 , {
158+ timestamp : `${ Date . now ( ) } |1`
159+ } ) ;
160+ const results = await ec . promise ;
161+ results . forEach ( result => {
162+ const value = result . val ( ) ;
163+ expect ( value ) . to . haveOwnProperty ( 'timestamp' ) ;
164+ expect ( value ) . to . haveOwnProperty ( 'action' ) ;
165+ expect ( value ) . to . haveOwnProperty ( 'testIndex' ) ;
166+ } ) ;
167+ onChildAddedCb ( ) ;
168+ onValueCb ( ) ;
169+ } ) ;
170+
120171 // Tests to make sure onValue's data does not get mutated after calling get
121172 it ( 'calls onValue only once after get request with a non-default query' , async ( ) => {
122173 const { readerRef } = getRWRefs ( getDatabase ( defaultApp ) ) ;
0 commit comments