import { test } from "node:test"; import assert from "node:assert/strict"; import path from "node:path"; import { fileURLToPath } from "node:url"; import dotenv from "dotenv"; import getPool from "../lib/server/db"; import { getUserSettings, setUserSettings } from "../lib/server/user-settings"; import { cleanupTestData } from "./test-helpers"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const envLoaded = dotenv.config({ path: path.resolve(__dirname, "../../../.env") }); const hasDb = Boolean(process.env.DATABASE_URL); test("user settings default and update", async t => { if (!hasDb) { t.skip("DATABASE_URL not set"); return; } if (envLoaded.error) t.diagnostic(String(envLoaded.error)); const pool = getPool(); const client = await pool.connect(); let userId: number | null = null; try { const userRes = await client.query( "insert into users(email, password_hash) values($1,$2) returning id", [`user_settings_${Date.now()}@example.com`, "hash"] ); userId = userRes.rows[0].id as number; const initial = await getUserSettings(userId); assert.equal(initial.entryPanelPageSize, 10); const updated = await setUserSettings({ userId, entryPanelPageSize: 25 }); assert.equal(updated.entryPanelPageSize, 25); const readBack = await getUserSettings(userId); assert.equal(readBack.entryPanelPageSize, 25); } finally { await cleanupTestData(client, { userIds: [userId] }); client.release(); } });