Unterstützung: Rechenregel und Abzug im Abo-Stundenkonto
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c4fab31603
commit
7c6b0c906b
5 files changed
+148
-5
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { supportMinutes, parseSupporters, worksheetMinutes, firstName } from '../server/services/worksheetMinutes.js'
|
||||
|
||||
// Gleiche Faelle wie WOMS tests/unit/support.test.mjs (Rechenregel muss in beiden Systemen gleich sein)
|
||||
const andrej = { employeeId: 'a', name: 'Andrej Stevanovski', task: 'Farbkonzept' }
|
||||
const nico = { employeeId: 'n', name: 'Nico Rech', task: 'Texte' }
|
||||
|
||||
test('supportMinutes: Hälfte, aufgerundet auf 15', () => {
|
||||
const cases = [[15, 15], [30, 15], [45, 30], [60, 30], [75, 45], [70, 45], [0, 0], [-5, 0], ['60', 30], [null, 0]]
|
||||
for (const [total, expected] of cases) assert.equal(supportMinutes(total), expected, `${total}`)
|
||||
})
|
||||
|
||||
test('parseSupporters ist fehlertolerant', () => {
|
||||
assert.deepEqual(parseSupporters('kaputt'), [])
|
||||
assert.deepEqual(parseSupporters('{}'), [])
|
||||
assert.deepEqual(parseSupporters(null), [])
|
||||
assert.deepEqual(parseSupporters(''), [])
|
||||
const raw = '[{"employeeId":"a","name":"Andrej S","task":" Farbe "},{"employeeId":"a","name":"x","task":"y"},{"employeeId":"b","name":"Nico"},null,"x"]'
|
||||
assert.deepEqual(parseSupporters(raw), [{ employeeId: 'a', name: 'Andrej S', task: 'Farbe' }])
|
||||
assert.equal(parseSupporters([{ employeeId: 'a', name: 'A', task: 'x'.repeat(250) }])[0].task.length, 200)
|
||||
})
|
||||
|
||||
test('parseSupporters meldet kaputte Werte einmal mit Kontext', () => {
|
||||
const warned = []
|
||||
const orig = console.warn
|
||||
console.warn = (...args) => warned.push(args.join(' '))
|
||||
try {
|
||||
parseSupporters('kaputt', 'ws9')
|
||||
parseSupporters('[]', 'ws8')
|
||||
} finally {
|
||||
console.warn = orig
|
||||
}
|
||||
assert.equal(warned.length, 1)
|
||||
assert.match(warned[0], /\[unterstuetzung\] supporters unlesbar ws9/)
|
||||
})
|
||||
|
||||
test('worksheetMinutes: Arbeitszeit plus je Person die Unterstützung', () => {
|
||||
assert.equal(worksheetMinutes({ totalTime: 60, supporters: JSON.stringify([andrej, nico]) }), 120)
|
||||
assert.equal(worksheetMinutes({ totalTime: 70, supporters: JSON.stringify([andrej]) }), 115)
|
||||
assert.equal(worksheetMinutes({ totalTime: 45 }), 45)
|
||||
assert.equal(worksheetMinutes({ totalTime: 0, supporters: JSON.stringify([andrej]) }), 0)
|
||||
assert.equal(worksheetMinutes({ totalTime: 60, supporters: 'kaputt' }), 60)
|
||||
})
|
||||
|
||||
test('firstName', () => {
|
||||
assert.equal(firstName('Andrej Stevanovski'), 'Andrej')
|
||||
assert.equal(firstName(''), '')
|
||||
})
|
||||
Reference in new issue
Block a user