Files
Betriebsf-hrungssoftware/test/personal.test.ts
Claude 859a076e83
Some checks failed
Prüfung / tests (push) Has been cancelled
Prüfung / container (push) Has been cancelled
Personal: Stammdaten, Arbeitszeitmodell, Abwesenheiten, Urlaubskonto (0.8.0)
Stufe 2, Schritt 2 (M1, M8, M4, M10-Konto). Modelle mit Gültig-ab, Abwesenheiten
ganztags, halbtags oder stundengenau, Verfügbarkeit je Tag als Grundlage für
T15/T16. Lohnkosten je Stunde nur für den Inhaber (nurInhaber in TABELLEN).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AmyPfuNc4sCRfaF3oURXZz
2026-10-20 06:33:33 +00:00

71 lines
3.8 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect } from "vitest";
import { type Abwesenheit, type Modell, modellAm, modellText, sollStunden, urlaubskonto, urlaubstage, verfuegbarkeit } from "../src/domain/personal.js";
const K = "k1";
const modelle: Modell[] = [
{ kontakt_id: K, gueltig_ab: "2026-01-01", stunden: [8, 8, 8, 8, 6, 0, 0] },
// ab November Teilzeit: Mittwoch frei, Donnerstag 4 Stunden (Beispiel aus M8)
{ kontakt_id: K, gueltig_ab: "2026-11-01", stunden: [8, 8, 0, 4, 0, 0, 0] },
];
const ab = (x: Partial<Abwesenheit>): Abwesenheit => ({ kontakt_id: K, art: "urlaub", von: "2026-10-26", bis: "2026-10-26", status: "genehmigt", ...x });
describe("Arbeitszeitmodell (M8)", () => {
it("gilt ab seinem Datum, frühere Tage behalten das alte Modell", () => {
expect(modellAm(modelle, K, "2026-10-31")!.gueltig_ab).toBe("2026-01-01");
expect(modellAm(modelle, K, "2026-11-01")!.gueltig_ab).toBe("2026-11-01");
expect(sollStunden(modelle, K, "2026-10-28")).toBe(8); // Mi vorher
expect(sollStunden(modelle, K, "2026-11-04")).toBe(0); // Mi nachher frei
expect(sollStunden(modelle, K, "2026-11-05")).toBe(4); // Do 4 h
});
it("ohne Modell Mo–Fr nach Einstellung, Feiertage 0", () => {
expect(sollStunden([], "x", "2026-10-30")).toBe(8); // Freitag
expect(sollStunden([], "x", "2026-10-31")).toBe(0); // Reformationstag (SH) und Samstag
expect(sollStunden(modelle, K, "2026-12-25")).toBe(0);
expect(sollStunden([], "x", "2026-10-27", 7.5)).toBe(7.5);
});
it("Text", () => {
expect(modellText([8, 8, 0, 4, 0, 0, 0])).toBe("Mo 8 · Di 8 · Do 4 = 20 Std.");
expect(modellText([8.5, 8.5, 8.5, 8.5, 6, 0, 0])).toBe("Mo 8,5 · Di 8,5 · Mi 8,5 · Do 8,5 · Fr 6 = 40 Std.");
});
});
describe("Verfügbarkeit (M4, M8)", () => {
it("Urlaub, halber Tag, stundengenaue Sperre; beantragter Urlaub sperrt noch nicht", () => {
const abw: Abwesenheit[] = [
ab({ von: "2026-10-19", bis: "2026-10-20" }),
ab({ von: "2026-10-21", bis: "2026-10-21", halbtag: true }),
ab({ art: "sperre", von: "2026-10-22", bis: "2026-10-22", stunden: 4 }),
ab({ von: "2026-10-23", bis: "2026-10-23", status: "beantragt" }),
ab({ art: "krank", von: "2026-10-26", bis: "2026-10-26", status: "abgelehnt" }),
];
const t = verfuegbarkeit(modelle, abw, K, "2026-10-19", "2026-10-26");
expect(t.map((x) => x.frei)).toEqual([0, 0, 4, 4, 6, 0, 0, 8]);
expect(t[4]!.abwesend.map((a) => a.status)).toEqual(["beantragt"]);
expect(t[7]!.abwesend).toEqual([]);
});
it("Sperre mit mehr Stunden als Soll nimmt höchstens das Soll", () => {
const t = verfuegbarkeit(modelle, [ab({ art: "sperre", von: "2026-11-05", bis: "2026-11-05", stunden: 6 })], K, "2026-11-05", "2026-11-05");
expect(t[0]!.frei).toBe(0);
});
});
describe("Urlaubskonto (M10)", () => {
it("zählt nur Tage mit Soll, Feiertage nicht, halbe Tage halb", () => {
// 23.12.–2.1. im Teilzeitmodell (Mi frei): Do 24., Mo 28., Di 29., Do 31.; 25.12. und 1.1. Feiertag
const a = ab({ von: "2026-12-23", bis: "2027-01-02" });
expect(urlaubstage(a, modelle, 2026)).toBe(4);
expect(urlaubstage(a, modelle, 2027)).toBe(0);
expect(urlaubstage(ab({ von: "2026-10-27", bis: "2026-10-27", halbtag: true }), modelle, 2026)).toBe(0.5);
});
it("genommen, geplant, beantragt, Rest", () => {
const abw = [
ab({ von: "2026-03-02", bis: "2026-03-06" }), // 5 Tage (Mo–Fr, altes Modell)
ab({ von: "2026-10-30", bis: "2026-10-30", halbtag: true }), // Fr, halber Tag
ab({ von: "2026-11-09", bis: "2026-11-13" }), // neues Modell: Mo, Di, Do → 3 Tage, geplant
ab({ von: "2026-11-16", bis: "2026-11-17", status: "beantragt" }), // 2
];
const k = urlaubskonto(K, 2026, "2026-10-30", 30, 2.5, abw, modelle);
expect(k).toEqual({ jahr: 2026, anspruch: 30, uebertrag: 2.5, genommen: 5.5, geplant: 3, beantragt: 2, rest: 24 });
});
});