@@ -241,24 +241,19 @@ class LocalStoreTester {
241
241
242
242
afterAcknowledgingMutation ( options : {
243
243
documentVersion : TestSnapshotVersion ;
244
- transformResult ?: api . Value ;
244
+ transformResults ?: api . Value [ ] ;
245
245
} ) : LocalStoreTester {
246
246
this . prepareNextStep ( ) ;
247
247
248
248
this . promiseChain = this . promiseChain
249
249
. then ( ( ) => {
250
250
const batch = this . batches . shift ( ) ! ;
251
- expect ( batch . mutations . length ) . to . equal (
252
- 1 ,
253
- 'Acknowledging more than one mutation not supported.'
254
- ) ;
255
251
const ver = version ( options . documentVersion ) ;
256
- const mutationResults = [
257
- new MutationResult (
258
- ver ,
259
- options . transformResult ? [ options . transformResult ] : [ ]
260
- )
261
- ] ;
252
+ const mutationResults = options . transformResults
253
+ ? options . transformResults . map (
254
+ value => new MutationResult ( ver , [ value ] )
255
+ )
256
+ : [ new MutationResult ( ver , [ ] ) ] ;
262
257
const write = MutationBatchResult . from ( batch , ver , mutationResults ) ;
263
258
264
259
return localStoreAcknowledgeBatch ( this . localStore , write ) ;
@@ -801,7 +796,7 @@ function genericLocalStoreTests(
801
796
return expectLocalStore ( )
802
797
. after ( deleteMutation ( 'foo/bar' ) )
803
798
. toReturnRemoved ( 'foo/bar' )
804
- . toContain ( deletedDoc ( 'foo/bar' , 0 ) )
799
+ . toContain ( deletedDoc ( 'foo/bar' , 0 ) . setHasLocalMutations ( ) )
805
800
. afterAcknowledgingMutation ( { documentVersion : 1 } )
806
801
. toReturnRemoved ( 'foo/bar' )
807
802
. toNotContainIfEager ( deletedDoc ( 'foo/bar' , 1 ) . setHasCommittedMutations ( ) )
@@ -819,7 +814,7 @@ function genericLocalStoreTests(
819
814
. toContain ( doc ( 'foo/bar' , 1 , { it : 'base' } ) )
820
815
. after ( deleteMutation ( 'foo/bar' ) )
821
816
. toReturnRemoved ( 'foo/bar' )
822
- . toContain ( deletedDoc ( 'foo/bar' , 0 ) )
817
+ . toContain ( deletedDoc ( 'foo/bar' , 0 ) . setHasLocalMutations ( ) )
823
818
// remove the mutation so only the mutation is pinning the doc
824
819
. afterReleasingTarget ( 2 )
825
820
. afterAcknowledgingMutation ( { documentVersion : 2 } )
@@ -839,10 +834,10 @@ function genericLocalStoreTests(
839
834
. toReturnTargetId ( 2 )
840
835
. after ( deleteMutation ( 'foo/bar' ) )
841
836
. toReturnRemoved ( 'foo/bar' )
842
- . toContain ( deletedDoc ( 'foo/bar' , 0 ) )
837
+ . toContain ( deletedDoc ( 'foo/bar' , 0 ) . setHasLocalMutations ( ) )
843
838
. after ( docUpdateRemoteEvent ( doc ( 'foo/bar' , 1 , { it : 'base' } ) , [ 2 ] ) )
844
839
. toReturnRemoved ( 'foo/bar' )
845
- . toContain ( deletedDoc ( 'foo/bar' , 0 ) )
840
+ . toContain ( deletedDoc ( 'foo/bar' , 0 ) . setHasLocalMutations ( ) )
846
841
// Don't need to keep doc pinned anymore
847
842
. afterReleasingTarget ( 2 )
848
843
. afterAcknowledgingMutation ( { documentVersion : 2 } )
@@ -948,10 +943,10 @@ function genericLocalStoreTests(
948
943
return expectLocalStore ( )
949
944
. after ( deleteMutation ( 'foo/bar' ) )
950
945
. toReturnRemoved ( 'foo/bar' )
951
- . toContain ( deletedDoc ( 'foo/bar' , 0 ) )
946
+ . toContain ( deletedDoc ( 'foo/bar' , 0 ) . setHasLocalMutations ( ) )
952
947
. after ( patchMutation ( 'foo/bar' , { foo : 'bar' } ) )
953
948
. toReturnRemoved ( 'foo/bar' )
954
- . toContain ( deletedDoc ( 'foo/bar' , 0 ) )
949
+ . toContain ( deletedDoc ( 'foo/bar' , 0 ) . setHasLocalMutations ( ) )
955
950
. afterAcknowledgingMutation ( { documentVersion : 2 } ) // delete mutation
956
951
. toReturnRemoved ( 'foo/bar' )
957
952
. toContain ( deletedDoc ( 'foo/bar' , 2 ) . setHasCommittedMutations ( ) )
@@ -1007,15 +1002,15 @@ function genericLocalStoreTests(
1007
1002
. after ( deleteMutation ( 'foo/baz' ) )
1008
1003
. toContain ( doc ( 'foo/bar' , 1 , { foo : 'bar' } ) . setHasLocalMutations ( ) )
1009
1004
. toContain ( doc ( 'foo/bah' , 0 , { foo : 'bah' } ) . setHasLocalMutations ( ) )
1010
- . toContain ( deletedDoc ( 'foo/baz' , 0 ) )
1005
+ . toContain ( deletedDoc ( 'foo/baz' , 0 ) . setHasLocalMutations ( ) )
1011
1006
. afterAcknowledgingMutation ( { documentVersion : 3 } )
1012
1007
. toNotContain ( 'foo/bar' )
1013
1008
. toContain ( doc ( 'foo/bah' , 0 , { foo : 'bah' } ) . setHasLocalMutations ( ) )
1014
- . toContain ( deletedDoc ( 'foo/baz' , 0 ) )
1009
+ . toContain ( deletedDoc ( 'foo/baz' , 0 ) . setHasLocalMutations ( ) )
1015
1010
. afterAcknowledgingMutation ( { documentVersion : 4 } )
1016
1011
. toNotContain ( 'foo/bar' )
1017
1012
. toNotContain ( 'foo/bah' )
1018
- . toContain ( deletedDoc ( 'foo/baz' , 0 ) )
1013
+ . toContain ( deletedDoc ( 'foo/baz' , 0 ) . setHasLocalMutations ( ) )
1019
1014
. afterAcknowledgingMutation ( { documentVersion : 5 } )
1020
1015
. toNotContain ( 'foo/bar' )
1021
1016
. toNotContain ( 'foo/bah' )
@@ -1041,15 +1036,15 @@ function genericLocalStoreTests(
1041
1036
. after ( deleteMutation ( 'foo/baz' ) )
1042
1037
. toContain ( doc ( 'foo/bar' , 1 , { foo : 'bar' } ) . setHasLocalMutations ( ) )
1043
1038
. toContain ( doc ( 'foo/bah' , 0 , { foo : 'bah' } ) . setHasLocalMutations ( ) )
1044
- . toContain ( deletedDoc ( 'foo/baz' , 0 ) )
1039
+ . toContain ( deletedDoc ( 'foo/baz' , 0 ) . setHasLocalMutations ( ) )
1045
1040
. afterRejectingMutation ( ) // patch mutation
1046
1041
. toNotContain ( 'foo/bar' )
1047
1042
. toContain ( doc ( 'foo/bah' , 0 , { foo : 'bah' } ) . setHasLocalMutations ( ) )
1048
- . toContain ( deletedDoc ( 'foo/baz' , 0 ) )
1043
+ . toContain ( deletedDoc ( 'foo/baz' , 0 ) . setHasLocalMutations ( ) )
1049
1044
. afterRejectingMutation ( ) // set mutation
1050
1045
. toNotContain ( 'foo/bar' )
1051
1046
. toNotContain ( 'foo/bah' )
1052
- . toContain ( deletedDoc ( 'foo/baz' , 0 ) )
1047
+ . toContain ( deletedDoc ( 'foo/baz' , 0 ) . setHasLocalMutations ( ) )
1053
1048
. afterRejectingMutation ( ) // delete mutation
1054
1049
. toNotContain ( 'foo/bar' )
1055
1050
. toNotContain ( 'foo/bah' )
@@ -1181,36 +1176,40 @@ function genericLocalStoreTests(
1181
1176
const firstQuery = query ( 'foo' ) ;
1182
1177
const secondQuery = query ( 'foo' , filter ( 'matches' , '==' , true ) ) ;
1183
1178
1184
- return expectLocalStore ( )
1185
- . afterAllocatingQuery ( firstQuery )
1186
- . toReturnTargetId ( 2 )
1187
- . after (
1188
- docAddedRemoteEvent (
1189
- [
1190
- doc ( 'foo/bar' , 10 , { matches : true } ) ,
1191
- doc ( 'foo/baz' , 20 , { matches : true } )
1192
- ] ,
1193
- [ 2 ]
1179
+ return (
1180
+ expectLocalStore ( )
1181
+ . afterAllocatingQuery ( firstQuery )
1182
+ . toReturnTargetId ( 2 )
1183
+ . after (
1184
+ docAddedRemoteEvent (
1185
+ [
1186
+ doc ( 'foo/bar' , 10 , { matches : true } ) ,
1187
+ doc ( 'foo/baz' , 20 , { matches : true } )
1188
+ ] ,
1189
+ [ 2 ]
1190
+ )
1194
1191
)
1195
- )
1196
- . toReturnChanged (
1197
- doc ( 'foo/bar' , 10 , { matches : true } ) ,
1198
- doc ( 'foo/baz' , 20 , { matches : true } )
1199
- )
1200
- . after ( setMutation ( 'foo/bonk' , { matches : true } ) )
1201
- . toReturnChanged (
1202
- doc ( 'foo/bonk' , 0 , { matches : true } ) . setHasLocalMutations ( )
1203
- )
1204
- . afterAllocatingQuery ( secondQuery )
1205
- . toReturnTargetId ( 4 )
1206
- . afterExecutingQuery ( secondQuery )
1207
- . toReturnChanged (
1208
- doc ( 'foo/bar' , 10 , { matches : true } ) ,
1209
- doc ( 'foo/baz' , 20 , { matches : true } ) ,
1210
- doc ( 'foo/bonk' , 0 , { matches : true } ) . setHasLocalMutations ( )
1211
- )
1212
- . toHaveRead ( { documentsByCollection : 2 , mutationsByCollection : 1 } )
1213
- . finish ( ) ;
1192
+ . toReturnChanged (
1193
+ doc ( 'foo/bar' , 10 , { matches : true } ) ,
1194
+ doc ( 'foo/baz' , 20 , { matches : true } )
1195
+ )
1196
+ . after ( setMutation ( 'foo/bonk' , { matches : true } ) )
1197
+ . toReturnChanged (
1198
+ doc ( 'foo/bonk' , 0 , { matches : true } ) . setHasLocalMutations ( )
1199
+ )
1200
+ . afterAllocatingQuery ( secondQuery )
1201
+ . toReturnTargetId ( 4 )
1202
+ . afterExecutingQuery ( secondQuery )
1203
+ . toReturnChanged (
1204
+ doc ( 'foo/bar' , 10 , { matches : true } ) ,
1205
+ doc ( 'foo/baz' , 20 , { matches : true } ) ,
1206
+ doc ( 'foo/bonk' , 0 , { matches : true } ) . setHasLocalMutations ( )
1207
+ )
1208
+ // TODO(overlays): implement overlaysReadByKey and overlaysReadByCollection
1209
+ // No mutations are read because only overlay is needed.
1210
+ . toHaveRead ( { documentsByCollection : 2 , mutationsByCollection : 0 } )
1211
+ . finish ( )
1212
+ ) ;
1214
1213
} ) ;
1215
1214
1216
1215
// eslint-disable-next-line no-restricted-properties
@@ -1340,7 +1339,7 @@ function genericLocalStoreTests(
1340
1339
. toContain ( doc ( 'foo/bar' , 1 , { sum : 1 } ) . setHasLocalMutations ( ) )
1341
1340
. afterAcknowledgingMutation ( {
1342
1341
documentVersion : 2 ,
1343
- transformResult : { integerValue : 1 }
1342
+ transformResults : [ { integerValue : 1 } ]
1344
1343
} )
1345
1344
. toReturnChanged (
1346
1345
doc ( 'foo/bar' , 2 , { sum : 1 } ) . setHasCommittedMutations ( )
@@ -1385,13 +1384,13 @@ function genericLocalStoreTests(
1385
1384
. toContain ( doc ( 'foo/bar' , 2 , { sum : 3 } ) . setHasLocalMutations ( ) )
1386
1385
. afterAcknowledgingMutation ( {
1387
1386
documentVersion : 3 ,
1388
- transformResult : { integerValue : 1 }
1387
+ transformResults : [ { integerValue : 1 } ]
1389
1388
} )
1390
1389
. toReturnChanged ( doc ( 'foo/bar' , 3 , { sum : 3 } ) . setHasLocalMutations ( ) )
1391
1390
. toContain ( doc ( 'foo/bar' , 3 , { sum : 3 } ) . setHasLocalMutations ( ) )
1392
1391
. afterAcknowledgingMutation ( {
1393
1392
documentVersion : 4 ,
1394
- transformResult : { integerValue : 1339 }
1393
+ transformResults : [ { integerValue : 1339 } ]
1395
1394
} )
1396
1395
. toReturnChanged (
1397
1396
doc ( 'foo/bar' , 4 , { sum : 1339 } ) . setHasCommittedMutations ( )
@@ -1452,9 +1451,28 @@ function genericLocalStoreTests(
1452
1451
. toReturnChanged (
1453
1452
doc ( 'foo/bar' , 2 , {
1454
1453
sum : 1 ,
1455
- arrayUnion : [ 'bar' , ' foo']
1454
+ arrayUnion : [ 'foo' ]
1456
1455
} ) . setHasLocalMutations ( )
1457
1456
)
1457
+ . afterAcknowledgingMutation ( {
1458
+ documentVersion : 3 ,
1459
+ transformResults : [
1460
+ { integerValue : 1338 } ,
1461
+ {
1462
+ arrayValue : {
1463
+ values : [ { stringValue : 'bar' } , { stringValue : 'foo' } ]
1464
+ }
1465
+ }
1466
+ ]
1467
+ } )
1468
+ . toReturnChanged (
1469
+ doc ( 'foo/bar' , 3 , {
1470
+ sum : 1338 ,
1471
+ arrayUnion : [ 'bar' , 'foo' ]
1472
+ } )
1473
+ . setReadTime ( SnapshotVersion . fromTimestamp ( new Timestamp ( 0 , 3000 ) ) )
1474
+ . setHasCommittedMutations ( )
1475
+ )
1458
1476
. finish ( )
1459
1477
) ;
1460
1478
} ) ;
0 commit comments