import test from 'node:test' import assert from 'node:assert/strict' import { loadModule } from './load.mjs' const { EINRICHTUNG_ABRECHNUNGEN, einrichtungAbrechnung, countsToPlanVorgabe, countsToPlanWert, nachtragPlanFelder } = await loadModule('src/lib/planVorgabe.js') const abo = { einrichtungAbrechnung: 'abo' }, projekt = { einrichtungAbrechnung: 'projekt' } test('einrichtungAbrechnung: nur exakt abo oder projekt', () => { assert.deepEqual(EINRICHTUNG_ABRECHNUNGEN, ['abo', 'projekt']) assert.deepEqual([abo, projekt, {}, null, undefined, { einrichtungAbrechnung: 'Abo' }, { einrichtungAbrechnung: 5 }].map(einrichtungAbrechnung), ['abo', 'projekt', '', '', '', '', '']) }) test('countsToPlanVorgabe: nur Abo-Einrichtung mit erlaubten Stunden', () => { assert.equal(countsToPlanVorgabe(abo, true), true) for (const [t, ok] of [[abo, false], [abo, undefined], [projekt, true], [{}, true], [null, true]]) assert.equal(countsToPlanVorgabe(t, ok), false) }) test('countsToPlanWert: Vorgabe, späte Antwort des Abo-Status, Handwahl, Kommentar', () => { const w = (o) => countsToPlanWert({ gewaehlt: null, ticket: abo, aboHoursAllowed: true, isComment: false, ...o }) assert.equal(w({}), true) // unberührt: Vorgabe assert.equal(w({ aboHoursAllowed: false }), false) // Abo-Status lädt noch assert.equal(w({ aboHoursAllowed: true }), true) // …und kommt danach: die Vorgabe greift trotzdem assert.equal(w({ gewaehlt: false }), false) // von Hand abgehakt bleibt aus assert.equal(w({ gewaehlt: true, ticket: projekt }), true) // von Hand anhaken ist immer möglich assert.equal(w({ gewaehlt: true, aboHoursAllowed: false }), false) assert.equal(w({ ticket: projekt }), false) assert.equal(w({ ticket: {} }), false) for (const gewaehlt of [null, true, false]) assert.equal(w({ gewaehlt, isComment: true }), false) }) test('nachtragPlanFelder: nur das erste Nachtragen einer Git-Zeit auf einer Abo-Einrichtung', () => { const git = { serviceType: 'GIT', isComment: true, startTime: '', totalTime: 0, countsToPlan: false } const f = (o) => nachtragPlanFelder({ worksheet: git, ticket: abo, aboHoursAllowed: true, ...o }) assert.deepEqual(f({}), { countsToPlan: true }) assert.deepEqual(f({ ticket: projekt }), {}) assert.deepEqual(f({ ticket: {} }), {}) assert.deepEqual(f({ aboHoursAllowed: false }), {}) assert.deepEqual(f({ worksheet: { ...git, startTime: '0900', totalTime: 45 } }), {}) // Zeit ist schon eingetragen: Entscheidung bleibt assert.deepEqual(f({ worksheet: { ...git, countsToPlan: true } }), {}) assert.deepEqual(f({ worksheet: { serviceType: 'Remote', totalTime: 0, startTime: '' } }), {}) })