diff --git a/tests/scripts/test_rename_sharepoint_files.py b/tests/scripts/test_rename_sharepoint_files.py index b9d56562b..c732383c7 100644 --- a/tests/scripts/test_rename_sharepoint_files.py +++ b/tests/scripts/test_rename_sharepoint_files.py @@ -124,6 +124,33 @@ def test_run_renames_files_for_property_under_batch_root(tmp_path: Path) -> None sp.rename_file.assert_called_once_with("id-1", "100_1 High St AB1 2CD_Survey.pdf") +def test_run_uprn_prefixed_address_yields_single_uprn_filename( + tmp_path: Path, +) -> None: + # Arrange + csv_path = _write_csv(tmp_path, [("100", "100_1 High St", "AB1 2CD")]) + batch_assessment = _assessment_path( + f"{BASE_PATH}/_Sero Batch 2", "100_1 High St", "AB1 2CD" + ) + + sp = MagicMock() + + def fake_get(path: str) -> dict[str, Any]: + if path == BASE_PATH: + return {"value": [_make_folder("_Sero Batch 2")]} + if path == batch_assessment: + return {"value": [_make_file("Survey.pdf", "id-1")]} + raise ValueError("not found") + + sp.get_folders_in_path.side_effect = fake_get + + # Act + SharepointRenamerOrchestrator(sp, csv_path).run() + + # Assert + sp.rename_file.assert_called_once_with("id-1", "100_1 High St AB1 2CD_Survey.pdf") + + # --------------------------------------------------------------------------- # _process_folder — files only at root level # ---------------------------------------------------------------------------