@@ -24,11 +24,14 @@ import {
24
24
child ,
25
25
get ,
26
26
limitToFirst ,
27
+ onChildAdded ,
27
28
onValue ,
29
+ orderByChild ,
28
30
query ,
29
31
refFromURL ,
30
32
set ,
31
33
startAt ,
34
+ update ,
32
35
orderByKey
33
36
} from '../../src/api/Reference_impl' ;
34
37
import {
@@ -117,6 +120,54 @@ describe('Database@exp Tests', () => {
117
120
unsubscribe ( ) ;
118
121
} ) ;
119
122
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
+
120
171
// Tests to make sure onValue's data does not get mutated after calling get
121
172
it ( 'calls onValue only once after get request with a non-default query' , async ( ) => {
122
173
const { readerRef } = getRWRefs ( getDatabase ( defaultApp ) ) ;
0 commit comments