Skip to content

Commit eaea528

Browse files
committed
still doesn't work b/c convex .gt/lt doesn't do undefined
1 parent 5dd14db commit eaea528

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
@@ -748,4 +748,52 @@ describe("stream", () => {
748748
expect(page1.page.map(stripSystemFields)).toEqual([{ a: 1, b: 3, c: 5 }]);
749749
});
750750
});
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+
});
751799
});

0 commit comments

Comments
 (0)