Files
Jyotisha/frontend/tests/local-postgres-or.test.ts
T
jesse-ux e71e4f9200
Independent Staging Quality Gate / validate (push) Failing after 16m52s
Independent Staging Quality Gate / publish (push) Skipped
fix(web): keep rectification sessions listed and persist chats on first send
Empty-consultation filtering is now session_type scoped so birth-time rows stay in the sidebar. Subtitles use updatedAt with sort/group/cursor. New chats stay local until the first send.
2026-09-21 16:39:32 +08:00

59 lines
2.1 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");
const listFilter = readFileSync(new URL("../src/lib/session-list-filter.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\)\)/);
});
test("session list empty-consultation filter is session_type scoped", () => {
assert.match(listFilter, /session_type\.neq\.consultation,messages\.neq\.\[\]/);
assert.match(listRoute, /excludeEmptyConsultations/);
assert.doesNotMatch(listRoute, /\.not\("messages", "eq", \[\]\)/);
assert.doesNotMatch(listFilter, /\.not\("messages", "eq", \[\]\)/);
});