Analyse: Einwilligungs-Historie, Nachweis beim Einschalten, Sperre ohne Verantwortlichen-Angaben, Textform für Mitarbeiter
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c6824f83a6
commit
3d05472b25
14 files changed
+585
-115
No files matched your search
+166
-21
@@ -7,11 +7,13 @@ import { schemaKeys } from './support/schema.js'
|
||||
import { mailSink } from './support/mailSink.js'
|
||||
|
||||
// Das Setup-Skript laedt config.js: erst nach useTestEnv() importieren, daher die Attributnamen hier fest
|
||||
const ANALYSE_KEYS = ['accentColor', 'avvVersion', 'avvAcceptedAt', 'avvAcceptedBy', 'activatedAt', 'offSince', 'privacyTicketId', 'activatedMailAt']
|
||||
const ANALYSE_KEYS = ['accentColor', 'avvVersion', 'avvAcceptedAt', 'avvAcceptedBy', 'activatedAt', 'offSince', 'privacyTicketId', 'activatedMailAt', 'avvConsentDate', 'avvConsentChannel', 'removalTicketId', 'publishTicketId']
|
||||
const CONSENT_KEYS = ['customerId', 'projectId', 'siteKey', 'event', 'avvVersion', 'via', 'acceptedAt', 'acceptedBy', 'textformDate', 'textformChannel']
|
||||
const aw = await startAppwriteMock({
|
||||
schema: {
|
||||
portalFeatures: [...schemaKeys('portalFeatures'), ...ANALYSE_KEYS],
|
||||
subscriptions: schemaKeys('subscriptions'),
|
||||
analyseConsents: CONSENT_KEYS,
|
||||
},
|
||||
})
|
||||
const st = await startFakeStripe()
|
||||
@@ -20,6 +22,8 @@ const { config } = await import('../server/config.js')
|
||||
const { wartungDoc, hosting2Doc } = await import('./support/fixtures.js')
|
||||
const an = await import('../server/services/analyse.js')
|
||||
const sf = await import('../server/services/siteFeatures.js')
|
||||
const cl = await import('../server/services/analyseConsent.js')
|
||||
const priv = await import('../server/services/analysePrivacy.js')
|
||||
const { updateDocument } = await import('../server/services/appwriteAdmin.js')
|
||||
const { setMailTransportForTests } = await import('../server/services/mailer.js')
|
||||
|
||||
@@ -36,18 +40,28 @@ an.analyseDeps.client = { putSite: async (siteKey, body) => puts.push({ siteKey,
|
||||
an.analyseDeps.rebuild = async (project) => rebuilds.push(project.$id)
|
||||
|
||||
const consent = () => ({ accepted: true, avvVersion: config.analyse.avvVersion })
|
||||
const actor = { name: 'Kunde Eins', email: 'eins@example.invalid' }
|
||||
const cust = (extra = {}) => ({ consent: consent(), actor, ...extra })
|
||||
const textform = { date: '2026-10-02', channel: 'email' }
|
||||
const NOW = new Date('2026-10-05T10:00:00.000Z')
|
||||
const consents = (p) => cl.listConsents(p)
|
||||
const analyseTickets = () => [...aw.docs('workorders').values()].filter((t) => String(t.topic).includes('Hinweis auf Analyse'))
|
||||
const doc = (c, p) => sf.getFeatureDoc(c, p, 'analyse')
|
||||
|
||||
aw.seed('customers', { $id: 'c1', name: 'Kunde Eins', email: 'eins@example.invalid', location: 'Berlin' })
|
||||
aw.seed('customers', { $id: 'c2', name: 'Kunde Zwei', email: 'zwei@example.invalid' })
|
||||
aw.seed('customers', { $id: 'c4', name: '', email: 'vier@example.invalid' })
|
||||
aw.seed('customers', { $id: 'c5', name: 'Kunde Fuenf', email: 'x' })
|
||||
aw.seed('customers', { $id: 'c3', name: 'Kunde Drei', email: 'drei@example.invalid' })
|
||||
aw.seed('subscriptions', wartungDoc)
|
||||
aw.seed('subscriptions', hosting2Doc)
|
||||
for (const c of ['c4', 'c5']) aw.seed('subscriptions', { ...wartungDoc, $id: `sub_w_${c}`, stripeSubscriptionId: `sub_w_${c}`, customerId: c })
|
||||
aw.seed('websiteProjects', { $id: 'p1', customerId: 'c1', projectName: 'Bäckerei', subdomain: 'baeckerei', liveDomain: 'https://Baeckerei.DE/start', isPublic: true, repoFullName: 'WEBklar/baeckerei' })
|
||||
aw.seed('websiteProjects', { $id: 'p2', customerId: 'c1', projectName: 'Privat', subdomain: 'privat', isPublic: false })
|
||||
aw.seed('websiteProjects', { $id: 'p3', customerId: 'c1', projectName: 'Ohne Sub', isPublic: true })
|
||||
aw.seed('websiteProjects', { $id: 'p4', customerId: 'c2', projectName: 'Hosting-Kunde', subdomain: 'hosting', isPublic: true })
|
||||
aw.seed('websiteProjects', { $id: 'p11', customerId: 'c4', projectName: 'Ohne Name', subdomain: 'ohnename', isPublic: true, repoFullName: 'WEBklar/ohnename' })
|
||||
aw.seed('websiteProjects', { $id: 'p12', customerId: 'c5', projectName: 'Schlechte Mail', subdomain: 'schlechtemail', isPublic: true })
|
||||
aw.seed('websiteProjects', { $id: 'p5', customerId: 'c3', projectName: 'Ohne Abo', subdomain: 'ohneabo', isPublic: true })
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -67,19 +81,19 @@ test('Berechtigung: Wartungs-Abo, öffentlich, Subdomain, Eigentum', async () =>
|
||||
})
|
||||
|
||||
test('Einschalten abgelehnt: Hosting-Abo, kein Abo, nicht öffentlich, AVV fehlt, Farbe', async () => {
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c2', projectId: 'p4', consent: consent() }), { status: 403 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c3', projectId: 'p5', consent: consent() }), { status: 403 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p2', consent: consent() }), { status: 409 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c2', projectId: 'p4', ...cust() }), { status: 403 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c3', projectId: 'p5', ...cust() }), { status: 403 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p2', ...cust() }), { status: 409 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p1' }), { status: 400, message: 'Bitte den Auftragsverarbeitungsvertrag bestätigen' })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p1', consent: { accepted: true, avvVersion: 'alt' } }), { status: 400 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p1', consent: { accepted: false, avvVersion: config.analyse.avvVersion } }), { status: 400 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p1', accentColor: 'rot', consent: consent() }), { status: 400 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p1', accentColor: 'rot', ...cust() }), { status: 400 })
|
||||
assert.equal(puts.length, 0)
|
||||
assert.equal(analyseTickets().length, 0)
|
||||
})
|
||||
|
||||
test('Einschalten: Dokument, Sammeldienst, Neubau, Ticket, Mail K18', async () => {
|
||||
const { doc: d, changed } = await an.activateAnalyse({ customerId: 'c1', projectId: 'p1', accentColor: '#1a73e8', consent: consent() })
|
||||
const { doc: d, changed } = await an.activateAnalyse({ customerId: 'c1', projectId: 'p1', accentColor: '#1a73e8', ...cust() })
|
||||
assert.equal(changed, true)
|
||||
assert.equal(d.featureKey, 'analyse')
|
||||
assert.equal(d.state, 'active')
|
||||
@@ -87,7 +101,7 @@ test('Einschalten: Dokument, Sammeldienst, Neubau, Ticket, Mail K18', async () =
|
||||
assert.match(d.siteKey, /^[a-z0-9]{16,40}$/)
|
||||
assert.equal(d.accentColor, '#1a73e8')
|
||||
assert.equal(d.avvVersion, config.analyse.avvVersion)
|
||||
assert.equal(d.avvAcceptedBy, 'customer')
|
||||
assert.equal(d.avvAcceptedBy, 'Kunde Eins')
|
||||
assert.ok(d.avvAcceptedAt && d.activatedAt)
|
||||
assert.deepEqual(puts, [{ siteKey: d.siteKey, projectId: 'p1', domains: ['baeckerei.project.webklar.com', 'baeckerei.de', 'www.baeckerei.de'], active: true }])
|
||||
assert.deepEqual(rebuilds, ['p1'])
|
||||
@@ -106,16 +120,17 @@ test('Einschalten: Dokument, Sammeldienst, Neubau, Ticket, Mail K18', async () =
|
||||
|
||||
test('Doppelt einschalten: kein zweites Ticket, keine zweite Mail, nur Farbe', async () => {
|
||||
const before = await doc('c1', 'p1')
|
||||
const same = await an.activateAnalyse({ customerId: 'c1', projectId: 'p1', accentColor: '#1a73e8', consent: consent() })
|
||||
const same = await an.activateAnalyse({ customerId: 'c1', projectId: 'p1', accentColor: '#1a73e8', ...cust() })
|
||||
assert.equal(same.changed, false)
|
||||
assert.equal(rebuilds.length, 0)
|
||||
const recolored = await an.activateAnalyse({ customerId: 'c1', projectId: 'p1', accentColor: '#CC0000', consent: consent() })
|
||||
const recolored = await an.activateAnalyse({ customerId: 'c1', projectId: 'p1', accentColor: '#CC0000', ...cust() })
|
||||
assert.equal(recolored.doc.accentColor, '#cc0000')
|
||||
assert.equal(recolored.doc.siteKey, before.siteKey)
|
||||
assert.deepEqual(rebuilds, ['p1'])
|
||||
assert.equal(analyseTickets().length, 1)
|
||||
assert.equal(mails.sent.length, 0)
|
||||
assert.equal(puts.length, 0)
|
||||
assert.equal((await consents('p1')).length, 1, 'Farbwechsel/zweites Aktivieren schreibt keine Historie')
|
||||
})
|
||||
|
||||
test('Ausschalten: off, offSince, Sammeldienst inaktiv, Neubau; erneut = nichts', async () => {
|
||||
@@ -132,15 +147,17 @@ test('Ausschalten: off, offSince, Sammeldienst inaktiv, Neubau; erneut = nichts'
|
||||
await assert.rejects(an.deactivateAnalyse({ customerId: 'c2', projectId: 'p1' }), { status: 403 })
|
||||
})
|
||||
|
||||
test('Wieder einschalten: gleicher siteKey, offSince leer, kein neues Ticket', async () => {
|
||||
test('Wieder einschalten: gleicher siteKey, offSince leer, neues Ticket und Historie', async () => {
|
||||
const before = await doc('c1', 'p1')
|
||||
const { doc: d } = await an.activateAnalyse({ customerId: 'c1', projectId: 'p1', consent: consent(), by: 'Kenso' })
|
||||
const { doc: d } = await an.activateAnalyse({ customerId: 'c1', projectId: 'p1', consent: consent(), by: 'Kenso', textform, now: NOW })
|
||||
assert.equal(d.siteKey, before.siteKey)
|
||||
assert.equal(d.state, 'active')
|
||||
assert.equal(d.offSince, '')
|
||||
assert.equal(d.accentColor, '#111111')
|
||||
assert.equal(d.avvAcceptedBy, 'Kenso')
|
||||
assert.equal(analyseTickets().length, 1)
|
||||
assert.equal(d.avvConsentDate, '2026-10-02')
|
||||
assert.equal(d.avvConsentChannel, 'email')
|
||||
assert.equal(analyseTickets().length, 2, 'neues Ticket nach Aus/An')
|
||||
})
|
||||
|
||||
test('Abo-Ende-Job: aktive Analyse ohne Wartungs-Abo wird beendet, K19', async () => {
|
||||
@@ -185,18 +202,18 @@ test('selbstheilend: Ticket scheitert einmal, Wiederholung holt Ticket, Neubau u
|
||||
return original(...args)
|
||||
}
|
||||
const before = analyseTickets().length
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p6', consent: consent() }), /Ticketsystem down/)
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p6', ...cust() }), /Ticketsystem down/)
|
||||
assert.equal((await doc('c1', 'p6')).state, 'active')
|
||||
assert.equal(rebuilds.length, 0)
|
||||
assert.equal(mails.sent.length, 0)
|
||||
const r = await an.activateAnalyse({ customerId: 'c1', projectId: 'p6', consent: consent() })
|
||||
const r = await an.activateAnalyse({ customerId: 'c1', projectId: 'p6', ...cust() })
|
||||
assert.equal(r.doc.state, 'active')
|
||||
assert.ok(r.doc.privacyTicketId && r.doc.activatedMailAt)
|
||||
assert.equal(analyseTickets().length, before + 1)
|
||||
assert.deepEqual(rebuilds, ['p6'])
|
||||
assert.equal(mails.sent.length, 1)
|
||||
// dritter Aufruf: nichts mehr offen
|
||||
await an.activateAnalyse({ customerId: 'c1', projectId: 'p6', consent: consent() })
|
||||
await an.activateAnalyse({ customerId: 'c1', projectId: 'p6', ...cust() })
|
||||
assert.equal(analyseTickets().length, before + 1)
|
||||
assert.deepEqual(rebuilds, ['p6'])
|
||||
assert.equal(mails.sent.length, 1)
|
||||
@@ -207,7 +224,7 @@ test('putSite scheitert: Dokument bleibt unverändert', async () => {
|
||||
aw.seed('websiteProjects', { $id: 'p7', customerId: 'c1', projectName: 'Down', subdomain: 'down', isPublic: true })
|
||||
const ok = an.analyseDeps.client
|
||||
an.analyseDeps.client = { putSite: async () => { throw Object.assign(new Error('Auswertung nicht erreichbar'), { status: 502 }) } }
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p7', consent: consent() }), { status: 502 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p7', ...cust() }), { status: 502 })
|
||||
assert.equal(await doc('c1', 'p7') === null || (await doc('c1', 'p7')).state === 'off', true)
|
||||
assert.equal(analyseTickets().filter((t) => t.details.includes('Down')).length, 0)
|
||||
an.analyseDeps.client = ok
|
||||
@@ -217,7 +234,7 @@ test('Neubau scheitert: Analyse bleibt aktiv, kein Fehler', async () => {
|
||||
aw.seed('websiteProjects', { $id: 'p8', customerId: 'c1', projectName: 'Bau', subdomain: 'bau', isPublic: true, repoFullName: 'WEBklar/bau' })
|
||||
const ok = an.analyseDeps.rebuild
|
||||
an.analyseDeps.rebuild = async () => { throw new Error('Runner weg') }
|
||||
const r = await an.activateAnalyse({ customerId: 'c1', projectId: 'p8', consent: consent() })
|
||||
const r = await an.activateAnalyse({ customerId: 'c1', projectId: 'p8', ...cust() })
|
||||
assert.equal(r.doc.state, 'active')
|
||||
assert.equal(mails.sent.length, 1)
|
||||
an.analyseDeps.rebuild = ok
|
||||
@@ -228,8 +245,8 @@ test('parallel einschalten: ein Ticket, eine Mail', async () => {
|
||||
const before = analyseTickets().length
|
||||
mails.sent.length = 0
|
||||
await Promise.all([
|
||||
an.activateAnalyse({ customerId: 'c1', projectId: 'p9', consent: consent() }),
|
||||
an.activateAnalyse({ customerId: 'c1', projectId: 'p9', consent: consent() }),
|
||||
an.activateAnalyse({ customerId: 'c1', projectId: 'p9', ...cust() }),
|
||||
an.activateAnalyse({ customerId: 'c1', projectId: 'p9', ...cust() }),
|
||||
])
|
||||
assert.equal(analyseTickets().length, before + 1)
|
||||
assert.equal(mails.sent.length, 1)
|
||||
@@ -239,8 +256,8 @@ test('gesperrte Analyse: Kunde 403, Mitarbeiter darf', async () => {
|
||||
aw.seed('websiteProjects', { $id: 'p10', customerId: 'c1', projectName: 'Gesperrt', subdomain: 'gesperrt', isPublic: true })
|
||||
const g = await sf.ensureFeatureDoc('c1', 'p10', 'analyse')
|
||||
await sf.disable(g.$id, {})
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p10', consent: consent() }), { status: 403, message: 'Analyse wurde gesperrt – bitte melde dich bei uns' })
|
||||
const r = await an.activateAnalyse({ customerId: 'c1', projectId: 'p10', consent: consent(), by: 'Kenso' })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p10', ...cust() }), { status: 403, message: 'Analyse wurde gesperrt – bitte melde dich bei uns' })
|
||||
const r = await an.activateAnalyse({ customerId: 'c1', projectId: 'p10', consent: consent(), by: 'Kenso', textform, now: NOW })
|
||||
assert.equal(r.doc.state, 'active')
|
||||
})
|
||||
|
||||
@@ -254,3 +271,131 @@ test('analyseDomains: www-/Apex-Gegenstück der Live-Domain, ohne Doppelte, max.
|
||||
// gespeicherter Host bleibt die Live-Domain (Heatmap-Link, Ticket)
|
||||
assert.deepEqual(an.analyseHosts({ subdomain: 'x', liveDomain: 'example.de' }), ['x.project.webklar.com', 'example.de'])
|
||||
})
|
||||
|
||||
// ---- Rechtsrunde Task 5: Verantwortlichen-Angaben, Historie, Textform ----
|
||||
|
||||
test('analysePrivacyData: Firma/Name, E-Mail, Bereinigung, Adresse', () => {
|
||||
const d = priv.analysePrivacyData
|
||||
assert.deepEqual(d({ companyName: '', name: '', email: 'a@b.de' }).missing, ['firma'])
|
||||
const nameOnly = d({ name: 'Max Muster', email: 'a@b.de' })
|
||||
assert.equal(nameOnly.company, 'Max Muster')
|
||||
assert.equal(nameOnly.ok, true)
|
||||
assert.deepEqual(nameOnly.missing, [])
|
||||
assert.deepEqual(d({ name: 'Max', email: 'abc' }).missing, ['email'])
|
||||
assert.deepEqual(d({ name: '', email: '' }).missing, ['firma', 'email'])
|
||||
assert.deepEqual(d(null).missing, ['firma', 'email'])
|
||||
assert.equal(d({ companyName: 'Muster\nGmbH\t& Co', email: 'a@b.de' }).company, 'Muster GmbH & Co')
|
||||
assert.equal(d({ name: 'M', email: 'a@b.de', street: 'Weg 1' }).address, 'Weg 1')
|
||||
assert.equal(d({ name: 'M', email: 'a@b.de', street: 'Weg 1', postalCode: '12345', city: 'Berlin' }).address, 'Weg 1, 12345 Berlin')
|
||||
assert.equal(d({ name: 'x'.repeat(300), email: 'a@b.de' }).company.length, 200)
|
||||
assert.deepEqual(d({ name: 'M', email: `${'a'.repeat(200)}@b.de` }).missing, ['email'])
|
||||
assert.deepEqual(d({ name: 'M', email: 'a b@c.de' }).missing, ['email'])
|
||||
})
|
||||
|
||||
test('validateTextform: Datum, Zukunft, Fassung, Weg', () => {
|
||||
const ctx = { today: '2026-10-05', minDate: '2026-10-02' }
|
||||
const bad = (t) => assert.throws(() => an.validateTextform(t, ctx), { status: 400 })
|
||||
bad({ date: '2026-10-01', channel: 'chat' })
|
||||
bad({ date: '2026-10-06', channel: 'chat' })
|
||||
bad({ date: '2026-02-30', channel: 'chat' })
|
||||
bad({ date: '02.10.2026', channel: 'chat' })
|
||||
bad({ date: '2026-10-02', channel: 'telefon' })
|
||||
bad({ date: '2026-10-02' })
|
||||
bad(undefined)
|
||||
assert.deepEqual(an.validateTextform({ date: '2026-10-02', channel: 'email' }, ctx), { date: '2026-10-02', channel: 'email' })
|
||||
assert.deepEqual(an.validateTextform({ date: '2026-10-05', channel: 'chat' }, ctx), { date: '2026-10-05', channel: 'chat' })
|
||||
})
|
||||
|
||||
test('Einschalten ohne Firma/Name oder mit ungültiger E-Mail: 409, nichts passiert', async () => {
|
||||
const before = analyseTickets().length
|
||||
for (const [c, p] of [['c4', 'p11'], ['c5', 'p12']]) {
|
||||
await assert.rejects(an.activateAnalyse({ customerId: c, projectId: p, ...cust() }), {
|
||||
status: 409,
|
||||
message: 'Für die Zusatzseite fehlen in Deinen Kundendaten Firma oder Name und eine gültige E-Mail-Adresse. Schreib uns im Chat, wir ergänzen sie.',
|
||||
})
|
||||
assert.equal((await doc(c, p)).state, 'off')
|
||||
}
|
||||
assert.equal(puts.length, 0)
|
||||
assert.equal(analyseTickets().length, before)
|
||||
assert.equal(mails.sent.length, 0)
|
||||
assert.equal((await consents('p11')).length, 0)
|
||||
})
|
||||
|
||||
test('Kunde ohne actor-Namen oder Mitarbeiter ohne Textform: 400', async () => {
|
||||
aw.seed('websiteProjects', { $id: 'p13', customerId: 'c1', projectName: 'Nachweis', subdomain: 'nachweis', isPublic: true })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p13', consent: consent() }), { status: 400 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p13', consent: consent(), actor: {} }), { status: 400 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p13', consent: consent(), by: 'Kenso', now: NOW }), { status: 400 })
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p13', by: 'Kenso', textform: { date: '2026-10-01', channel: 'chat' }, now: NOW }), { status: 400 })
|
||||
assert.equal(puts.length, 0)
|
||||
assert.equal((await consents('p13')).length, 0)
|
||||
})
|
||||
|
||||
test('Historie: Kunde, Aus, An durch Mitarbeiter in zeitlicher Folge; Portal-Dokument gleich', async () => {
|
||||
aw.seed('websiteProjects', { $id: 'p14', customerId: 'c1', projectName: 'Historie', subdomain: 'historie', isPublic: true })
|
||||
const { doc: d1 } = await an.activateAnalyse({ customerId: 'c1', projectId: 'p14', ...cust() })
|
||||
let h = await consents('p14')
|
||||
assert.equal(h.length, 1)
|
||||
assert.equal(h[0].event, 'on')
|
||||
assert.equal(h[0].via, 'portal')
|
||||
assert.equal(h[0].avvVersion, '2026-10-02')
|
||||
assert.equal(h[0].acceptedBy, 'Kunde Eins')
|
||||
assert.equal(h[0].customerId, 'c1')
|
||||
assert.equal(h[0].siteKey, d1.siteKey)
|
||||
assert.match(h[0].acceptedAt, /^\d{4}-\d\d-\d\dT[\d:.]+Z$/)
|
||||
assert.equal(h[0].acceptedAt, d1.avvAcceptedAt)
|
||||
assert.equal(d1.avvAcceptedBy, 'Kunde Eins')
|
||||
assert.equal(d1.avvConsentDate, '')
|
||||
assert.equal(d1.avvConsentChannel, '')
|
||||
// Farbwechsel und erneutes Aktivieren: keine neue Zeile
|
||||
await an.activateAnalyse({ customerId: 'c1', projectId: 'p14', accentColor: '#222222', ...cust() })
|
||||
await an.activateAnalyse({ customerId: 'c1', projectId: 'p14', ...cust() })
|
||||
assert.equal((await consents('p14')).length, 1)
|
||||
// Marker zurücksetzen beim Wiedereinschalten
|
||||
await updateDocument(config.collections.portalFeatures, d1.$id, { removalTicketId: 'r1', publishTicketId: 'u1' })
|
||||
await an.deactivateAnalyse({ customerId: 'c1', projectId: 'p14', now: NOW, actor })
|
||||
const { doc: d3 } = await an.activateAnalyse({ customerId: 'c1', projectId: 'p14', consent: consent(), by: 'Kenso', textform, now: NOW })
|
||||
assert.equal(d3.privacyTicketId && d3.privacyTicketId !== d1.privacyTicketId, true, 'neues Datenschutz-Ticket')
|
||||
assert.equal(d3.removalTicketId, '')
|
||||
assert.equal(d3.publishTicketId, '')
|
||||
h = await consents('p14')
|
||||
assert.deepEqual(h.map((x) => x.event), ['on', 'off', 'on'])
|
||||
assert.deepEqual(h.map((x) => x.via), ['portal', 'portal', 'woms'])
|
||||
assert.equal(h[1].acceptedBy, 'Kunde Eins')
|
||||
assert.equal(h[2].acceptedBy, 'Kenso')
|
||||
assert.equal(h[2].textformDate, '2026-10-02')
|
||||
assert.equal(h[2].textformChannel, 'email')
|
||||
assert.equal(d3.avvConsentDate, '2026-10-02')
|
||||
assert.equal(d3.avvAcceptedBy, 'Kenso')
|
||||
})
|
||||
|
||||
test('analyseConsent exportiert nur recordConsent und listConsents', () => {
|
||||
assert.deepEqual(Object.keys(cl).sort(), ['listConsents', 'recordConsent'])
|
||||
})
|
||||
|
||||
test('recordConsent scheitert: putSite wird zurückgenommen, Dokument bleibt aus', async () => {
|
||||
aw.seed('websiteProjects', { $id: 'p15', customerId: 'c1', projectName: 'Rollback', subdomain: 'rollback', isPublic: true })
|
||||
const prev = an.analyseDeps.recordConsent
|
||||
an.analyseDeps.recordConsent = async () => { throw new Error('Historie weg') }
|
||||
await assert.rejects(an.activateAnalyse({ customerId: 'c1', projectId: 'p15', ...cust() }), /Historie weg/)
|
||||
an.analyseDeps.recordConsent = prev
|
||||
assert.equal(puts.length, 2)
|
||||
assert.equal(puts[0].active, true)
|
||||
assert.equal(puts[1].active, false)
|
||||
assert.equal((await doc('c1', 'p15')).state, 'off')
|
||||
assert.equal(analyseTickets().filter((t) => t.details.includes('Rollback')).length, 0)
|
||||
})
|
||||
|
||||
test('Ausschalten schreibt off-Historie; Fehler dort verhindert das Ausschalten nicht', async () => {
|
||||
aw.seed('websiteProjects', { $id: 'p16', customerId: 'c1', projectName: 'Aus', subdomain: 'aus', isPublic: true })
|
||||
await an.activateAnalyse({ customerId: 'c1', projectId: 'p16', ...cust() })
|
||||
const prev = an.analyseDeps.recordConsent
|
||||
an.analyseDeps.recordConsent = async () => { throw new Error('Historie weg') }
|
||||
const r = await an.deactivateAnalyse({ customerId: 'c1', projectId: 'p16', now: NOW, actor })
|
||||
an.analyseDeps.recordConsent = prev
|
||||
assert.equal(r.doc.state, 'off')
|
||||
assert.deepEqual((await consents('p16')).map((x) => x.event), ['on'])
|
||||
await an.activateAnalyse({ customerId: 'c1', projectId: 'p16', ...cust() })
|
||||
await an.deactivateAnalyse({ customerId: 'c1', projectId: 'p16', now: NOW, actor })
|
||||
assert.deepEqual((await consents('p16')).map((x) => x.event), ['on', 'on', 'off'])
|
||||
})
|
||||
Reference in new issue
Block a user