Files
alpenwerk-hr/tests/unit/verhaeltnis-standorte.test.ts
Andrei Laas 79979216e4
All checks were successful
CI / Lint, Typen, Tests, Build (push) Successful in 12m26s
CI / Migrationen auf leerer Datenbank (push) Successful in 10m22s
CI / Ausrollen (push) Successful in 7s
Standort Shop mit Unterauswahl; C-Level nur als Code; Sonstige im Import
Standort: locations.parent_id, eine Ebene. Neu "Shop" mit sechs Shops
(Shop W17, Shop Wodo, Shop Parndorf, Shop Donaupark, Shop W1, Shop Wien
Hauptbahnhof). Personen sitzen nur auf Standorten ohne Unterstandorte;
zwei Trigger halten das auch fuer Import und Nachtlauf fest. Einstellung,
Externe und Versetzung zeigen bei "Shop" eine zweite Auswahl
(StandortAuswahl). Filter in Liste und Berichten und die Importliste
bieten "Shop" selbst nicht an; der Import nennt bei "Shop" die Shops.
rauchtest.sql und vertragsangaben.sql waehlen einen zuweisbaren Standort.

C-Level: ueberall nur der Code (Formular, Akte, Zusammenfassung,
Historie, Berichte, Import). Export ohne Spalte "C-Level Bezeichnung".

Angehoerige und Notfallkontakte im Import wie im Formular: Auswahl als
feste Liste und daneben "Verhaeltnis (Sonstige)" fuer den eigenen Text.
Gespeichert wird bei "Sonstige" der Text; ein Text ohne "Sonstige" ist
ein Fehler. Der Download teilt einen eigenen Text in beide Spalten.

Geprueft: lint, tsc, types:check, npm test, waechter; Migrationen auf
leerer Datenbank zweimal (Nichts anzuwenden), rauchtest.sql,
vertragsangaben.sql; als alpenwerk_app: Einstellung auf "Shop" abgewiesen,
auf "Shop W17" angenommen, Wechsel auf "Shop" abgewiesen, auf "Shop Wodo"
angenommen, Unterstandort unter einem Shop abgewiesen.
2026-11-23 11:50:45 +01:00

80 lines
3.6 KiB
TypeScript

import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { BLATT_ANGEHOERIGE, BLATT_NOTFALLKONTAKTE } from "@/lib/austausch/katalog";
import { kurzname, oberstandorte, oberstandortVon, unterstandorte, zuweisbareStandorte } from "@/lib/standorte";
import { verhaeltnisAusDatei, verhaeltnisFuerDatei } from "@/lib/verhaeltnis";
describe("Verhältnis in der Austauschdatei", () => {
it("teilt einen frei eingetragenen Wert in „Sonstige“ und den Text", () => {
expect(verhaeltnisFuerDatei("Onkel")).toEqual({ auswahl: "Sonstige", sonstige: "Onkel" });
expect(verhaeltnisFuerDatei("Kind")).toEqual({ auswahl: "Kind", sonstige: null });
expect(verhaeltnisFuerDatei("Sonstige")).toEqual({ auswahl: "Sonstige", sonstige: null });
expect(verhaeltnisFuerDatei(null)).toEqual({ auswahl: null, sonstige: null });
});
it("speichert bei „Sonstige“ den Text, ohne Text „Sonstige“", () => {
expect(verhaeltnisAusDatei("Sonstige", " Nachbarin ")).toEqual({ wert: "Nachbarin" });
expect(verhaeltnisAusDatei("Sonstige", null)).toEqual({ wert: "Sonstige" });
expect(verhaeltnisAusDatei("Kind", null)).toEqual({ wert: "Kind" });
expect(verhaeltnisAusDatei(null, null)).toEqual({ wert: null });
});
it("weist einen Text ohne „Sonstige“ ab", () => {
expect(verhaeltnisAusDatei("Kind", "Onkel")).toHaveProperty("fehler");
expect(verhaeltnisAusDatei(null, "Onkel")).toHaveProperty("fehler");
});
it("hat in beiden Blättern die Spalte gleich hinter der Auswahl, die Auswahl ohne freie Eingabe", () => {
for (const [blatt, feld] of [
[BLATT_ANGEHOERIGE, "relationship"],
[BLATT_NOTFALLKONTAKTE, "relation"],
] as const) {
const i = blatt.spalten.findIndex((s) => s.feld === feld);
expect(blatt.spalten[i + 1].feld).toBe(`${feld}_sonstige`);
const format = blatt.spalten[i].format;
expect(format.art === "auswahl" && format.frei).toBeFalsy();
}
});
});
const ALLE = [
{ id: "hernals", name: "Wien-Hernals", parent_id: null },
{ id: "shop", name: "Shop", parent_id: null },
{ id: "w17", name: "Shop W17", parent_id: "shop" },
{ id: "hbf", name: "Shop Wien Hauptbahnhof", parent_id: "shop" },
];
describe("Standorte mit Unterstandorten", () => {
it("zeigt zuerst die oberste Ebene und unter „Shop“ die Shops", () => {
expect(oberstandorte(ALLE).map((s) => s.id)).toEqual(["hernals", "shop"]);
expect(unterstandorte(ALLE, "shop").map((s) => s.id)).toEqual(["w17", "hbf"]);
expect(unterstandorte(ALLE, "hernals")).toEqual([]);
expect(kurzname(ALLE[3], ALLE[1])).toBe("Wien Hauptbahnhof");
});
it("findet zu einem gespeicherten Shop die erste Auswahl", () => {
expect(oberstandortVon(ALLE, "w17")).toBe("shop");
expect(oberstandortVon(ALLE, "hernals")).toBe("hernals");
expect(oberstandortVon(ALLE, "")).toBe("");
});
it("bietet in Filtern nur Standorte an, auf denen jemand sitzen kann", () => {
expect(zuweisbareStandorte(ALLE).map((s) => s.id)).toEqual(["hernals", "w17", "hbf"]);
});
it("legt in der Migration genau die sechs Shops an", () => {
const sql = readFileSync(join(process.cwd(), "db/migrations/20261123140000_standort_shop.sql"), "utf8");
const einfuegen = sql.match(/from \(values ([^\n]+)\) v\(name\)\non conflict/)?.[1];
expect(einfuegen).toBeDefined();
expect([...einfuegen!.matchAll(/'([^']+)'/g)].map((m) => m[1])).toEqual([
"Shop W17",
"Shop Wodo",
"Shop Parndorf",
"Shop Donaupark",
"Shop W1",
"Shop Wien Hauptbahnhof",
]);
});
});