138 lines
7.6 KiB
JavaScript
138 lines
7.6 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { loadModule } from './load.mjs'
|
|
|
|
// Kunden-Reiter "Funktionen": Register der Funktionen (News, Terminplaner), Aktionen je Zustand, Antwort einarbeiten
|
|
const { FUNKTIONEN, ZUSTAND, funktionOf, aktionen, mergeFunktion, siteKeyOf, abgeschaltetText } = await loadModule('src/lib/funktionenView.js')
|
|
|
|
test('FUNKTIONEN: News und Terminplaner mit den Bestätigungstexten', () => {
|
|
assert.deepEqual(FUNKTIONEN, [
|
|
{
|
|
key: 'news',
|
|
label: 'News',
|
|
bestaetigen: {
|
|
activate: 'News ohne Zahlung aktivieren?',
|
|
disable: 'News abschalten? Die Website zeigt dann keine Beiträge mehr.',
|
|
},
|
|
},
|
|
{
|
|
key: 'termine',
|
|
label: 'Terminplaner',
|
|
bestaetigen: {
|
|
activate: 'Terminplaner ohne Zahlung aktivieren?',
|
|
disable: 'Terminplaner abschalten? Auf der Website sind dann keine Buchungen mehr möglich.',
|
|
},
|
|
},
|
|
])
|
|
})
|
|
|
|
test('ZUSTAND: Ton und Beschriftung je Zustand', () => {
|
|
assert.deepEqual(ZUSTAND, {
|
|
off: ['muted', 'Aus'],
|
|
ordered: ['warn', 'Bestellt'],
|
|
setup: ['info', 'Einrichtung'],
|
|
active: ['ok', 'Aktiv'],
|
|
disabled: ['muted', 'Abgeschaltet'],
|
|
})
|
|
})
|
|
|
|
test('funktionOf: Ansicht der Funktion, ohne Eintrag "off"', () => {
|
|
const project = { projectId: 'p1', features: { news: { state: 'active', ticketWoid: '100' }, termine: { state: 'setup' } } }
|
|
assert.deepEqual(funktionOf(project, 'news'), { state: 'active', ticketWoid: '100' })
|
|
assert.deepEqual(funktionOf(project, 'termine'), { state: 'setup' })
|
|
assert.deepEqual(funktionOf({ projectId: 'p2', features: { news: { state: 'active' } } }, 'termine'), { state: 'off' })
|
|
assert.deepEqual(funktionOf({ projectId: 'p3' }, 'news'), { state: 'off' })
|
|
assert.deepEqual(funktionOf(null, 'news'), { state: 'off' })
|
|
})
|
|
|
|
test('aktionen: Aktivieren außer bei "active", Abschalten bei Bestellt, Einrichtung und Aktiv', () => {
|
|
assert.deepEqual(aktionen('off'), ['activate'])
|
|
assert.deepEqual(aktionen('ordered'), ['activate', 'disable'])
|
|
assert.deepEqual(aktionen('setup'), ['activate', 'disable'])
|
|
assert.deepEqual(aktionen('active'), ['disable'])
|
|
assert.deepEqual(aktionen('disabled'), ['activate'])
|
|
assert.deepEqual(aktionen(undefined), ['activate'])
|
|
})
|
|
|
|
const projects = () => [
|
|
{ projectId: 'p1', projectName: 'Eins', features: { news: { state: 'off' }, termine: { state: 'active', siteKey: 'abc' } } },
|
|
{ projectId: 'p2', projectName: 'Zwei', features: { news: { state: 'active' }, termine: { state: 'off' } } },
|
|
]
|
|
|
|
test('mergeFunktion: übernimmt nur die gewählte Funktion, die andere bleibt', () => {
|
|
const antwort = {
|
|
projectId: 'p1',
|
|
projectName: 'Eins (neu)',
|
|
features: { news: { state: 'setup', ticketWoid: '7' }, termine: { state: 'off' } },
|
|
}
|
|
const merged = mergeFunktion(projects(), 'p1', 'news', antwort)
|
|
assert.deepEqual(merged[0].features.news, { state: 'setup', ticketWoid: '7' })
|
|
assert.deepEqual(merged[0].features.termine, { state: 'active', siteKey: 'abc' })
|
|
assert.equal(merged[0].projectName, 'Eins')
|
|
assert.deepEqual(merged[1], projects()[1])
|
|
})
|
|
|
|
test('mergeFunktion: Terminplaner überschreibt News nicht', () => {
|
|
const antwort = { projectId: 'p2', features: { news: { state: 'off' }, termine: { state: 'ordered' } } }
|
|
const merged = mergeFunktion(projects(), 'p2', 'termine', antwort)
|
|
assert.deepEqual(merged[1].features, { news: { state: 'active' }, termine: { state: 'ordered' } })
|
|
})
|
|
|
|
test('mergeFunktion: verändert die Eingabe nicht, ohne Antwort oder ohne Funktion bleibt alles', () => {
|
|
const list = projects()
|
|
const merged = mergeFunktion(list, 'p1', 'news', { projectId: 'p1', features: { news: { state: 'active' } } })
|
|
assert.notEqual(merged, list)
|
|
assert.deepEqual(list, projects())
|
|
assert.deepEqual(mergeFunktion(list, 'p1', 'news', undefined), projects())
|
|
assert.deepEqual(mergeFunktion(list, 'p1', 'news', { projectId: 'p1', features: {} }), projects())
|
|
assert.deepEqual(mergeFunktion(list, 'unbekannt', 'news', { features: { news: { state: 'active' } } }), projects())
|
|
})
|
|
|
|
test('mergeFunktion: Projekt ohne bisherige features bekommt die Funktion', () => {
|
|
const merged = mergeFunktion([{ projectId: 'p9' }], 'p9', 'termine', { features: { termine: { state: 'setup' } } })
|
|
assert.deepEqual(merged, [{ projectId: 'p9', features: { termine: { state: 'setup' } } }])
|
|
})
|
|
|
|
test('siteKeyOf: nur der Terminplaner zeigt seinen Site-Key, nur wenn das Portal einen nennt', () => {
|
|
assert.equal(siteKeyOf({ state: 'active', siteKey: 'abcdefghijklmnop' }, 'termine'), 'abcdefghijklmnop')
|
|
assert.equal(siteKeyOf({ state: 'active', siteKey: ' abcdefghijklmnop ' }, 'termine'), 'abcdefghijklmnop', 'getrimmt')
|
|
assert.equal(siteKeyOf({ state: 'active', siteKey: 'abcdefghijklmnop' }, 'news'), '', 'News: kein Site-Key in der Tabelle')
|
|
for (const feature of [{ state: 'off' }, { state: 'active', siteKey: null }, { state: 'active', siteKey: '' }, { state: 'active', siteKey: 5 }, null, undefined]) {
|
|
assert.equal(siteKeyOf(feature, 'termine'), '', JSON.stringify(feature))
|
|
}
|
|
})
|
|
|
|
test('abgeschaltetText: Grund und Löschdatum im Zustand "disabled"', () => {
|
|
const text = (disabledReason, loeschungAm) => abgeschaltetText({ state: 'disabled', disabledReason, loeschungAm })
|
|
assert.equal(text('abo_ende', '2026-11-04'), 'Abgeschaltet (Abo beendet), Löschung am 04.11.2026')
|
|
assert.equal(text('abo_ende', undefined), 'Abgeschaltet (Abo beendet)')
|
|
assert.equal(text('abo_ende_vor_einrichtung', '2026-11-04'), 'Abgeschaltet (Abo endete vor Einrichtung, Erstattung prüfen), Löschung am 04.11.2026')
|
|
assert.equal(text('abo_ende_vor_einrichtung', null), 'Abgeschaltet (Abo endete vor Einrichtung, Erstattung prüfen)')
|
|
assert.equal(text('team', '2026-12-01'), 'Abgeschaltet (Team), Löschung am 01.12.2026')
|
|
assert.equal(text('team', null), 'Abgeschaltet (Team)')
|
|
assert.equal(text('kunde_geloescht', '2026-12-31'), 'Abgeschaltet (Kunde gelöscht), Löschung am 31.12.2026')
|
|
assert.equal(text('kunde_geloescht', ''), 'Abgeschaltet (Kunde gelöscht)')
|
|
})
|
|
|
|
test('abgeschaltetText: ohne Grund nur "Abgeschaltet", mit Datum "Abgeschaltet, Löschung am …"', () => {
|
|
assert.equal(abgeschaltetText({ state: 'disabled' }), 'Abgeschaltet')
|
|
assert.equal(abgeschaltetText({ state: 'disabled', disabledReason: null, loeschungAm: null }), 'Abgeschaltet')
|
|
assert.equal(abgeschaltetText({ state: 'disabled', disabledReason: '', loeschungAm: '' }), 'Abgeschaltet')
|
|
assert.equal(abgeschaltetText({ state: 'disabled', disabledReason: null, loeschungAm: '2026-11-04' }), 'Abgeschaltet, Löschung am 04.11.2026')
|
|
assert.equal(abgeschaltetText({ state: 'disabled', loeschungAm: '2026-01-09' }), 'Abgeschaltet, Löschung am 09.01.2026')
|
|
})
|
|
|
|
test('abgeschaltetText: unbekannter Grund wird wie "ohne Grund" behandelt', () => {
|
|
assert.equal(abgeschaltetText({ state: 'disabled', disabledReason: 'frist' }), 'Abgeschaltet')
|
|
assert.equal(abgeschaltetText({ state: 'disabled', disabledReason: 'frist', loeschungAm: '2026-11-04' }), 'Abgeschaltet, Löschung am 04.11.2026')
|
|
assert.equal(abgeschaltetText({ state: 'disabled', disabledReason: 'constructor' }), 'Abgeschaltet', 'kein Treffer über die Prototypenkette')
|
|
assert.equal(abgeschaltetText({ state: 'disabled', disabledReason: 5 }), 'Abgeschaltet')
|
|
})
|
|
|
|
test('abgeschaltetText: außerhalb von "disabled" leer, auch mit Grund und Datum', () => {
|
|
for (const state of ['active', 'setup', 'ordered', 'off', undefined, null]) {
|
|
assert.equal(abgeschaltetText({ state, disabledReason: 'abo_ende', loeschungAm: '2026-11-04' }), '', String(state))
|
|
}
|
|
for (const feature of [{}, null, undefined]) assert.equal(abgeschaltetText(feature), '', JSON.stringify(feature))
|
|
})
|