Lead zum festen Kunden nur mit Kundenart
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
463aaf1066
commit
58bb956645
5 files changed
+62
-6
No files matched your search
@@ -2,7 +2,7 @@ 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')
|
||||
const { createWorksheetFlow, acquisitionOutcome, KUNDENART_ZUGESAGT_HINWEIS } = await loadModule('src/lib/worksheetFlow.js')
|
||||
async function run(ticket, newStatus, over = {}) {
|
||||
const calls = { ticket: [], customer: [] }
|
||||
const result = await createWorksheetFlow({
|
||||
@@ -10,6 +10,7 @@ async function run(ticket, newStatus, over = {}) {
|
||||
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') },
|
||||
getCustomer: 'getCustomer' in over ? over.getCustomer : async () => ({ kundenart: 'unternehmen' }),
|
||||
now: () => new Date('2026-10-05T10:00:00Z'),
|
||||
})
|
||||
return { result, calls }
|
||||
@@ -38,3 +39,32 @@ test('Fehlschlag und Kundenfehler', async () => {
|
||||
assert.equal((await run(akq, 'Zugesagt', { customerFails: true })).result.success, true)
|
||||
assert.equal(acquisitionOutcome({ type: 'Akquise', customerId: 'c' }, 'Zugesagt'), 'customer')
|
||||
})
|
||||
test('Zugesagt mit gesetzter Kundenart (unternehmen, privat): Kunde fest, kein Hinweis', async () => {
|
||||
for (const kundenart of ['unternehmen', 'privat']) {
|
||||
const { calls, result } = await run(akq, 'Zugesagt', { getCustomer: async () => ({ kundenart }) })
|
||||
assert.deepEqual(calls.customer, [['c1', { customerStatus: 'customer', updatedAt: '2026-10-05T10:00:00.000Z' }]], kundenart)
|
||||
assert.equal(result.hinweis, undefined)
|
||||
}
|
||||
})
|
||||
test('Zugesagt ohne gültige Kundenart: Blatt und Ticketstatus bleiben, der Lead bleibt Lead, Hinweis', async () => {
|
||||
for (const kundenart of [undefined, '', 'Unternehmen', 'firma', ' privat']) {
|
||||
const { calls, result } = await run(akq, 'Zugesagt', { getCustomer: async () => ({ kundenart }) })
|
||||
assert.deepEqual(calls, { ticket: [['t1', { status: 'Zugesagt' }]], customer: [] }, String(kundenart))
|
||||
assert.equal(result.success, true)
|
||||
assert.equal(result.hinweis, KUNDENART_ZUGESAGT_HINWEIS)
|
||||
}
|
||||
})
|
||||
test('Kunde nicht ladbar, null oder ohne getCustomer: wie ohne Kundenart', async () => {
|
||||
for (const getCustomer of [async () => { throw new Error('weg') }, async () => null, undefined]) {
|
||||
const { calls, result } = await run(akq, 'Zugesagt', { getCustomer })
|
||||
assert.deepEqual(calls.customer, [])
|
||||
assert.equal(result.hinweis, KUNDENART_ZUGESAGT_HINWEIS)
|
||||
}
|
||||
})
|
||||
test('Abgesagt und andere Ergebnisse brauchen keine Kundenart und laden den Kunden nicht', async () => {
|
||||
let geladen = 0
|
||||
const getCustomer = async () => { geladen += 1; return {} }
|
||||
assert.deepEqual((await run(akq, 'Abgesagt', { getCustomer })).calls.customer, [['c1', { customerStatus: 'lost', updatedAt: '2026-10-05T10:00:00.000Z' }]])
|
||||
await run(akq, 'In Kontakt', { getCustomer })
|
||||
assert.equal(geladen, 0)
|
||||
})
|
||||
Reference in new issue
Block a user