import { test } from 'node:test' import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import { schemaKeys } from './support/schema.js' test('bankTransactions: Attribute der Spec sind im Setup-Skript angelegt', () => { const keys = schemaKeys('bankTransactions') for (const key of ['amountCents', 'category', 'matchedInvoiceId', 'entryReference', 'bookingDate', 'syncedAt']) { assert.ok(keys.includes(key), `${key} fehlt`) } }) test('bankConnections: Status und Warnstufen', () => { const keys = schemaKeys('bankConnections') for (const key of ['status', 'sessionId', 'accountUid', 'validUntil', 'warnedThresholds', 'balanceBookedCents']) { assert.ok(keys.includes(key), `${key} fehlt`) } }) test('financeSettings und financeFixedCosts sind angelegt', () => { assert.ok(schemaKeys('financeSettings').includes('taxReservePercent')) assert.ok(schemaKeys('financeFixedCosts').includes('counterpartyMatch')) }) test('subscriptions wird weiter aus dem Abo-Setup gelesen', () => { assert.ok(schemaKeys('subscriptions').includes('stripeSubscriptionId')) }) test('unbekannte Collection scheitert mit klarer Meldung', () => { assert.throws(() => schemaKeys('gibtEsNicht'), /Collection gibtEsNicht fehlt im Setup-Skript/) }) test('bankTransactions: Indexe auf bookingDate (Sortierung) und status (Vormerkungen suchen)', () => { const src = readFileSync(new URL('../scripts/setup-finanzen.mjs', import.meta.url), 'utf8') const start = src.indexOf("'bankTransactions',") const block = src.slice(start, src.indexOf("// Einstellungen", start)) assert.match(block, /key: 'idx_booking', type: 'key', attributes: \['bookingDate'\]/) assert.match(block, /key: 'idx_status', type: 'key', attributes: \['status'\]/) })