@@ -141,10 +141,11 @@ describe("stream", () => {
141
141
test ( "query round trip with pagination" , async ( ) => {
142
142
const t = convexTest ( schema , modules ) ;
143
143
await t . run ( async ( ctx ) => {
144
+ // put first out of order just in case
145
+ await ctx . db . insert ( "foo" , { a : 1 , b : 4 , c : 3 } ) ;
144
146
await ctx . db . insert ( "foo" , { a : 1 , b : 2 , c : 3 } ) ;
145
147
await ctx . db . insert ( "foo" , { a : 1 , b : 3 , c : 3 } ) ;
146
148
await ctx . db . insert ( "foo" , { a : 1 , b : 3 , c : 4 } ) ;
147
- await ctx . db . insert ( "foo" , { a : 1 , b : 4 , c : 3 } ) ;
148
149
await ctx . db . insert ( "foo" , { a : 1 , b : 4 , c : 4 } ) ;
149
150
const query = stream ( ctx . db , schema )
150
151
. query ( "foo" )
@@ -173,6 +174,42 @@ describe("stream", () => {
173
174
} ) ;
174
175
} ) ;
175
176
177
+ test ( "query round trip with pagination one item at a time" , async ( ) => {
178
+ const t = convexTest ( schema , modules ) ;
179
+ await t . run ( async ( ctx ) => {
180
+ // put first out of order just in case
181
+ await ctx . db . insert ( "foo" , { a : 1 , b : 3 , c : 1 } ) ;
182
+ await ctx . db . insert ( "foo" , { a : 1 , b : 2 , c : 1 } ) ;
183
+ await ctx . db . insert ( "foo" , { a : 1 , b : 2 , c : 2 } ) ;
184
+ await ctx . db . insert ( "foo" , { a : 1 , b : 3 , c : 2 } ) ;
185
+ await ctx . db . insert ( "foo" , { a : 1 , b : 2 , c : 3 } ) ;
186
+ const query = stream ( ctx . db , schema )
187
+ . query ( "foo" )
188
+ . withIndex ( "abc" , ( q ) => q . eq ( "a" , 1 ) . gt ( "b" , 2 ) ) ;
189
+ const result = await query . paginate ( { numItems : 1 , cursor : null } ) ;
190
+ expect ( result . page . map ( stripSystemFields ) ) . toEqual ( [
191
+ { a : 1 , b : 3 , c : 1 } ,
192
+ ] ) ;
193
+ expect ( result . isDone ) . toBe ( false ) ;
194
+ const result2 = await query . paginate ( {
195
+ numItems : 1 ,
196
+ cursor : result . continueCursor ,
197
+ } ) ;
198
+ expect ( result2 . page . map ( stripSystemFields ) ) . toEqual ( [
199
+ { a : 1 , b : 2 , c : 1 } ,
200
+ ] ) ;
201
+ expect ( result2 . isDone ) . toBe ( false ) ;
202
+ const result3 = await query . paginate ( {
203
+ numItems : 1 ,
204
+ cursor : result2 . continueCursor ,
205
+ } ) ;
206
+ expect ( result3 . page . map ( stripSystemFields ) ) . toEqual ( [
207
+ { a : 1 , b : 2 , c : 2 } ,
208
+ ] ) ;
209
+ expect ( result3 . isDone ) . toBe ( false ) ;
210
+ } ) ;
211
+ } ) ;
212
+
176
213
test ( "merge streams" , async ( ) => {
177
214
const t = convexTest ( schema , modules ) ;
178
215
await t . run ( async ( ctx ) => {
0 commit comments