fix(employees): remove history entries when deleting an employee (#5)

removeEmployee now also filters the deleted employee's history entries, so
no orphaned "(unbekannt)" rows remain. Adds a test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ferdi2goandClaude Opus 4.8 committed 2026-06-03 12:29:16 +00:00
1 parent 7b53618921
commit 142e0efa1f
2 files changed
+19 -1

No files matched your search

+17 -1
View File
@@ -1,5 +1,5 @@
import assert from 'node:assert/strict';
import { addHistoryEntries, removeHistoryEntry, loadFromJSON, saveToJSON, normalizeEmployees } from '../js/data.js';
import { addHistoryEntries, removeHistoryEntry, loadFromJSON, saveToJSON, normalizeEmployees, removeEmployee } from '../js/data.js';
function makeState(history = []) {
return {
@@ -164,4 +164,20 @@ function makeState(history = []) {
assert.ok(Array.isArray(loaded.employees[0].constraints.neverDays), 'constraints present after load');
}
// removeEmployee: also removes the employee's history entries (no orphans)
{
const state = {
employees: [{ id: 'a', name: 'Alice' }, { id: 'b', name: 'Bob' }],
calendar: { holidays: [], companyClosures: [] },
history: [
{ date: '2026-04-01', employeeId: 'a', manual: false },
{ date: '2026-04-02', employeeId: 'b', manual: false }
]
};
removeEmployee(state, 'a');
assert.equal(state.employees.length, 1, 'alice removed from employees');
assert.ok(!state.history.some(h => h.employeeId === 'a'), 'alice history removed');
assert.equal(state.history.length, 1, 'bob history untouched');
}
console.log('All data tests passed.');