Titel (vorangestellt): fachlich vorgegebene Liste
All checks were successful
CI / Lint, Typen, Tests, Build (push) Successful in 12m32s
CI / Migrationen auf leerer Datenbank (push) Successful in 11m11s
CI / Ausrollen (push) Successful in 7s

Neu: DI, Dipl.-Ing. (FH), DI (FH); Reihenfolge wie vorgegeben. Jeder
gespeicherte Titel steht auch in der neuen Liste. Migration
20261103100000 ersetzt chk_title_prefix_valid; lib/titles.ts fuehrt
dieselbe Liste fuer Formulare und Austauschdatei, tests/unit/titel.test.ts
gleicht beide ab.

Geprueft: lint, tsc, types:check, 1034 Tests, Waechter; alle Migrationen
auf leerer Datenbank (zweiter Lauf nichts anzuwenden), Rauchtest.
This commit is contained in:
2026-11-03 10:20:11 +01:00
parent 912ea38413
commit ebbb158bd3
3 changed files with 84 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
-- Vorangestellte Titel: fachlich vorgegebene Liste.
--
-- Jeder gespeicherte Titel steht auch in dieser Liste und bleibt damit
-- gültig. Dieselbe Liste und Reihenfolge
-- steht in lib/titles.ts (Auswahl in Formularen und Austauschdatei);
-- tests/unit/titel.test.ts gleicht beide ab.
alter table employees drop constraint if exists chk_title_prefix_valid;
alter table employees add constraint chk_title_prefix_valid check (
title_prefix <@ array[
'Dr.', 'DDr.', 'Mag.', 'MMag.', 'Dipl.-Ing.', 'DI', 'Ing.', 'Mag. (FH)',
'Dipl.-Ing. (FH)', 'DI (FH)', 'Dkfm.', 'Prof.', 'Priv.-Doz.'
]::text[]
);
do $pruefung$
declare
v_def text;
begin
select pg_get_constraintdef(oid) into v_def from pg_constraint where conname = 'chk_title_prefix_valid';
if v_def is null or position('''DI (FH)''' in v_def) = 0 or position('''Priv.-Doz.''' in v_def) = 0 then
raise exception 'chk_title_prefix_valid kennt die vorgegebenen Titel nicht.';
end if;
end
$pruefung$;

View File

@@ -3,6 +3,24 @@
// and nachgestellte akademische Grade (suffix, mostly Bologna-system // and nachgestellte akademische Grade (suffix, mostly Bologna-system
// Bachelor's/Master's degrees, follow the name after a comma). A person can // Bachelor's/Master's degrees, follow the name after a comma). A person can
// hold several of either. // hold several of either.
export const TITLE_PREFIXES: string[] = ["Dr.", "DDr.", "Dipl.-Ing.", "Ing.", "Mag.", "Mag. (FH)", "MMag.", "Dkfm.", "Priv.-Doz.", "Prof."]; //
// Die vorangestellten Titel sind fachlich vorgegeben, in dieser Reihenfolge.
// Dieselbe Liste prüft die Datenbank (chk_title_prefix_valid, Migration
// 20261103100000); tests/unit/titel.test.ts gleicht beide ab.
export const TITLE_PREFIXES: string[] = [
"Dr.",
"DDr.",
"Mag.",
"MMag.",
"Dipl.-Ing.",
"DI",
"Ing.",
"Mag. (FH)",
"Dipl.-Ing. (FH)",
"DI (FH)",
"Dkfm.",
"Prof.",
"Priv.-Doz.",
];
export const TITLE_SUFFIXES: string[] = ["BA", "BSc", "BEd", "BBA", "LLB", "MA", "MSc", "MBA", "MEd", "LLM", "PhD", "MBL"]; export const TITLE_SUFFIXES: string[] = ["BA", "BSc", "BEd", "BBA", "LLB", "MA", "MSc", "MBA", "MEd", "LLM", "PhD", "MBL"];

41
tests/unit/titel.test.ts Normal file
View File

@@ -0,0 +1,41 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { TITLE_PREFIXES } from "@/lib/titles";
// Die vorangestellten Titel stehen in der Migration als CHECK und hier für die
// Auswahl. Laufen die beiden auseinander, bietet das Formular einen Titel an,
// den die Datenbank abweist.
const MIGRATION = join(process.cwd(), "db/migrations/20261103100000_titel_vorangestellt.sql");
function werteAusDerBedingung(): string[] {
const sql = readFileSync(MIGRATION, "utf8");
const block = sql.match(/add constraint chk_title_prefix_valid check[\s\S]*?\);/)?.[0];
expect(block, "Die Bedingung steht nicht mehr in der Migration").toBeDefined();
return [...block!.matchAll(/'([^']+)'/g)].map((m) => m[1]);
}
describe("Die vorangestellten Titel", () => {
it("stimmen mit der Bedingung in der Datenbank überein, in derselben Reihenfolge", () => {
expect(werteAusDerBedingung()).toEqual(TITLE_PREFIXES);
});
it("folgen der fachlichen Vorgabe", () => {
expect(TITLE_PREFIXES).toEqual([
"Dr.",
"DDr.",
"Mag.",
"MMag.",
"Dipl.-Ing.",
"DI",
"Ing.",
"Mag. (FH)",
"Dipl.-Ing. (FH)",
"DI (FH)",
"Dkfm.",
"Prof.",
"Priv.-Doz.",
]);
});
});