@@ -70,37 +70,64 @@ describe('cacheReducer', () => {
70
70
expect ( pass2 . cache . testStoreAs2 . docs [ 0 ] ) . to . eql ( {
71
71
other : 'test' ,
72
72
id : 'testDocId1' ,
73
+ path,
73
74
} ) ;
74
75
} ) ;
75
76
} ) ;
76
77
77
78
describe ( 'query fields' , ( ) => {
78
79
it ( 'query fields return partial document' , ( ) => {
79
80
const doc1 = { key1 : 'value1' , other : 'test' , id : 'testDocId1' , path } ;
81
+ const doc2 = { key1 : 'value1' , other : 'limit' , id : 'testDocId2' , path } ;
82
+ const doc3 = { key1 : 'value1' , other : 'third' , id : 'testDocId3' , path } ;
83
+ const doc4 = { key1 : 'value1' , other : 'fourth' , id : 'testDocId4' , path } ;
80
84
81
85
// Initial seed
82
86
const action1 = {
83
87
meta : {
84
88
collection,
85
89
storeAs : 'testStoreAs' ,
86
90
where : [ [ 'key1' , '==' , 'value1' ] ] ,
87
- orderBy : [ 'value1 ' ] ,
91
+ orderBy : [ 'key1 ' ] ,
88
92
fields : [ 'id' , 'other' ] ,
93
+ limit : 2 ,
89
94
} ,
90
95
payload : {
91
- data : { [ doc1 . id ] : doc1 } ,
92
- ordered : [ doc1 ] ,
96
+ data : { [ doc1 . id ] : doc1 , [ doc2 . id ] : doc2 , [ doc3 . id ] : doc3 } ,
97
+ ordered : [ doc1 , doc2 , doc3 ] ,
93
98
fromCache : true ,
94
99
} ,
95
100
type : actionTypes . LISTENER_RESPONSE ,
96
101
} ;
102
+ const action2 = {
103
+ type : actionTypes . OPTIMISTIC_ADDED ,
104
+ meta : {
105
+ collection,
106
+ doc : doc4 . id ,
107
+ } ,
108
+ payload : { data : doc4 } ,
109
+ } ;
97
110
98
111
const pass1 = reducer ( initialState , action1 ) ;
112
+ const pass2 = reducer ( pass1 , action2 ) ;
99
113
100
114
expect ( pass1 . cache . testStoreAs . docs [ 0 ] ) . to . eql ( {
101
115
other : 'test' ,
102
116
id : 'testDocId1' ,
117
+ path,
118
+ } ) ;
119
+ expect ( pass1 . cache . testStoreAs . docs [ 1 ] ) . to . eql ( {
120
+ other : 'limit' ,
121
+ id : 'testDocId2' ,
122
+ path,
103
123
} ) ;
124
+ expect ( pass2 . cache . testStoreAs . docs [ 1 ] ) . to . eql ( {
125
+ other : 'limit' ,
126
+ id : 'testDocId2' ,
127
+ path,
128
+ } ) ;
129
+
130
+ expect ( pass2 . cache . testStoreAs . docs [ 2 ] ) . to . eql ( undefined ) ;
104
131
} ) ;
105
132
106
133
it ( 'empty fields return entire document' , ( ) => {
@@ -175,11 +202,13 @@ describe('cacheReducer', () => {
175
202
expect ( pass1 . cache . testStoreAs . docs [ 0 ] ) . to . eql ( {
176
203
id : 'testDocId1' ,
177
204
key1 : 'value1' ,
205
+ path,
178
206
} ) ;
179
207
expect ( pass2 . cache . testStoreAs . docs [ 0 ] ) . to . eql ( {
180
208
anotherDocument : doc2 ,
181
209
key1 : 'value1' ,
182
210
id : 'testDocId1' ,
211
+ path,
183
212
} ) ;
184
213
} ) ;
185
214
@@ -231,12 +260,14 @@ describe('cacheReducer', () => {
231
260
expect ( pass1 . cache . testStoreAs . docs [ 0 ] ) . to . eql ( {
232
261
id : 'testDocId1' ,
233
262
key1 : 'value1' ,
263
+ path,
234
264
} ) ;
235
265
236
266
expect ( pass2 . cache . testStoreAs . docs [ 0 ] ) . to . eql ( {
237
267
others : [ doc3 , doc2 ] ,
238
268
key1 : 'value1' ,
239
269
id : 'testDocId1' ,
270
+ path,
240
271
} ) ;
241
272
} ) ;
242
273
@@ -288,12 +319,14 @@ describe('cacheReducer', () => {
288
319
expect ( pass1 . cache . testStoreAs . docs [ 0 ] ) . to . eql ( {
289
320
id : 'testDocId1' ,
290
321
key1 : 'value1' ,
322
+ path,
291
323
} ) ;
292
324
293
325
expect ( pass2 . cache . testStoreAs . docs [ 0 ] ) . to . eql ( {
294
326
others : [ doc3 , doc2 ] ,
295
327
key1 : 'value1' ,
296
328
id : 'testDocId1' ,
329
+ path,
297
330
} ) ;
298
331
} ) ;
299
332
} ) ;
0 commit comments