Local Postgres not() only handled eq/cs, so archived=1 threw and the sidebar archive view returned 500. Compile is not null/true/false instead of inequality.
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
closeLocalPostgresDataPools,
|
|
compileUnaryIsClause,
|
|
createLocalPostgresDataClient,
|
|
} from "../src/lib/db/local-postgres-client-core.ts";
|
|
|
|
test("not(col, is, null) compiles to IS NOT NULL rather than inequality", () => {
|
|
const sql = compileUnaryIsClause("archived_at", null, true);
|
|
assert.equal(sql, '"archived_at" is not null');
|
|
assert.doesNotMatch(sql, /<>/);
|
|
assert.equal(compileUnaryIsClause("archived_at", true, true), '"archived_at" is not true');
|
|
assert.equal(compileUnaryIsClause("archived_at", false, true), '"archived_at" is not false');
|
|
assert.equal(compileUnaryIsClause("archived_at", null, false), '"archived_at" is null');
|
|
});
|
|
|
|
test("not(col, is, undefined) still throws", async () => {
|
|
assert.throws(() => compileUnaryIsClause("archived_at", undefined, true), /unsupported not filter/);
|
|
const local = createLocalPostgresDataClient(
|
|
"postgresql://unused:unused@127.0.0.1:9/unused",
|
|
{ id: "11111111-1111-4111-8111-111111111111", email: "unused@example.com" },
|
|
);
|
|
try {
|
|
assert.throws(
|
|
() => local.from("chat_sessions").select("id").not("archived_at", "is", undefined),
|
|
/unsupported not filter/,
|
|
);
|
|
} finally {
|
|
await closeLocalPostgresDataPools();
|
|
}
|
|
});
|