import { readAppFile } from '../test-support/i18n.js'; import assert from 'node:assert/strict'; import fs from 'node:fs/promises'; import path from 'node:path'; import test from 'node:test'; const root = path.resolve(import.meta.dirname, '..'); async function read(relativePath) { return readAppFile(relativePath); } test('fresh routes schema stores timestamps as STRICT-compatible TEXT values', async () => { const schema = await read('database/schema.sql'); const routesTable = schema.match(/CREATE TABLE IF NOT EXISTS routes\s*\((?[\s\S]*?)\)\s*STRICT\s*;/i); assert.ok(routesTable?.groups?.body, 'routes must be a STRICT table'); const body = routesTable.groups.body; assert.match(body, /created_at\s+TEXT\s+NOT NULL\s+DEFAULT\s+CURRENT_TIMESTAMP/i); assert.match(body, /updated_at\s+TEXT\s+NOT NULL\s+DEFAULT\s+CURRENT_TIMESTAMP/i); assert.match(body, /deleted_at\s+TEXT\s+DEFAULT\s+NULL/i); assert.match(body, /activated_at\s+TEXT\s+DEFAULT\s+NULL/i); assert.doesNotMatch(body, /activated_at\s+DATETIME/i); assert.doesNotMatch(body, /ON\s+UPDATE\s+CURRENT_TIMESTAMP/i); }); test('fresh schema owns timestamp triggers and activation index', async () => { const schema = await read('database/schema.sql'); assert.match(schema, /CREATE TRIGGER IF NOT EXISTS routes_updated_at/i); assert.match(schema, /AFTER UPDATE ON routes/i); assert.match(schema, /SET updated_at\s*=\s*CURRENT_TIMESTAMP/i); assert.match(schema, /CREATE TRIGGER IF NOT EXISTS pois_updated_at/i); assert.match(schema, /AFTER UPDATE ON pois/i); assert.match(schema, /CREATE INDEX IF NOT EXISTS idx_routes_activation\s+ON routes\s*\(\s*status\s*,\s*activated_at\s*\)/i); }); test('public route listing can require activated routes without changing base service semantics', async () => { const service = await read('src/services/routes-service.js'); const api = await read('src/routes/api.js'); const client = await read('public/js/api-client.js'); assert.match(service, /publishedOnly\s*=\s*false/); assert.match(service, /activated_at\s+IS\s+NOT\s+NULL/i); assert.match(service, /activatedAt:\s*row\.activated_at/); assert.match(api, /publishedOnly:\s*req\.query\.activatedOnly\s*===\s*['"]true['"]/); assert.match(client, /activatedOnly:\s*['"]true['"]/); });