Files
Jyotisha/frontend/tests/local-postgres-or.test.ts
T
jesse-uxandClaude Code 4d801e53c3
Independent Staging Quality Gate / validate (push) Successful in 16m28s
Independent Staging Quality Gate / publish (push) Successful in 3m33s
fix: integrate people archive, report reader and western chart corrections
Validate on Linux Node 22 and PostgreSQL 17: 3894 frontend tests and 64 database tests pass, with no removed test names or new failures. Preserve static Home, bounded gzip, assertion-change records and manual acceptance gaps.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-09-25 20:41:16 +08:00

69 lines
2.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");
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("or() compiles null and boolean IS without binding them as strings", () => {
const parameters: unknown[] = [];
assert.equal(compilePostgrestOr("chart_profile_id.is.null,chart_profile_id.eq.self", parameters, new Map()),
'("chart_profile_id" is null or "chart_profile_id" = $1)');
assert.deepEqual(parameters, ["self"]);
assert.equal(compilePostgrestOr("enabled.is.true,enabled.is.false", [], new Map()),
'("enabled" is true or "enabled" is false)');
assert.throws(() => compilePostgrestOr("enabled.is.anything", [], new Map()));
});
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", \[\]\)/);
});