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:
1 parent
7b53618921
commit
142e0efa1f
2 files changed
+19
-1
No files matched your search
@@ -109,6 +109,8 @@ export function createEmployee(name) {
|
|||||||
|
|
||||||
export function removeEmployee(state, id) {
|
export function removeEmployee(state, id) {
|
||||||
state.employees = state.employees.filter(e => e.id !== id);
|
state.employees = state.employees.filter(e => e.id !== id);
|
||||||
|
// Also drop the employee's history entries so no orphaned "(unbekannt)" rows remain
|
||||||
|
state.history = state.history.filter(h => h.employeeId !== id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toggleHoliday(state, isoDate) {
|
export function toggleHoliday(state, isoDate) {
|
||||||
|
|||||||
+17
-1
@@ -1,5 +1,5 @@
|
|||||||
import assert from 'node:assert/strict';
|
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 = []) {
|
function makeState(history = []) {
|
||||||
return {
|
return {
|
||||||
@@ -164,4 +164,20 @@ function makeState(history = []) {
|
|||||||
assert.ok(Array.isArray(loaded.employees[0].constraints.neverDays), 'constraints present after load');
|
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.');
|
console.log('All data tests passed.');
|
||||||
Reference in new issue
Block a user