Skip to content

Commit 11465c2

Browse files
committed
tests: refactor message pagination tests to use withSession helper
1 parent 9cc6b92 commit 11465c2

1 file changed

Lines changed: 19 additions & 25 deletions

File tree

packages/opencode/test/session/messages-pagination.test.ts

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -286,50 +286,44 @@ describe("MessageV2.page", () => {
286286
}),
287287
)
288288

289-
test("pages forward with after cursor", async () => {
290-
await WithInstance.provide({
291-
directory: root,
292-
fn: async () => {
293-
const session = await svc.create({})
294-
const ids = await fill(session.id, 6)
289+
it.instance("pages forward with after cursor", () =>
290+
withSession(({ sessionID }) =>
291+
Effect.gen(function* () {
292+
const ids = yield* fill(sessionID, 6)
295293

296294
// Anchor at "before everything": all messages are newer than time 0
297295
const anchor = MessageV2.cursor.encode({ id: MessageID.ascending(), time: 0 })
298296

299-
const a = MessageV2.page({ sessionID: session.id, limit: 2, after: anchor })
297+
const a = MessageV2.page({ sessionID, limit: 2, after: anchor })
300298
expect(a.items.map((item) => item.info.id)).toEqual(ids.slice(0, 2))
301299
expect(a.more).toBe(true)
302300
expect(a.cursor).toBeTruthy()
303301

304-
const b = MessageV2.page({ sessionID: session.id, limit: 2, after: a.cursor! })
302+
const b = MessageV2.page({ sessionID, limit: 2, after: a.cursor! })
305303
expect(b.items.map((item) => item.info.id)).toEqual(ids.slice(2, 4))
306304
expect(b.more).toBe(true)
307305
expect(b.cursor).toBeTruthy()
308306

309-
const c = MessageV2.page({ sessionID: session.id, limit: 2, after: b.cursor! })
307+
const c = MessageV2.page({ sessionID, limit: 2, after: b.cursor! })
310308
expect(c.items.map((item) => item.info.id)).toEqual(ids.slice(4, 6))
311309
expect(c.more).toBe(false)
312310
expect(c.cursor).toBeUndefined()
311+
}),
312+
),
313+
)
313314

314-
await svc.remove(session.id)
315-
},
316-
})
317-
})
318-
319-
test("rejects requests with both before and after", async () => {
320-
await WithInstance.provide({
321-
directory: root,
322-
fn: async () => {
323-
const session = await svc.create({})
324-
await fill(session.id, 2)
315+
it.instance("rejects requests with both before and after", () =>
316+
withSession(({ sessionID }) =>
317+
Effect.gen(function* () {
318+
yield* fill(sessionID, 2)
325319
const dummyCursor = MessageV2.cursor.encode({ id: MessageID.ascending(), time: 0 })
320+
326321
expect(() =>
327-
MessageV2.page({ sessionID: session.id, limit: 2, before: dummyCursor, after: dummyCursor }),
322+
MessageV2.page({ sessionID, limit: 2, before: dummyCursor, after: dummyCursor }),
328323
).toThrow()
329-
await svc.remove(session.id)
330-
},
331-
})
332-
})
324+
}),
325+
),
326+
)
333327

334328
it.instance("large limit returns all messages without cursor", () =>
335329
withSession(({ sessionID }) =>

0 commit comments

Comments
 (0)