diff --git a/tests/orchestration/test_bulk_document_download_orchestrator.py b/tests/orchestration/test_bulk_document_download_orchestrator.py index b1b48830a..02400e16f 100644 --- a/tests/orchestration/test_bulk_document_download_orchestrator.py +++ b/tests/orchestration/test_bulk_document_download_orchestrator.py @@ -11,6 +11,7 @@ from datetime import datetime, timezone import pytest from moto import mock_aws +from domain.tasks.subtasks import SubTaskFailure from infrastructure.postgres.uploaded_file_table import FileTypeEnum, UploadedFile from infrastructure.s3.s3_client import S3Client from orchestration.bulk_document_download_orchestrator import ( @@ -111,3 +112,28 @@ def test_builds_uploads_and_emails_a_download_package(packages: S3Client) -> Non to, _subject, body = email.sent[0] assert to == "user@example.com" assert result.presigned_url in body + + +def test_a_selection_with_no_documents_is_a_recorded_failure( + packages: S3Client, +) -> None: + # Arrange — the selection resolves to no packageable documents. + email = _RecordingEmail() + orchestrator = BulkDocumentDownloadOrchestrator( + uploaded_files=_FakeUploadedFiles([]), + addresses=_FakeAddresses({}), + documents=_FakeDocuments({}), + packages=packages, + email=email, + url_ttl_seconds=3600, + ) + + # Act / Assert — a recorded SubTask failure, and nobody is emailed an empty + # package. + with pytest.raises(SubTaskFailure): + orchestrator.run( + landlord_property_ids=["LP1"], + recipient_email="user@example.com", + package_name="empty", + ) + assert email.sent == []