Files
Jyotisha/frontend/tests/local-postgres-or.test.ts
T
jesse-ux e4e73f56c0
Independent Staging Quality Gate / publish (push) Canceled after 0s
Independent Staging Quality Gate / validate (push) Canceled after 9m33s
fix(web): 四个页面共用一份会话列表,空会话不入列
对话、星盘、星历、报告进同一 (app) 外壳,列表只拉一次。服务端不再列出空咨询;新建复用已有空会话。新标题改成「生时校正 · M月D日」,侧栏副标题用创建时间。
2026-09-17 21:27:40 +08:00

51 lines
1.6 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
import { compilePostgrestOr } from "../src/lib/db/local-postgres-client-core.ts";
import { sessionCursorFilter } from "../src/lib/session-cursor.ts";
const core = readFileSync(new URL("../src/lib/db/local-postgres-client-core.ts", import.meta.url), "utf8");
const listRoute = readFileSync(new URL("../src/app/api/sessions/route.ts", import.meta.url), "utf8");
test("or() compiles a comma-separated PostgREST filter", () => {
const parameters: unknown[] = [];
const sql = compilePostgrestOr(
"session_type.neq.consultation,messages.neq.[]",
parameters,
new Map([
["session_type", "text"],
["messages", "jsonb"],
]),
);
assert.equal(sql, '("session_type" <> $1 or "messages" <> $2)');
assert.deepEqual(parameters, ["consultation", "[]"]);
assert.match(core, /or\(expression: string\)/);
});
test("or() compiles the session cursor filter with a nested and", () => {
const cursor = sessionCursorFilter({
updatedAt: "2026-09-03T07:09:23Z",
id: "11111111-1111-4111-8111-111111111111",
});
const parameters: unknown[] = [];
const sql = compilePostgrestOr(
cursor,
parameters,
new Map([
["updated_at", "timestamptz"],
["id", "uuid"],
]),
);
assert.equal(
sql,
'("updated_at" < $1 or ("updated_at" = $2 and "id" < $3))',
);
assert.deepEqual(parameters, [
"2026-09-03T07:09:23Z",
"2026-09-03T07:09:23Z",
"11111111-1111-4111-8111-111111111111",
]);
assert.match(listRoute, /pageQuery = pageQuery\.or\(sessionCursorFilter\(cursor\)\)/);
});