"""Unit tests for ``_derive_dept_hierarchy``. The Google ``Department_Information`` custom schema has 4 slots (L1-L4 Dept). SuccessFactors ``cust_L0`` is the legal entity (e.g. "PingCAP") and including it as L1 pushes the real top business unit down into L2 — which Google admins read as "Engineering Group is a sub-unit of PingCAP". The handler now strips configured root segments before mapping into the L1-L4 slots. """ from __future__ import annotations from app.scheduled_jobs.google_handlers import _derive_dept_hierarchy def test_drops_company_root_when_configured() -> None: levels = _derive_dept_hierarchy( "PingCAP / Engineering Group / Global Cloud & Customer Support" " / Support Engineering", level_max=4, drop_root_segments=["PingCAP"], ) assert levels == [ "Engineering Group", "Global Cloud & Customer Support", "Support Engineering", ] def test_drop_root_is_case_insensitive() -> None: levels = _derive_dept_hierarchy( "pingcap / Engineering Group / Team", drop_root_segments=["PingCAP"], ) assert levels == ["Engineering Group", "Team"] def test_no_drop_when_root_not_in_list() -> None: levels = _derive_dept_hierarchy( "Acme / Engineering / Team", drop_root_segments=["PingCAP"], ) assert levels == ["Acme", "Engineering", "Team"] def test_no_drop_when_list_empty() -> None: levels = _derive_dept_hierarchy( "PingCAP / Engineering / Team", drop_root_segments=[], ) assert levels == ["PingCAP", "Engineering", "Team"] def test_drop_then_truncate_when_over_max() -> None: """Drop root first, then take deepest level_max if still too long.""" levels = _derive_dept_hierarchy( "PingCAP / A / B / C / D / E", level_max=4, drop_root_segments=["PingCAP"], ) assert levels == ["B", "C", "D", "E"] def test_empty_path_returns_empty() -> None: assert _derive_dept_hierarchy(None, drop_root_segments=["PingCAP"]) == [] assert _derive_dept_hierarchy("", drop_root_segments=["PingCAP"]) == [] assert _derive_dept_hierarchy( "PingCAP", drop_root_segments=["PingCAP"], ) == []