from __future__ import annotations from typing import Optional from uuid import UUID from applications.ara_first_run.ara_first_run_trigger_body import ( AraFirstRunTriggerBody, ) from applications.ara_first_run.handler import dispatch_first_run from orchestration.ara_first_run_pipeline import AraFirstRunCommand class _SpyPipeline: """Records the command it is asked to run, instead of composing stages.""" def __init__(self) -> None: self.received: Optional[AraFirstRunCommand] = None def run(self, command: AraFirstRunCommand) -> None: self.received = command def test_validates_the_event_body_and_delegates_the_command_to_the_pipeline() -> None: # Arrange — a raw SQS body, as the decorator hands it to the handler. body = { "task_id": "e295d89b-a7c5-4a9a-8b4e-b405fab1f298", "sub_task_id": "f4a9944f-41f0-4a33-8669-5016ec574068", "portfolio_id": 42, "property_ids": [101, 102], "scenario_ids": [7], } pipeline = _SpyPipeline() # Act dispatch_first_run(body, pipeline=pipeline) # Assert — the raw body was validated into the typed trigger and handed # straight on, untouched. received = pipeline.received assert isinstance(received, AraFirstRunTriggerBody) assert received.task_id == UUID("e295d89b-a7c5-4a9a-8b4e-b405fab1f298") assert received.portfolio_id == 42 assert received.property_ids == [101, 102] assert received.scenario_ids == [7]