Files
Webklar-Kundenbereich/test/stripeProductsScript.test.js
T

56 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test, after } from 'node:test'
import assert from 'node:assert/strict'
import { startAppwriteMock } from './support/appwriteMock.js'
import { startFakeStripe } from './support/fakeStripe.js'
import { useTestEnv } from './support/testEnv.js'
// scripts/stripe-products.mjs: der Import darf weder main() starten (kein Stripe-Aufruf, kein process.exit) noch etwas anlegen;
// "--anlegen" macht der Inhaber im Livegang (Block G, Schritt 4).
const aw = await startAppwriteMock()
const st = await startFakeStripe()
after(() => Promise.all([aw.close(), st.close()]))
useTestEnv({ appwriteUrl: aw.url, stripeUrl: st.url })
const { config } = await import('../server/config.js')
const realExit = process.exit
let exitCalls = 0
process.exit = () => {
exitCalls += 1
}
let script
try {
script = await import('../scripts/stripe-products.mjs')
// main() liefe asynchron an: einen Moment warten, damit ein versehentlicher Start sichtbar wird
await new Promise((resolve) => setTimeout(resolve, 100))
} finally {
process.exit = realExit
}
test('Import startet main() nicht: kein Stripe-Aufruf, kein process.exit', () => {
assert.equal(exitCalls, 0)
assert.equal(st.calls.length, 0)
})
test('KEYS enthaelt den Terminplaner-Katalogschluessel', () => {
assert.deepEqual(script.KEYS, ['wartung', 'hosting', 'mailStorage', 'newsSetup', 'termineSetup'])
})
test('catalogEntry liefert die Katalogeintraege aus der Konfiguration', () => {
assert.equal(script.catalogEntry('termineSetup'), config.termineSetup)
assert.equal(script.catalogEntry('newsSetup'), config.newsSetup)
assert.equal(script.catalogEntry('mailStorage'), config.mailStorage)
assert.equal(script.catalogEntry('wartung'), config.products.wartung)
for (const key of script.KEYS) assert.ok(script.catalogEntry(key)?.lookupKey, `${key} hat einen lookupKey`)
})
test('config.termineSetup: Festwerte', () => {
assert.deepEqual(config.termineSetup, {
key: 'termineSetup',
name: 'Terminplaner – Einrichtung',
amountCents: 14900,
lookupKey: 'webklar_termine_einrichtung_14900',
oneTime: true,
priceNickname: 'Terminplaner-Einrichtung 149 €',
})
})