import pytest

from backend.pashub_fetcher.pashub_to_ara_trigger_request import (
    PashubToAraTriggerRequest,
)


def make_request(pashub_link: str) -> PashubToAraTriggerRequest:
    return PashubToAraTriggerRequest(pashub_link=pashub_link)


def test_pashub_job_id_extracts_id_from_details_link() -> None:
    # Arrange
    request = make_request("https://pashub.net/jobs/job-id-123/details")

    # Act
    result = request.pashub_job_id

    # Assert
    assert result == "job-id-123"


def test_pashub_job_id_raises_for_invalid_link() -> None:
    # Arrange
    request = make_request("https://pashub.net/rcs-dashboard")

    # Act / Assert
    with pytest.raises(ValueError):
        request.pashub_job_id


def test_pashub_job_id_extracts_id_from_bare_job_link() -> None:
    # Arrange
    request = make_request("https://pashub.net/jobs/job-id-123")

    # Act
    result = request.pashub_job_id

    # Assert
    assert result == "job-id-123"


def test_pashub_job_id_extracts_id_from_evidence_view_link() -> None:
    # Arrange
    request = make_request("https://pashub.net/jobs/job-id-123/evidence/view")

    # Act
    result = request.pashub_job_id

    # Assert
    assert result == "job-id-123"
