Skip to content

Commit c3fddc9

Browse files
committed
still doesn't work b/c convex .gt/lt doesn't do undefined
1 parent 9eb547a commit c3fddc9

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

packages/convex-helpers/server/stream.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,4 +624,52 @@ describe("stream", () => {
624624
expect(page1.page.map(stripSystemFields)).toEqual([{ a: 1, b: 3, c: 5 }]);
625625
});
626626
});
627+
test("undefined cursor serialization roundtrips", async () => {
628+
const schema = defineSchema({
629+
foo: defineTable({
630+
a: v.optional(v.number()),
631+
b: v.number(),
632+
}).index("ab", ["a", "b"]),
633+
});
634+
});
635+
636+
test("undefined cursor serialization roundtrips", async () => {
637+
const schema = defineSchema({
638+
foo: defineTable({
639+
a: v.optional(v.number()),
640+
b: v.number(),
641+
}).index("ab", ["a", "b"]),
642+
});
643+
const t = convexTest(schema, modules);
644+
await t.run(async (ctx) => {
645+
await ctx.db.insert("foo", { a: 1, b: 2 });
646+
await ctx.db.insert("foo", { a: undefined, b: 3 });
647+
await ctx.db.insert("foo", { a: 2, b: 4 });
648+
await ctx.db.insert("foo", { a: undefined, b: 5 });
649+
const query = stream(ctx.db, schema).query("foo").withIndex("ab");
650+
const result = await query.paginate({ numItems: 1, cursor: null });
651+
expect(result.continueCursor).toMatch('["$_",');
652+
expect(result.page.map(stripSystemFields)).toEqual([
653+
{ a: undefined, b: 3 },
654+
]);
655+
expect(result.isDone).toBe(false);
656+
const page1 = await query.paginate({
657+
numItems: 2,
658+
cursor: result.continueCursor,
659+
});
660+
expect(page1.page.map(stripSystemFields)).toEqual([
661+
{ b: 5 },
662+
{ a: 1, b: 2 },
663+
]);
664+
expect(page1.isDone).toBe(false);
665+
const page2 = await query.paginate({
666+
numItems: 1,
667+
cursor: page1.continueCursor,
668+
});
669+
expect(page2.page.map(stripSystemFields)).toEqual([
670+
{ a: undefined, b: 5 },
671+
]);
672+
expect(page2.isDone).toBe(true);
673+
});
674+
});
627675
});

0 commit comments

Comments
 (0)