@@ -34,14 +37,14 @@ a{color:#111111;}
|
-| Deine Bestellung: News-Pinnwand |
-Hallo {{kunde_name}}, vielen Dank für Deine Bestellung und Deine Zahlung. Wir richten die News-Pinnwand jetzt für Dein Projekt ein. |
-| Funktion | News-Pinnwand – Einrichtung | | Projekt | {{projekt}} | | Einmalig bezahlt | {{preis}} (brutto, einmalig; die Nutzung ist kostenlos, es läuft kein Abo) | | Einrichtung | {{zeit}} |
|
-Wie geht es weiter? Sobald die News-Pinnwand auf Deiner Website eingebaut ist, schalten wir sie im Kundenportal frei und Du bekommst eine weitere E-Mail. Danach kannst Du Beiträge im Portal schreiben. |
|
+| Deine Bestellung: {{funktion}} |
+Hallo {{kunde_name}}, vielen Dank für Deine Bestellung und Deine Zahlung. Wir richten {{funktion_akk}} jetzt für Dein Projekt ein. |
+| Funktion | {{funktion}} – Einrichtung | | Projekt | {{projekt}} | | Einmalig bezahlt | {{preis}} ({{preis_hinweis}}) | | Einrichtung | {{zeit}} |
|
+Wie geht es weiter? Sobald {{funktion_nom}} auf Deiner Website eingebaut ist, schalten wir {{funktion_pron}} im Kundenportal frei und Du bekommst eine weitere E-Mail. {{danach}} |
|
|
- |
+ |
Viele Grüße Dein WEBklar-Team |
|
diff --git a/server/mail-templates/K16 Funktion bereit.html b/server/mail-templates/K16 Funktion bereit.html
index f9c2fde..30419da 100644
--- a/server/mail-templates/K16 Funktion bereit.html
+++ b/server/mail-templates/K16 Funktion bereit.html
@@ -3,16 +3,18 @@
-Deine News-Pinnwand ist bereit
+{{funktion_dein}} ist bereit
-Deine News-Pinnwand ist freigeschaltet. ͏ ͏ ͏
+{{funktion_dein}} ist freigeschaltet. ͏ ͏ ͏
@@ -31,11 +33,11 @@ a{color:#111111;}
|
- |
-| Deine News-Pinnwand ist bereit |
-Hallo {{kunde_name}}, die News-Pinnwand ist auf Deiner Website eingebaut und freigeschaltet. Du kannst ab sofort Beiträge schreiben, sie erscheinen direkt bei Dir auf der Seite. |
-| Funktion | News-Pinnwand | | Projekt | {{projekt}} |
|
- |
+ |
+| {{funktion_dein}} ist bereit |
+Hallo {{kunde_name}}, {{funktion_nom}} ist auf Deiner Website eingebaut und freigeschaltet. {{bereit}} |
+| Funktion | {{funktion}} | | Projekt | {{projekt}} |
|
+ |
Viele Grüße Dein WEBklar-Team |
|
diff --git a/server/services/siteFeatures.js b/server/services/siteFeatures.js
index edacfc0..0b0a432 100644
--- a/server/services/siteFeatures.js
+++ b/server/services/siteFeatures.js
@@ -469,7 +469,60 @@ export async function findActiveBySiteKey(siteKey, featureKey = 'news') {
// ---------------------------------------------------------------------------
const eur = (cents) => `${(cents / 100).toFixed(2).replace('.', ',')} €`
-const portalUrl = () => `${config.publicBaseUrl}/dashboard.html#news`
+/** Adresse der Funktion im Kundenportal (Anker aus dem Register: returnHash). */
+const portalUrl = (feature) => `${config.publicBaseUrl}/dashboard.html#${feature.returnHash}`
+/** Preis der Einrichtung aus dem Katalog der Funktion (feature.product: newsSetup | termineSetup); config.* bei jedem Aufruf gelesen. */
+function einrichtungsPreis(feature) {
+ const amountCents = config[feature.product]?.amountCents
+ if (!Number.isInteger(amountCents)) throw new Error(`Katalogpreis ${feature.product} fehlt`)
+ return eur(amountCents)
+}
+
+/**
+ * K15 (Bestellung eingegangen) einer Funktion: Vorlage, Platzhalterwerte und Bloecke ausschliesslich aus dem Register-Eintrag
+ * (mails.*, setupEstimate, returnHash) und dem Katalogpreis. Die Werte decken genau die Platzhalter der Vorlage ab.
+ * Ohne Anhaenge: die Rechtsunterlagen der Termine-Bestellung haengt F8 direkt in onFeaturePaid an.
+ */
+export function bestellMail(feature, { kundeName, projekt, invoiceUrl }) {
+ const { funktion, formen, preisHinweis, danach } = feature.mails
+ return {
+ template: 'K15',
+ values: {
+ kunde_name: kundeName,
+ projekt,
+ funktion,
+ funktion_gen: formen.gen,
+ funktion_akk: formen.akk,
+ funktion_nom: formen.nom,
+ funktion_pron: formen.pron,
+ preis: einrichtungsPreis(feature),
+ preis_hinweis: preisHinweis,
+ zeit: feature.setupEstimate,
+ danach,
+ portal_url: portalUrl(feature),
+ rechnung_url: invoiceUrl || '',
+ },
+ blocks: { rechnung: Boolean(invoiceUrl) },
+ }
+}
+
+/** K16 (Funktion bereit) einer Funktion, Werte wie bei bestellMail aus dem Register-Eintrag. */
+export function bereitMail(feature, { kundeName, projekt }) {
+ const { funktion, formen, bereit, knopf } = feature.mails
+ return {
+ template: 'K16',
+ values: {
+ kunde_name: kundeName,
+ projekt,
+ funktion,
+ funktion_dein: formen.dein,
+ funktion_nom: formen.nom,
+ bereit,
+ knopf,
+ portal_url: portalUrl(feature),
+ },
+ }
+}
/** Ereignisse, die handleFeatureCheckoutEvent versteht (Funktions-Checkout: mode 'payment' mit featureKey). */
export const FEATURE_EVENT_TYPES = [
@@ -595,17 +648,12 @@ async function onFeaturePaid(session) {
}
if (customer?.email) {
try {
- await sendCustomerMail(customer.email, {
- template: 'K15',
- values: {
- kunde_name: customer.name || '',
- projekt: await projectName(doc.projectId),
- preis: eur(config.newsSetup.amountCents),
- zeit: config.funktionen.setupEstimate,
- rechnung_url: invoiceUrl,
- },
- blocks: { rechnung: Boolean(invoiceUrl) },
- })
+ const feature = featureConfig(doc.featureKey)
+ if (!feature) throw new Error(`Funktion ${doc.featureKey} nicht im Register`)
+ await sendCustomerMail(
+ customer.email,
+ bestellMail(feature, { kundeName: customer.name || '', projekt: await projectName(doc.projectId), invoiceUrl })
+ )
} catch (err) {
console.error('[funktionen] K15 fehlgeschlagen:', err.message)
}
@@ -647,10 +695,12 @@ export async function runActivation({ now = new Date(), customerId = null } = {}
try {
const customer = await customerOf(doc.customerId)
if (!customer?.email) continue
- await sendCustomerMail(customer.email, {
- template: 'K16',
- values: { kunde_name: customer.name || '', projekt: await projectName(doc.projectId), portal_url: portalUrl() },
- })
+ const feature = featureConfig(doc.featureKey)
+ if (!feature) throw new Error(`Funktion ${doc.featureKey} nicht im Register`)
+ await sendCustomerMail(
+ customer.email,
+ bereitMail(feature, { kundeName: customer.name || '', projekt: await projectName(doc.projectId) })
+ )
} catch (err) {
console.error(`[funktionen] K16 an Kunde ${doc.customerId} fehlgeschlagen:`, err.message)
}
diff --git a/test/featureMails.test.js b/test/featureMails.test.js
new file mode 100644
index 0000000..f8642f7
--- /dev/null
+++ b/test/featureMails.test.js
@@ -0,0 +1,302 @@
+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'
+import { schemaKeys } from './support/schema.js'
+
+// Mails K15 (Bestellung eingegangen) und K16 (Funktion bereit) je Funktion (Task B9a). Der News-Wortlaut ist als Literal
+// eingefroren (vor dem Umbau der Vorlagen aus den damaligen Mails uebernommen): "News-Mails bleiben woertlich".
+// B9b ergaenzt T16 und T19 in dieser Datei. websiteProjects, workorders und customers legt das Setup-Skript nicht an: ohne Schema.
+const aw = await startAppwriteMock({ schema: { portalFeatures: schemaKeys('portalFeatures') } })
+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 reg = await import('../server/services/featureRegistry.js')
+const sf = await import('../server/services/siteFeatures.js')
+const { loadTemplate, renderMail } = await import('../server/services/mailTemplates.js')
+const { setMailTransportForTests } = await import('../server/services/mailer.js')
+const { mailSink } = await import('./support/mailSink.js')
+
+const mails = mailSink()
+setMailTransportForTests(mails)
+after(() => setMailTransportForTests(null))
+
+// Vorlagenprobleme (unbekannte oder fehlende Platzhalter) meldet der Mailer nur als Warnung: hier mitschreiben
+const warnungen = []
+const origWarn = console.warn
+console.warn = (...args) => {
+ if (String(args[0]).startsWith('[mailer] Vorlage')) warnungen.push(args.join(' '))
+ else origWarn(...args)
+}
+after(() => {
+ console.warn = origWarn
+})
+
+aw.seed('customers', { $id: 'c1', name: 'Kunde Eins', location: 'Berlin', email: 'kunde1@example.test' })
+st.invoices.set('in_1', { id: 'in_1', object: 'invoice', hosted_invoice_url: 'https://invoice.stripe.test/i/1' })
+
+const BASE = 'https://project.webklar.com'
+const FOOTER = [
+ 'Viele Grüße',
+ 'Dein WEBklar-Team',
+ '',
+ `Kundenportal (${BASE}/dashboard.html)`,
+ '',
+ 'WEBklar GbR · Am Schwimmbad 10 · 67722 Winnweiler',
+ 'Telefon 0176 23726355 · support@webklar.com',
+ 'Vertreten durch die Gesellschafter Kenso Grimm und Justin Klein',
+ '',
+]
+
+let zaehler = 0
+/** Projekt (Kunde c1) anlegen und die Funktion bestellen: liefert { projectId, sessionId }. */
+async function bestelle(key, projectName) {
+ zaehler += 1
+ const projectId = `bm${zaehler}`
+ const sessionId = `cs_bm${zaehler}`
+ aw.seed('websiteProjects', { $id: projectId, customerId: 'c1', projectName })
+ await sf.markOrdered({ customerId: 'c1', projectId, key, sessionId, consent: {} })
+ return { projectId, sessionId }
+}
+
+const paidEvent = (sessionId, projectId, key, extra = {}) => ({
+ id: `evt_${sessionId}`,
+ object: 'event',
+ type: 'checkout.session.completed',
+ data: {
+ object: { id: sessionId, object: 'checkout.session', mode: 'payment', payment_status: 'paid', metadata: { customerId: 'c1', projectId, featureKey: key }, ...extra },
+ },
+})
+
+/** Bestellung bezahlen (Stripe-Ereignis) und die K15-Mail an den Kunden liefern. */
+async function bezahle(key, projectName, extra = {}) {
+ const { projectId, sessionId } = await bestelle(key, projectName)
+ const vor = mails.sent.length
+ await sf.handleFeatureCheckoutEvent(paidEvent(sessionId, projectId, key, extra))
+ const k15 = mails.sent.slice(vor).filter((m) => m.subject.startsWith('Deine Bestellung'))
+ assert.equal(k15.length, 1, `genau eine K15-Mail: ${mails.sent.slice(vor).map((m) => m.subject)}`)
+ return { projectId, sessionId, mail: k15[0] }
+}
+
+// ------------------------------------------------------------------------- News bleibt woertlich ---
+test('News-Mails bleiben wörtlich: K15 mit Rechnung', async () => {
+ const { mail } = await bezahle('news', 'Bäckerei', { invoice: 'in_1' })
+ assert.equal(mail.subject, 'Deine Bestellung: News-Pinnwand')
+ assert.equal(
+ mail.text,
+ [
+ 'WEBklar',
+ '',
+ 'Bestätigung',
+ '',
+ '✓ Bestellung eingegangen',
+ '',
+ 'Deine Bestellung: News-Pinnwand',
+ '',
+ 'Hallo Kunde Eins,',
+ 'vielen Dank für Deine Bestellung und Deine Zahlung. Wir richten die News-Pinnwand jetzt für Dein Projekt ein.',
+ '',
+ 'Funktion: News-Pinnwand – Einrichtung',
+ 'Projekt: Bäckerei',
+ 'Einmalig bezahlt: 30,00 € (brutto, einmalig; die Nutzung ist kostenlos, es läuft kein Abo)',
+ 'Einrichtung: meist innerhalb von 1–2 Wochen',
+ '',
+ 'Wie geht es weiter?',
+ 'Sobald die News-Pinnwand auf Deiner Website eingebaut ist, schalten wir sie im Kundenportal frei und Du bekommst eine weitere E-Mail. Danach kannst Du Beiträge im Portal schreiben.',
+ '',
+ 'Rechnung ansehen: https://invoice.stripe.test/i/1',
+ '',
+ `Zum Kundenportal: ${BASE}/dashboard.html#news`,
+ '',
+ ...FOOTER,
+ ].join('\n')
+ )
+ assert.deepEqual(mail.to.map((t) => t.address), ['kunde1@example.test'])
+})
+
+test('News-Mails bleiben wörtlich: K15 ohne Rechnung', async () => {
+ const { mail } = await bezahle('news', 'Café')
+ assert.equal(mail.subject, 'Deine Bestellung: News-Pinnwand')
+ assert.equal(
+ mail.text,
+ [
+ 'WEBklar',
+ '',
+ 'Bestätigung',
+ '',
+ '✓ Bestellung eingegangen',
+ '',
+ 'Deine Bestellung: News-Pinnwand',
+ '',
+ 'Hallo Kunde Eins,',
+ 'vielen Dank für Deine Bestellung und Deine Zahlung. Wir richten die News-Pinnwand jetzt für Dein Projekt ein.',
+ '',
+ 'Funktion: News-Pinnwand – Einrichtung',
+ 'Projekt: Café',
+ 'Einmalig bezahlt: 30,00 € (brutto, einmalig; die Nutzung ist kostenlos, es läuft kein Abo)',
+ 'Einrichtung: meist innerhalb von 1–2 Wochen',
+ '',
+ 'Wie geht es weiter?',
+ 'Sobald die News-Pinnwand auf Deiner Website eingebaut ist, schalten wir sie im Kundenportal frei und Du bekommst eine weitere E-Mail. Danach kannst Du Beiträge im Portal schreiben.',
+ '',
+ `Zum Kundenportal: ${BASE}/dashboard.html#news`,
+ '',
+ ...FOOTER,
+ ].join('\n')
+ )
+ assert.doesNotMatch(mail.text, /Rechnung ansehen/)
+})
+
+test('News-Mails bleiben wörtlich: K16', async () => {
+ const { projectId } = await bezahle('news', 'Bistro')
+ const doc = await sf.getFeatureDoc('c1', projectId, 'news')
+ aw.seed('workorders', { ...aw.docs('workorders').get(doc.ticketId), status: 'Closed' })
+ const vor = mails.sent.length
+ const done = await sf.runActivation({ customerId: 'c1' })
+ assert.deepEqual(done.map((d) => d.projectId), [projectId])
+ const gesendet = mails.sent.slice(vor)
+ assert.equal(gesendet.length, 1)
+ const [mail] = gesendet
+ assert.equal(mail.subject, 'Deine News-Pinnwand ist bereit')
+ assert.equal(
+ mail.text,
+ [
+ 'WEBklar',
+ '',
+ 'Bereit',
+ '',
+ '✓ News-Pinnwand',
+ '',
+ 'Deine News-Pinnwand ist bereit',
+ '',
+ 'Hallo Kunde Eins,',
+ 'die News-Pinnwand ist auf Deiner Website eingebaut und freigeschaltet. Du kannst ab sofort Beiträge schreiben, sie erscheinen direkt bei Dir auf der Seite.',
+ '',
+ 'Funktion: News-Pinnwand',
+ 'Projekt: Bistro',
+ '',
+ `Beitrag schreiben: ${BASE}/dashboard.html#news`,
+ '',
+ ...FOOTER,
+ ].join('\n')
+ )
+ assert.deepEqual(mail.to.map((t) => t.address), ['kunde1@example.test'])
+})
+
+// ------------------------------------------------------------------------------------- Termine ---
+test('Termine-Mails: K15 mit den Werten des Terminplaners', async () => {
+ const termine = config.features.termine.mails
+ const { mail } = await bezahle('termine', 'Salon Haarlinie', { invoice: 'in_1' })
+ assert.equal(mail.subject, 'Deine Bestellung: Terminplaner')
+ assert.doesNotMatch(mail.text, /News|Beitr/)
+ assert.doesNotMatch(mail.html, /News|Beitr/)
+ assert.match(mail.text, /Wir richten den Terminplaner jetzt für Dein Projekt ein\./)
+ assert.match(mail.text, /Funktion: Terminplaner – Einrichtung/)
+ assert.match(mail.text, /Projekt: Salon Haarlinie/)
+ assert.ok(mail.text.includes(`Einmalig bezahlt: 149,00 € (${termine.preisHinweis})`), mail.text)
+ assert.ok(
+ mail.text.includes(`Sobald der Terminplaner auf Deiner Website eingebaut ist, schalten wir ihn im Kundenportal frei und Du bekommst eine weitere E-Mail. ${termine.danach}`),
+ mail.text
+ )
+ assert.match(mail.text, /Rechnung ansehen: https:\/\/invoice\.stripe\.test\/i\/1/)
+ assert.ok(mail.text.includes(`Zum Kundenportal: ${BASE}/dashboard.html#termine`), mail.text)
+ assert.match(mail.html, new RegExp(`href="${BASE.replace(/\./g, '\\.')}/dashboard\\.html#termine"`))
+ assert.deepEqual(mail.to.map((t) => t.address), ['kunde1@example.test'])
+})
+
+test('Termine-Mails: K16 mit den Werten des Terminplaners', () => {
+ const termine = config.features.termine.mails
+ const nachricht = sf.bereitMail(reg.featureConfig('termine'), { kundeName: 'Kunde Eins', projekt: 'Salon Haarlinie' })
+ assert.equal(nachricht.template, 'K16')
+ const mail = renderMail(nachricht.template, nachricht.values, nachricht.blocks)
+ assert.deepEqual(mail.problems, [])
+ assert.equal(mail.subject, 'Dein Terminplaner ist bereit')
+ assert.doesNotMatch(mail.text, /News|Beitr/)
+ assert.doesNotMatch(mail.html, /News|Beitr/)
+ assert.match(mail.text, /Hallo Kunde Eins,\nder Terminplaner ist auf Deiner Website eingebaut und freigeschaltet\./)
+ assert.ok(mail.text.includes(termine.bereit), mail.text)
+ assert.match(mail.text, /Funktion: Terminplaner\nProjekt: Salon Haarlinie/)
+ assert.ok(mail.text.includes(`Termine öffnen: ${BASE}/dashboard.html#termine`), mail.text)
+})
+
+// ----------------------------------------------------------------------------- Platzhalter, Blöcke ---
+test('Platzhalter-/Blocklisten exakt: K15 und K16', () => {
+ const k15 = loadTemplate('K15')
+ assert.deepEqual(k15.placeholders, [
+ 'kunde_name',
+ 'projekt',
+ 'funktion',
+ 'funktion_gen',
+ 'funktion_akk',
+ 'funktion_nom',
+ 'funktion_pron',
+ 'preis',
+ 'preis_hinweis',
+ 'zeit',
+ 'danach',
+ 'portal_url',
+ 'rechnung_url',
+ ])
+ assert.deepEqual(k15.blocks, ['rechnung'])
+ assert.equal(k15.subject, 'Deine Bestellung: {{funktion}}')
+ const k16 = loadTemplate('K16')
+ assert.deepEqual(k16.placeholders, ['kunde_name', 'projekt', 'funktion', 'funktion_dein', 'funktion_nom', 'bereit', 'knopf', 'portal_url'])
+ assert.deepEqual(k16.blocks, [])
+ assert.equal(k16.subject, '{{funktion_dein}} ist bereit')
+})
+
+test('Die Mail-Werte je Funktion decken genau die Platzhalter der Vorlagen ab', () => {
+ const ctx = { kundeName: 'Kunde Eins', projekt: 'Salon', invoiceUrl: 'https://invoice.stripe.test/i/1' }
+ for (const key of reg.featureKeys()) {
+ const feature = reg.featureConfig(key)
+ const k15 = sf.bestellMail(feature, ctx)
+ const k16 = sf.bereitMail(feature, ctx)
+ assert.equal(k15.template, 'K15')
+ assert.equal(k16.template, 'K16')
+ assert.deepEqual(Object.keys(k15.values).sort(), [...loadTemplate('K15').placeholders].sort(), `${key}: K15`)
+ assert.deepEqual(Object.keys(k16.values).sort(), [...loadTemplate('K16').placeholders].sort(), `${key}: K16`)
+ assert.deepEqual(k15.blocks, { rechnung: true })
+ assert.deepEqual(sf.bestellMail(feature, { ...ctx, invoiceUrl: '' }).blocks, { rechnung: false })
+ for (const nachricht of [k15, k16]) {
+ const mail = renderMail(nachricht.template, nachricht.values, nachricht.blocks)
+ assert.deepEqual(mail.problems, [], `${key}: ${nachricht.template}`)
+ }
+ // Preis aus dem Katalog der Funktion (feature.product), nicht aus News
+ assert.equal(k15.values.preis, `${(config[feature.product].amountCents / 100).toFixed(2).replace('.', ',')} €`)
+ assert.equal(k15.values.portal_url, `${config.publicBaseUrl}/dashboard.html#${feature.returnHash}`)
+ assert.equal(k16.values.portal_url, k15.values.portal_url)
+ }
+})
+
+// ------------------------------------------------------------------------------------ Anhänge ---
+test('K15 ohne Anhänge: die Termine-Bestellung ruft keinen Registerhaken', async () => {
+ const termine = config.features.termine
+ const aufrufe = []
+ const alt = {}
+ const spion = (name) => (...args) => {
+ aufrufe.push(name)
+ return name === 'mails.anhaenge' ? [] : true
+ }
+ for (const name of ['verfuegbar', 'bestellpruefung', 'unterlagenBereit', 'belehrung', 'freischaltbar']) {
+ alt[name] = termine[name]
+ termine[name] = spion(name)
+ }
+ termine.mails.anhaenge = spion('mails.anhaenge')
+ try {
+ const { mail } = await bezahle('termine', 'Anhang-Test')
+ assert.ok(!mail.attachments || mail.attachments.length === 0, 'K15 trägt keinen Anhang')
+ assert.deepEqual(aufrufe, [])
+ } finally {
+ for (const name of Object.keys(alt)) {
+ if (alt[name] === undefined) delete termine[name]
+ else termine[name] = alt[name]
+ }
+ delete termine.mails.anhaenge
+ }
+})
+
+test('keine Vorlagenwarnungen in allen Abläufen dieser Datei', () => {
+ assert.deepEqual(warnungen, [])
+})
diff --git a/test/mailTemplates.test.js b/test/mailTemplates.test.js
index 74ab663..b885138 100644
--- a/test/mailTemplates.test.js
+++ b/test/mailTemplates.test.js
@@ -6,7 +6,7 @@ import { contractAttachmentFor, termsDocFor } from '../server/services/products.
const DIR = new URL('../server/mail-templates/', import.meta.url)
// G01–G08 Gästemails des Terminplaners (Task 9, neutrales Layout im Auftrag eines Betriebs), K20 und K21 Hinweise an den Betrieb;
-// K12, K14 und T12 (Wechsel ins Wartungs-Abo) aus Task 9, K13 und T13 (Zusatzspeicher) aus Task 8 (Fix 1); Endfassung der Texte in Task 12; T14 „Löschfristen“ aus Task 21 (F39); T15 Push-Zeitmail; K15, K16, T16 Funktionen (News-Pinnwand); T17 Repo zuordnen; K17 Chat-Hinweis an Kunden; K18, K19 Website-Analyse; T18 Bankzugang erneuern (Finanzen); T20 Terminplaner Betriebsmeldung (Terminplaner TP2, Team-Hinweis; T19 „Erstattung fällig“ folgt in Block B)
+// K12, K14 und T12 (Wechsel ins Wartungs-Abo) aus Task 9, K13 und T13 (Zusatzspeicher) aus Task 8 (Fix 1); Endfassung der Texte in Task 12; T14 „Löschfristen“ aus Task 21 (F39); T15 Push-Zeitmail; K15, K16, T16 Funktionen (News-Pinnwand, Terminplaner; K15 und K16 gelten je Funktion, Terminplaner TP2 B9a); T17 Repo zuordnen; K17 Chat-Hinweis an Kunden; K18, K19 Website-Analyse; T18 Bankzugang erneuern (Finanzen); T20 Terminplaner Betriebsmeldung (Terminplaner TP2, Team-Hinweis; T19 „Erstattung fällig“ folgt in Block B)
const ids = (prefix, count) => Array.from({ length: count }, (_, i) => `${prefix}${String(i + 1).padStart(2, '0')}`)
const EXPECTED = [...ids('G', 8), ...ids('K', 21), ...ids('T', 18), 'T20']
const GUEST = ids('G', 8)
@@ -70,6 +70,33 @@ test('T20: Betreff [Terminplaner], Platzhalter vorfall/details/zeit, keine Blöc
for (const line of ['Mailkontingent erreicht', 'Zeile 1\nZeile <2>', '04.10.2026, 10:00']) assert.ok(mail.text.includes(line), `Text enthält: ${line}\n---\n${mail.text}`)
})
+// Terminplaner TP2 (B9a): K15 und K16 gelten für jede Funktion des Registers; der Wortlaut je Funktion kommt aus den Platzhaltern
+test('K15, K16: Platzhalter und Blöcke je Funktion, keine Funktion fest im Text', () => {
+ const k15 = loadTemplate('K15')
+ assert.equal(k15.subject, 'Deine Bestellung: {{funktion}}')
+ assert.deepEqual(k15.placeholders, ['kunde_name', 'projekt', 'funktion', 'funktion_gen', 'funktion_akk', 'funktion_nom', 'funktion_pron', 'preis', 'preis_hinweis', 'zeit', 'danach', 'portal_url', 'rechnung_url'])
+ assert.deepEqual(k15.blocks, ['rechnung'])
+ const k16 = loadTemplate('K16')
+ assert.equal(k16.subject, '{{funktion_dein}} ist bereit')
+ assert.deepEqual(k16.placeholders, ['kunde_name', 'projekt', 'funktion', 'funktion_dein', 'funktion_nom', 'bereit', 'knopf', 'portal_url'])
+ assert.deepEqual(k16.blocks, [])
+ for (const tpl of [k15, k16]) assert.doesNotMatch(tpl.body, /News|Beitr|#news|#termine|Terminplaner/, `${tpl.id}: keine feste Funktion`)
+
+ const mail = renderMail('K15', { ...sampleValues(k15), rechnung_url: 'https://rechnung.example/1', portal_url: 'https://portal.example/#x' }, { rechnung: true })
+ assert.deepEqual(mail.problems, [])
+ assert.equal(mail.subject, 'Deine Bestellung: Wert-funktion')
+ for (const part of ['Wir richten Wert-funktion_akk jetzt für Dein Projekt ein.', 'Sobald Wert-funktion_nom auf Deiner Website eingebaut ist, schalten wir Wert-funktion_pron im Kundenportal frei', 'Wert-danach', 'Wert-preis (Wert-preis_hinweis)', 'Rechnung ansehen: https://rechnung.example/1', 'Zum Kundenportal: https://portal.example/#x']) {
+ assert.ok(mail.text.includes(part), `K15 enthält: ${part}\n---\n${mail.text}`)
+ }
+ assert.doesNotMatch(renderMail('K15', sampleValues(k15), { rechnung: false }).text, /Rechnung ansehen/)
+ const bereit = renderMail('K16', sampleValues(k16), {})
+ assert.deepEqual(bereit.problems, [])
+ assert.equal(bereit.subject, 'Wert-funktion_dein ist bereit')
+ for (const part of ['✓ Wert-funktion', 'Wert-funktion_nom ist auf Deiner Website eingebaut und freigeschaltet. Wert-bereit', 'Wert-knopf: Wert-portal_url']) {
+ assert.ok(bereit.text.includes(part), `K16 enthält: ${part}\n---\n${bereit.text}`)
+ }
+})
+
test('Werte werden HTML-sicher eingesetzt, Zeilenumbrüche werden ', () => {
const mail = renderMail('T01', { kunde_name: 'Max &"\'', nachricht: 'Zeile 1\nZeile <2>' })
assert.match(mail.html, /Max <b>&"' hat im Kundenportal geschrieben/)
|