@@ -748,4 +748,52 @@ describe("stream", () => {
748
748
expect ( page1 . page . map ( stripSystemFields ) ) . toEqual ( [ { a : 1 , b : 3 , c : 5 } ] ) ;
749
749
} ) ;
750
750
} ) ;
751
+ test ( "undefined cursor serialization roundtrips" , async ( ) => {
752
+ const schema = defineSchema ( {
753
+ foo : defineTable ( {
754
+ a : v . optional ( v . number ( ) ) ,
755
+ b : v . number ( ) ,
756
+ } ) . index ( "ab" , [ "a" , "b" ] ) ,
757
+ } ) ;
758
+ } ) ;
759
+
760
+ test ( "undefined cursor serialization roundtrips" , async ( ) => {
761
+ const schema = defineSchema ( {
762
+ foo : defineTable ( {
763
+ a : v . optional ( v . number ( ) ) ,
764
+ b : v . number ( ) ,
765
+ } ) . index ( "ab" , [ "a" , "b" ] ) ,
766
+ } ) ;
767
+ const t = convexTest ( schema , modules ) ;
768
+ await t . run ( async ( ctx ) => {
769
+ await ctx . db . insert ( "foo" , { a : 1 , b : 2 } ) ;
770
+ await ctx . db . insert ( "foo" , { a : undefined , b : 3 } ) ;
771
+ await ctx . db . insert ( "foo" , { a : 2 , b : 4 } ) ;
772
+ await ctx . db . insert ( "foo" , { a : undefined , b : 5 } ) ;
773
+ const query = stream ( ctx . db , schema ) . query ( "foo" ) . withIndex ( "ab" ) ;
774
+ const result = await query . paginate ( { numItems : 1 , cursor : null } ) ;
775
+ expect ( result . continueCursor ) . toMatch ( '["$_",' ) ;
776
+ expect ( result . page . map ( stripSystemFields ) ) . toEqual ( [
777
+ { a : undefined , b : 3 } ,
778
+ ] ) ;
779
+ expect ( result . isDone ) . toBe ( false ) ;
780
+ const page1 = await query . paginate ( {
781
+ numItems : 2 ,
782
+ cursor : result . continueCursor ,
783
+ } ) ;
784
+ expect ( page1 . page . map ( stripSystemFields ) ) . toEqual ( [
785
+ { b : 5 } ,
786
+ { a : 1 , b : 2 } ,
787
+ ] ) ;
788
+ expect ( page1 . isDone ) . toBe ( false ) ;
789
+ const page2 = await query . paginate ( {
790
+ numItems : 1 ,
791
+ cursor : page1 . continueCursor ,
792
+ } ) ;
793
+ expect ( page2 . page . map ( stripSystemFields ) ) . toEqual ( [
794
+ { a : undefined , b : 5 } ,
795
+ ] ) ;
796
+ expect ( page2 . isDone ) . toBe ( true ) ;
797
+ } ) ;
798
+ } ) ;
751
799
} ) ;
0 commit comments