Files
perinco-CRM/server/test/acquisitionNotify.test.mjs
Sascha WolfandClaude Opus 5.5 019fa1a251 fix(akquise): Berater-Mail ohne Link ins CRM
Die Berater haben keinen Zugang zum CRM. Die Mail verlinkt nur noch die
Ausschreibung, falls hinterlegt; der Hinweis auf die Einstellungen in der
Fusszeile entfaellt ebenso. CRM_PUBLIC_URL wird nicht mehr gebraucht.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 11:04:23 +02:00

66 lines
2.6 KiB
JavaScript

/*
* Pruefungen der Berater-Mail (acquisitionNotify.js): laeuft mit `npm test`.
*
* Geprueft wird, wer eine Mail bekommt (nur neu hinzugekommene Berater) und
* dass der Mailtext Eingaben escaped - Titel und Beschreibung kommen aus
* Freitextfeldern und landen als HTML im Postfach des Beraters.
*/
const { addedConsultants, buildMessage } = await import('../src/acquisitionNotify.js');
let failures = 0;
function check(name, condition, detail = '') {
if (condition) {
console.log(` ok ${name}${detail ? ` - ${detail}` : ''}`);
} else {
console.log(` FAIL ${name}${detail ? ` - ${detail}` : ''}`);
failures += 1;
}
}
const same = (left, right) => JSON.stringify(left) === JSON.stringify(right);
console.log('\nWer bekommt eine Mail');
check('Anlegen: alle', same(addedConsultants(null, 'Nico, Lisa'), ['Nico', 'Lisa']));
check('Ohne Berater: niemand', same(addedConsultants(null, null), []));
check('Bearbeiten: nur neue', same(addedConsultants('Nico', 'Nico, Lisa'), ['Lisa']));
check('Schreibweise egal', same(addedConsultants('nico', 'Nico'), []));
check('Entfernen: niemand', same(addedConsultants('Nico, Lisa', 'Nico'), []));
console.log('\nMailtext');
const message = buildMessage(
{
id: 1,
title: 'SAP <script>',
company: 'ACME & Co',
provider: 'Hays',
daily_rate: 950,
start_date: '2026-11-01',
end_date: '2026-12-31',
link: 'https://example.com/p?a=1&b=2',
description: 'Zeile 1\nZeile 2',
created_by_name: 'Sascha Wolf',
},
'Jörg Müller'
);
check('Betreff mit Titel', message.subject === 'Du wurdest beworben: SAP <script>');
check('Sagt, dass beworben wurde', message.html.includes('<strong>beworben</strong>'));
check('Titel escaped', message.html.includes('SAP &lt;script&gt;') && !message.html.includes('<script>'));
check('Firma escaped', message.html.includes('ACME &amp; Co'));
check('Anrede mit Vorname', message.html.includes('Hallo Jörg,'));
check('Datum deutsch', message.html.includes('01.11.2026 bis 31.12.2026'));
check(
'Link sichtbar',
message.html.includes('<a href="https://example.com/p?a=1&amp;b=2">https://example.com/p?a=1&amp;b=2</a>')
);
check('Leere Felder fehlen', !message.html.includes('Projektpreis'));
check('Kein Link ins CRM', !/crm\.perinco|CRM/.test(message.html));
const withoutLink = buildMessage({ id: 2, title: 'Ohne Link', link: null }, 'Nico');
check('Ohne Link: kein <a>', !withoutLink.html.includes('<a ') && !withoutLink.html.includes('Link zum Projekt'));
console.log(
failures === 0 ? '\nAlle Pruefungen bestanden.' : `\n${failures} Pruefung(en) fehlgeschlagen.`
);
process.exit(failures === 0 ? 0 : 1);