Skip to content

Commit 1ab7d75

Browse files
committed
ok this is the repro
1 parent 6cee34c commit 1ab7d75

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ describe("stream", () => {
141141
test("query round trip with pagination", async () => {
142142
const t = convexTest(schema, modules);
143143
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 });
144146
await ctx.db.insert("foo", { a: 1, b: 2, c: 3 });
145147
await ctx.db.insert("foo", { a: 1, b: 3, c: 3 });
146148
await ctx.db.insert("foo", { a: 1, b: 3, c: 4 });
147-
await ctx.db.insert("foo", { a: 1, b: 4, c: 3 });
148149
await ctx.db.insert("foo", { a: 1, b: 4, c: 4 });
149150
const query = stream(ctx.db, schema)
150151
.query("foo")
@@ -173,6 +174,42 @@ describe("stream", () => {
173174
});
174175
});
175176

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+
176213
test("merge streams", async () => {
177214
const t = convexTest(schema, modules);
178215
await t.run(async (ctx) => {

0 commit comments

Comments
 (0)