@@ -58,25 +58,25 @@ describe('Mutation', () => {
58
58
59
59
it ( 'can apply sets to documents' , ( ) => {
60
60
const docData = { foo : 'foo-value' , baz : 'baz-value' } ;
61
- const baseDoc = doc ( 'collection/key' , 0 , docData ) ;
61
+ const document = doc ( 'collection/key' , 0 , docData ) ;
62
62
63
63
const set = setMutation ( 'collection/key' , { bar : 'bar-value' } ) ;
64
- const setDoc = applyMutationToLocalView ( set , baseDoc , timestamp ) ;
65
- expect ( setDoc ) . to . deep . equal (
64
+ applyMutationToLocalView ( set , document , timestamp ) ;
65
+ expect ( document ) . to . deep . equal (
66
66
doc ( 'collection/key' , 0 , { bar : 'bar-value' } ) . setHasLocalMutations ( )
67
67
) ;
68
68
} ) ;
69
69
70
70
it ( 'can apply patches to documents' , ( ) => {
71
71
const docData = { foo : { bar : 'bar-value' } , baz : 'baz-value' } ;
72
72
73
- const baseDoc = doc ( 'collection/key' , 0 , docData ) ;
73
+ const document = doc ( 'collection/key' , 0 , docData ) ;
74
74
const patch = patchMutation ( 'collection/key' , {
75
75
'foo.bar' : 'new-bar-value'
76
76
} ) ;
77
77
78
- const patchedDoc = applyMutationToLocalView ( patch , baseDoc , timestamp ) ;
79
- expect ( patchedDoc ) . to . deep . equal (
78
+ applyMutationToLocalView ( patch , document , timestamp ) ;
79
+ expect ( document ) . to . deep . equal (
80
80
doc ( 'collection/key' , 0 , {
81
81
foo : { bar : 'new-bar-value' } ,
82
82
baz : 'baz-value'
@@ -87,15 +87,15 @@ describe('Mutation', () => {
87
87
it ( 'can apply patches with merges to missing documents' , ( ) => {
88
88
const timestamp = Timestamp . now ( ) ;
89
89
90
- const baseDoc = deletedDoc ( 'collection/key' , 0 ) ;
90
+ const document = deletedDoc ( 'collection/key' , 0 ) ;
91
91
const patch = patchMutation (
92
92
'collection/key' ,
93
93
{ 'foo.bar' : 'new-bar-value' } ,
94
94
Precondition . none ( )
95
95
) ;
96
96
97
- const patchedDoc = applyMutationToLocalView ( patch , baseDoc , timestamp ) ;
98
- expect ( patchedDoc ) . to . deep . equal (
97
+ applyMutationToLocalView ( patch , document , timestamp ) ;
98
+ expect ( document ) . to . deep . equal (
99
99
doc ( 'collection/key' , 0 , {
100
100
foo : { bar : 'new-bar-value' }
101
101
} ) . setHasLocalMutations ( )
@@ -105,48 +105,48 @@ describe('Mutation', () => {
105
105
it ( 'can apply patches with merges to null documents' , ( ) => {
106
106
const timestamp = Timestamp . now ( ) ;
107
107
108
- const baseDoc = MutableDocument . newInvalidDocument ( key ( 'collection/key' ) ) ;
108
+ const document = MutableDocument . newInvalidDocument ( key ( 'collection/key' ) ) ;
109
109
const patch = patchMutation (
110
110
'collection/key' ,
111
111
{ 'foo.bar' : 'new-bar-value' } ,
112
112
Precondition . none ( )
113
113
) ;
114
114
115
- const patchedDoc = applyMutationToLocalView ( patch , baseDoc , timestamp ) ;
116
- expect ( patchedDoc ) . to . deep . equal (
115
+ applyMutationToLocalView ( patch , document , timestamp ) ;
116
+ expect ( document ) . to . deep . equal (
117
117
doc ( 'collection/key' , 0 , {
118
118
foo : { bar : 'new-bar-value' }
119
119
} ) . setHasLocalMutations ( )
120
120
) ;
121
121
} ) ;
122
122
123
123
it ( 'will delete values from the field-mask' , ( ) => {
124
- const baseDoc = doc ( 'collection/key' , 0 , {
124
+ const document = doc ( 'collection/key' , 0 , {
125
125
foo : { bar : 'bar-value' , baz : 'baz-value' }
126
126
} ) ;
127
127
const patch = patchMutation ( 'collection/key' , {
128
128
'foo.bar' : FieldValue . delete ( )
129
129
} ) ;
130
130
131
- const patchedDoc = applyMutationToLocalView ( patch , baseDoc , timestamp ) ;
132
- expect ( patchedDoc ) . to . deep . equal (
131
+ applyMutationToLocalView ( patch , document , timestamp ) ;
132
+ expect ( document ) . to . deep . equal (
133
133
doc ( 'collection/key' , 0 , {
134
134
foo : { baz : 'baz-value' }
135
135
} ) . setHasLocalMutations ( )
136
136
) ;
137
137
} ) ;
138
138
139
139
it ( 'will patch a primitive value' , ( ) => {
140
- const baseDoc = doc ( 'collection/key' , 0 , {
140
+ const document = doc ( 'collection/key' , 0 , {
141
141
foo : 'foo-value' ,
142
142
baz : 'baz-value'
143
143
} ) ;
144
144
const patch = patchMutation ( 'collection/key' , {
145
145
'foo.bar' : 'new-bar-value'
146
146
} ) ;
147
147
148
- const patchedDoc = applyMutationToLocalView ( patch , baseDoc , timestamp ) ;
149
- expect ( patchedDoc ) . to . deep . equal (
148
+ applyMutationToLocalView ( patch , document , timestamp ) ;
149
+ expect ( document ) . to . deep . equal (
150
150
doc ( 'collection/key' , 0 , {
151
151
foo : { bar : 'new-bar-value' } ,
152
152
baz : 'baz-value'
@@ -155,25 +155,21 @@ describe('Mutation', () => {
155
155
} ) ;
156
156
157
157
it ( 'patching a NoDocument yields a NoDocument' , ( ) => {
158
- const baseDoc = deletedDoc ( 'collection/key' , 0 ) ;
158
+ const document = deletedDoc ( 'collection/key' , 0 ) ;
159
159
const patch = patchMutation ( 'collection/key' , { foo : 'bar' } ) ;
160
- const patchedDoc = applyMutationToLocalView ( patch , baseDoc , timestamp ) ;
161
- expect ( patchedDoc ) . to . deep . equal ( baseDoc ) ;
160
+ applyMutationToLocalView ( patch , document , timestamp ) ;
161
+ expect ( document ) . to . deep . equal ( deletedDoc ( 'collection/key' , 0 ) ) ;
162
162
} ) ;
163
163
164
164
it ( 'can apply local serverTimestamp transforms to documents' , ( ) => {
165
165
const docData = { foo : { bar : 'bar-value' } , baz : 'baz-value' } ;
166
166
167
- const baseDoc = doc ( 'collection/key' , 0 , docData ) ;
167
+ const document = doc ( 'collection/key' , 0 , docData ) ;
168
168
const transform = patchMutation ( 'collection/key' , {
169
169
'foo.bar' : FieldValue . serverTimestamp ( )
170
170
} ) ;
171
171
172
- const transformedDoc = applyMutationToLocalView (
173
- transform ,
174
- baseDoc ,
175
- timestamp
176
- ) ;
172
+ applyMutationToLocalView ( transform , document , timestamp ) ;
177
173
178
174
// Server timestamps aren't parsed, so we manually insert it.
179
175
const data = wrapObject ( {
@@ -183,7 +179,7 @@ describe('Mutation', () => {
183
179
data . set ( field ( 'foo.bar' ) , serverTimestamp ( timestamp , null ) ) ;
184
180
const expectedDoc = doc ( 'collection/key' , 0 , data ) . setHasLocalMutations ( ) ;
185
181
186
- expect ( transformedDoc ) . to . deep . equal ( expectedDoc ) ;
182
+ expect ( document ) . to . deep . equal ( expectedDoc ) ;
187
183
} ) ;
188
184
189
185
// NOTE: This is more a test of UserDataReader code than Mutation code but
@@ -352,7 +348,7 @@ describe('Mutation', () => {
352
348
it ( 'can apply server-acked serverTimestamp transform to documents' , ( ) => {
353
349
const docData = { foo : { bar : 'bar-value' } , baz : 'baz-value' } ;
354
350
355
- const baseDoc = doc ( 'collection/key' , 0 , docData ) ;
351
+ const document = doc ( 'collection/key' , 0 , docData ) ;
356
352
const transform = patchMutation ( 'collection/key' , {
357
353
'foo.bar' : FieldValue . serverTimestamp ( )
358
354
} ) ;
@@ -365,13 +361,9 @@ describe('Mutation', () => {
365
361
}
366
362
}
367
363
] ) ;
368
- const transformedDoc = applyMutationToRemoteDocument (
369
- transform ,
370
- baseDoc ,
371
- mutationResult
372
- ) ;
364
+ applyMutationToRemoteDocument ( transform , document , mutationResult ) ;
373
365
374
- expect ( transformedDoc ) . to . deep . equal (
366
+ expect ( document ) . to . deep . equal (
375
367
doc ( 'collection/key' , 1 , {
376
368
foo : { bar : timestamp . toDate ( ) } ,
377
369
baz : 'baz-value'
@@ -381,21 +373,17 @@ describe('Mutation', () => {
381
373
382
374
it ( 'can apply server-acked array transforms to document' , ( ) => {
383
375
const docData = { array1 : [ 1 , 2 ] , array2 : [ 'a' , 'b' ] } ;
384
- const baseDoc = doc ( 'collection/key' , 0 , docData ) ;
376
+ const document = doc ( 'collection/key' , 0 , docData ) ;
385
377
const transform = setMutation ( 'collection/key' , {
386
378
array1 : FieldValue . arrayUnion ( 2 , 3 ) ,
387
379
array2 : FieldValue . arrayRemove ( 'a' , 'c' )
388
380
} ) ;
389
381
390
382
// Server just sends null transform results for array operations.
391
383
const mutationResult = new MutationResult ( version ( 1 ) , [ null , null ] ) ;
392
- const transformedDoc = applyMutationToRemoteDocument (
393
- transform ,
394
- baseDoc ,
395
- mutationResult
396
- ) ;
384
+ applyMutationToRemoteDocument ( transform , document , mutationResult ) ;
397
385
398
- expect ( transformedDoc ) . to . deep . equal (
386
+ expect ( document ) . to . deep . equal (
399
387
doc ( 'collection/key' , 1 , {
400
388
array1 : [ 1 , 2 , 3 ] ,
401
389
array2 : [ 'b' ]
@@ -466,51 +454,47 @@ describe('Mutation', () => {
466
454
467
455
it ( 'can apply server-acked numeric add transform to document' , ( ) => {
468
456
const docData = { sum : 1 } ;
469
- const baseDoc = doc ( 'collection/key' , 0 , docData ) ;
457
+ const document = doc ( 'collection/key' , 0 , docData ) ;
470
458
const transform = setMutation ( 'collection/key' , {
471
459
sum : FieldValue . increment ( 2 )
472
460
} ) ;
473
461
474
462
const mutationResult = new MutationResult ( version ( 1 ) , [
475
463
{ integerValue : 3 }
476
464
] ) ;
477
- const transformedDoc = applyMutationToRemoteDocument (
478
- transform ,
479
- baseDoc ,
480
- mutationResult
481
- ) ;
465
+ applyMutationToRemoteDocument ( transform , document , mutationResult ) ;
482
466
483
- expect ( transformedDoc ) . to . deep . equal (
467
+ expect ( document ) . to . deep . equal (
484
468
doc ( 'collection/key' , 1 , { sum : 3 } ) . setHasCommittedMutations ( )
485
469
) ;
486
470
} ) ;
487
471
488
472
it ( 'can apply deletes to documents' , ( ) => {
489
- const baseDoc = doc ( 'collection/key' , 0 , { foo : 'bar' } ) ;
473
+ const document = doc ( 'collection/key' , 0 , { foo : 'bar' } ) ;
490
474
491
475
const mutation = deleteMutation ( 'collection/key' ) ;
492
- const result = applyMutationToLocalView ( mutation , baseDoc , Timestamp . now ( ) ) ;
493
- expect ( result ) . to . deep . equal ( deletedDoc ( 'collection/key' , 0 ) ) ;
476
+ applyMutationToLocalView ( mutation , document , Timestamp . now ( ) ) ;
477
+ expect ( document ) . to . deep . equal ( deletedDoc ( 'collection/key' , 0 ) ) ;
494
478
} ) ;
495
479
496
480
it ( 'can apply sets with mutation results' , ( ) => {
497
- const baseDoc = doc ( 'collection/key' , 0 , { foo : 'bar' } ) ;
481
+ const document = doc ( 'collection/key' , 0 , { foo : 'bar' } ) ;
498
482
499
483
const docSet = setMutation ( 'collection/key' , { foo : 'new-bar' } ) ;
500
484
const setResult = mutationResult ( 4 ) ;
501
- const setDoc = applyMutationToRemoteDocument ( docSet , baseDoc , setResult ) ;
502
- expect ( setDoc ) . to . deep . equal (
485
+ applyMutationToRemoteDocument ( docSet , document , setResult ) ;
486
+ expect ( document ) . to . deep . equal (
503
487
doc ( 'collection/key' , 4 , { foo : 'new-bar' } ) . setHasCommittedMutations ( )
504
488
) ;
505
489
} ) ;
506
490
507
491
it ( 'will apply patches with mutation results' , ( ) => {
508
- const baseDoc = doc ( 'collection/key' , 0 , { foo : 'bar' } ) ;
492
+ const document = doc ( 'collection/key' , 0 , { foo : 'bar' } ) ;
509
493
510
494
const mutation = patchMutation ( 'collection/key' , { foo : 'new-bar' } ) ;
511
495
const result = mutationResult ( 5 ) ;
512
- const patchedDoc = applyMutationToRemoteDocument ( mutation , baseDoc , result ) ;
513
- expect ( patchedDoc ) . to . deep . equal (
496
+ applyMutationToRemoteDocument ( mutation , document , result ) ;
497
+ expect ( document ) . to . deep . equal (
514
498
doc ( 'collection/key' , 5 , { foo : 'new-bar' } ) . setHasCommittedMutations ( )
515
499
) ;
516
500
} ) ;
@@ -521,8 +505,9 @@ describe('Mutation', () => {
521
505
mutationResult : MutationResult ,
522
506
expected : MutableDocument
523
507
) : void {
524
- applyMutationToRemoteDocument ( mutation , base , mutationResult ) ;
525
- expect ( base ) . to . deep . equal ( expected ) ;
508
+ const documentCopy = base . clone ( ) ;
509
+ applyMutationToRemoteDocument ( mutation , documentCopy , mutationResult ) ;
510
+ expect ( documentCopy ) . to . deep . equal ( expected ) ;
526
511
}
527
512
528
513
it ( 'transitions versions correctly' , ( ) => {
0 commit comments