Tickets: Arbeitsblatt-Folgen und Zeilen-Logik als getestete Lib (Akquise-Ergebnis, Summen, Abo-Regel)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
32746727ed
commit
9fec381056
4 files changed
+192
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { loadModule } from './load.mjs'
|
||||
|
||||
const { createWorksheetFlow, acquisitionOutcome } = await loadModule('src/lib/worksheetFlow.js')
|
||||
async function run(ticket, newStatus, over = {}) {
|
||||
const calls = { ticket: [], customer: [] }
|
||||
const result = await createWorksheetFlow({
|
||||
ticket, worksheetData: { newStatus }, user: { $id: 'u' },
|
||||
createWorksheet: async () => over.result ?? { success: true },
|
||||
updateTicket: async (id, data) => { calls.ticket.push([id, data]) },
|
||||
updateCustomer: async (id, data) => { calls.customer.push([id, data]); if (over.customerFails) throw new Error('weg') },
|
||||
now: () => new Date('2026-10-05T10:00:00Z'),
|
||||
})
|
||||
return { result, calls }
|
||||
}
|
||||
const akq = { $id: 't1', type: 'Akquise', status: 'In Kontakt', customerId: 'c1' }
|
||||
test('Akquise + Zugesagt: Status zurückschreiben, Kunde fest', async () => {
|
||||
const { calls } = await run(akq, 'Zugesagt')
|
||||
assert.deepEqual(calls.ticket, [['t1', { status: 'Zugesagt' }]])
|
||||
assert.deepEqual(calls.customer, [['c1', { customerStatus: 'customer', updatedAt: '2026-10-05T10:00:00.000Z' }]])
|
||||
})
|
||||
test('Akquise + Abgesagt: Kunde verloren', async () => {
|
||||
assert.deepEqual((await run(akq, 'Abgesagt')).calls.customer, [['c1', { customerStatus: 'lost', updatedAt: '2026-10-05T10:00:00.000Z' }]])
|
||||
})
|
||||
test('Akquise + In Kontakt: keine Änderung', async () => {
|
||||
assert.deepEqual((await run(akq, 'In Kontakt')).calls, { ticket: [], customer: [] })
|
||||
assert.deepEqual((await run({ ...akq, status: 'Zugesagt' }, 'In Kontakt')).calls.customer, [])
|
||||
})
|
||||
test('Nicht-Akquise ändert nie den Kunden, Status nur bei Abweichung', async () => {
|
||||
for (const status of ['Zugesagt', 'Abgesagt', 'Closed']) assert.deepEqual((await run({ ...akq, type: 'Webpage', status: 'Open' }, status)).calls.customer, [])
|
||||
assert.deepEqual((await run({ ...akq, type: 'Webpage', status: 'Closed' }, 'Closed')).calls.ticket, [])
|
||||
assert.deepEqual((await run({ ...akq, customerId: '' }, 'Zugesagt')).calls.customer, [])
|
||||
})
|
||||
test('Fehlschlag und Kundenfehler', async () => {
|
||||
const failed = await run(akq, 'Zugesagt', { result: { success: false, error: 'x' } })
|
||||
assert.deepEqual(failed, { result: { success: false, error: 'x' }, calls: { ticket: [], customer: [] } })
|
||||
assert.equal((await run(akq, 'Zugesagt', { customerFails: true })).result.success, true)
|
||||
assert.equal(acquisitionOutcome({ type: 'Akquise', customerId: 'c' }, 'Zugesagt'), 'customer')
|
||||
})
|
||||
@@ -0,0 +1,45 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { loadModule } from './load.mjs'
|
||||
|
||||
const w = await loadModule('src/lib/worksheetView.js')
|
||||
const ws = (o = {}) => ({ totalTime: 60, isComment: false, countsToPlan: false, serviceType: 'Remote', ...o })
|
||||
const sup = (n, name = 'Anna Meier') => JSON.stringify(Array.from({ length: n }, (_, i) => ({ employeeId: 'e' + i, name, task: 'DNS' })))
|
||||
test('worksheetSums: Kommentare zählen nie, Abo nur countsToPlan, Zeiten offen', () => {
|
||||
const list = [ws(), ws({ supporters: sup(1), countsToPlan: true }), ws({ isComment: true, totalTime: 0 }), ws({ serviceType: 'GIT', isComment: true, totalTime: 0 }), ws({ serviceType: 'GIT', totalTime: 30, startTime: '0900' })]
|
||||
assert.deepEqual(w.worksheetSums(list), { totalMinutes: 180, aboMinutes: 90, openCount: 1 })
|
||||
assert.deepEqual(w.worksheetSums([]), { totalMinutes: 0, aboMinutes: 0, openCount: 0 })
|
||||
assert.deepEqual(w.worksheetSums([ws({ isComment: true, countsToPlan: true })]), { totalMinutes: 0, aboMinutes: 0, openCount: 0 })
|
||||
})
|
||||
test('showAboToggle: Regel bleibt exakt', () => {
|
||||
assert.equal(w.showAboToggle(ws(), true), true)
|
||||
assert.equal(w.showAboToggle(ws(), false), false)
|
||||
assert.equal(w.showAboToggle(ws({ countsToPlan: true }), false), true)
|
||||
assert.equal(w.showAboToggle(ws({ totalTime: 0 }), true), false)
|
||||
assert.equal(w.showAboToggle(ws({ isComment: true }), true), false)
|
||||
assert.equal(w.showAboToggle(ws({ totalTime: '45' }), true), true)
|
||||
})
|
||||
test('worksheetWhen: Start-, sonst Endzweig, Altwerte als Rohtext', () => {
|
||||
assert.deepEqual(w.worksheetWhen({ startDate: '2.5.2026', startTime: '0930', endDate: '2.5.2026', endTime: '1100' }), { date: '02.05.2026', time: '09:30' })
|
||||
assert.deepEqual(w.worksheetWhen({ startDate: '', startTime: '', endDate: '31.02.2026', endTime: '1405' }), { date: '31.02.2026', time: '14:05' })
|
||||
assert.deepEqual(w.worksheetWhen({ startDate: '03.10.2026', startTime: '' }), { date: '03.10.2026', time: '' })
|
||||
assert.deepEqual(w.worksheetWhen({}), { date: '', time: '' })
|
||||
})
|
||||
test('Art, Badge, Status danach, Zeit', () => {
|
||||
assert.equal(w.worksheetKindLabel(ws({ isComment: true })), 'Kommentar')
|
||||
assert.deepEqual(['Remote', 'On Site', 'Off Site', 'GIT'].map((s) => w.worksheetKindLabel(ws({ serviceType: s, isComment: s === 'GIT' }))), ['Fernwartung', 'Vor Ort', 'Fernwartung', 'GIT'])
|
||||
assert.deepEqual(w.worksheetBadge(ws({ serviceType: 'GIT', isComment: true, totalTime: 0 })), { tone: 'orange', text: 'Zeit offen' })
|
||||
assert.deepEqual(w.worksheetBadge(ws({ serviceType: 'GIT', startTime: '0900' })), { tone: 'green', text: 'Zeit eingetragen' })
|
||||
assert.equal(w.worksheetBadge(ws()), null)
|
||||
assert.equal(w.statusAfterLabel({ oldStatus: 'Open', newStatus: 'Occupied' }), 'Status danach: In Arbeit')
|
||||
assert.equal(w.statusAfterLabel({ oldStatus: 'Closed', newStatus: 'Open' }), 'Status danach: Offen')
|
||||
assert.equal(w.statusAfterLabel({ oldStatus: 'Open', newStatus: 'Completed' }), 'Status danach: Completed')
|
||||
for (const same of [{ oldStatus: 'Open', newStatus: 'Open' }, { oldStatus: 'Open', newStatus: '' }, {}]) assert.equal(w.statusAfterLabel(same), '')
|
||||
assert.deepEqual([ws({ isComment: true }), ws({ totalTime: 0 }), ws({ totalTime: 90 }), ws({ totalTime: '45' })].map(w.timeLabel), ['', '–', '1 h 30 min', '45 min'])
|
||||
})
|
||||
test('supportLines: je Person eine Zeile, Wörter wie bisher', () => {
|
||||
assert.deepEqual(w.supportLines(ws({ supporters: sup(1) })), ['Unterstützung Anna · DNS · 30 min'])
|
||||
assert.deepEqual(w.supportLines(ws({ totalTime: 75, supporters: sup(1, '') })), ['Unterstützung · DNS · 45 min'])
|
||||
assert.deepEqual(w.supportLines(ws({ isComment: true, supporters: sup(1) })), [])
|
||||
assert.deepEqual(w.supportLines(ws({ supporters: '{kaputt' })), [])
|
||||
})
|
||||
Reference in new issue
Block a user