Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

threadDetailCursor.test.ts

44 lines1.6 KB

1import { ThreadId } from "@t3tools/contracts";
2import { describe, expect, it } from "@effect/vitest";
3​
4import {
5 decodeThreadDetailPageCursor,
6 encodeThreadDetailPageCursor,
7} from "./threadDetailCursor.ts";
8​
9describe("threadDetailCursor", () => {
10 it("round-trips a cursor", () => {
11 const cursor = {
12 threadId: ThreadId.make("thread-1"),
13 beforeAnchorAt: "2026-08-01T00:00:00.000Z",
14 beforeTurnId: "turn-9",
15 };
16 expect(decodeThreadDetailPageCursor(encodeThreadDetailPageCursor(cursor))).toEqual(cursor);
17 });
18​
19 it("round-trips empty boundary values", () => {
20 // The anchor is COALESCE(requested_at, started_at, '') and the turn key
21 // is COALESCE(turn_id, ''), so a server-minted cursor can legitimately
22 // carry empty strings; rejecting them would degrade a valid cursor to a
23 // first-page request that repeats recent history (review finding).
24 const cursor = {
25 threadId: ThreadId.make("thread-1"),
26 beforeAnchorAt: "",
27 beforeTurnId: "",
28 };
29 expect(decodeThreadDetailPageCursor(encodeThreadDetailPageCursor(cursor))).toEqual(cursor);
30 });
31​
32 it("rejects malformed input", () => {
33 expect(decodeThreadDetailPageCursor("not-base64-json")).toBeNull();
34 expect(decodeThreadDetailPageCursor(Buffer.from("[]").toString("base64url"))).toBeNull();
35 expect(
36 decodeThreadDetailPageCursor(Buffer.from(JSON.stringify({ t: "" })).toString("base64url")),
37 ).toBeNull();
38 expect(
39 decodeThreadDetailPageCursor(
40 Buffer.from(JSON.stringify({ t: "thread-1", a: 5, i: "x" })).toString("base64url"),
41 ),
42 ).toBeNull();
43 });
44});