import { test } from 'node:test' import assert from 'node:assert/strict' // runAutoChecks arbeitet ohne Domain komplett offline (kein DNS-Abgleich, kein Appwrite, kein Stripe): // Die Pruefung vergleicht den Monatsbetrag beim bisherigen Anbieter mit der Monatsgebuehr des Abos des Kunden. const { runAutoChecks } = await import('../server/services/takeoverCredits.js') // 300 € fuer 12 Monate = 25,00 € pro Monat: mehr als das Hosting-Abo (20,00 €), weniger als das Wartungs-Abo (50,00 €) const doc = { $id: 'req1', $createdAt: '2026-10-01T10:00:00.000Z', domain: '', invoiceAmountCents: 30000, billingMonths: 12, files: '[]' } const sub = (productKey) => ({ status: 'active', startedAt: '2026-10-01T00:00:00.000Z', currentPeriodEnd: '2026-11-01T00:00:00.000Z', ...(productKey === undefined ? {} : { productKey }), }) const amountCheck = async (subscription) => (await runAutoChecks(doc, { allRequests: [], subscription, calc: null })).find((c) => c.key === 'amount') test('Plausibilität: 25 € pro Monat ist mehr als das Hosting-Abo (20,00 €)', async () => { const hosting = await amountCheck(sub('hosting')) assert.ok(hosting, 'Hinweis „mehr als die Monatsgebühr“ fehlt beim Hosting-Abo') assert.equal(hosting.status, 'info') assert.ok(hosting.label.includes('20,00'), hosting.label) assert.ok(hosting.label.includes('25,00'), hosting.label) }) test('Plausibilität: 25 € pro Monat ist nicht mehr als das Wartungs-Abo (50,00 €)', async () => { assert.equal(await amountCheck(sub('wartung')), undefined) }) test('Abos ohne oder mit unbekanntem productKey gelten als Wartungs-Abo, ohne Abo ebenso', async () => { assert.equal(await amountCheck(sub(undefined)), undefined, 'Altbestand ohne productKey') assert.equal(await amountCheck(sub('gibtsnicht')), undefined, 'unbekannter productKey darf die Prüfung nicht abbrechen') const ohneAbo = await runAutoChecks(doc, { allRequests: [], subscription: null, calc: null }) assert.equal(ohneAbo.find((c) => c.key === 'amount'), undefined) assert.equal(ohneAbo.find((c) => c.key === 'abo')?.status, 'warn') })