import pytest_mock
from temporalio.testing import ActivityEnvironment

from csirtmu.beta_temporal.config import Config as WorkerConfig
from csirtmu.beta_temporal.external_services.rt import structs
from csirtmu.beta_temporal.external_services.rt.client import RTClient
from csirtmu.beta_temporal.workflows.change_subject_of_automatic_report_on_correspond import (
    ChangeSubjectOfAutomaticReportOnCorrespondActivities,
)


class TestChangeSubjectOnAutomaticReport:
    async def test_is_automatic_report_true(
        self,
        worker_config: WorkerConfig,
        mock_transaction_obj: structs.TransactionStruct,
        test_activity_env: ActivityEnvironment,
        mock_ticket_data: structs.TicketData,
        mocker: pytest_mock.MockerFixture,
    ) -> None:
        assert mock_transaction_obj.ticket_obj is not None
        mock_ticket_data.attachments[0].subject = "[SHOULD NOT BE IN RESULT] Should be in result"

        get_ticket_data_mock = mocker.patch(
            "csirtmu.beta_temporal.workflows.change_subject_of_automatic_report_on_correspond.RTClient.get_ticket_data"
        )
        get_ticket_data_mock.return_value = mock_ticket_data

        edit_ticket_mock = mocker.patch(
            "csirtmu.beta_temporal.workflows.change_subject_of_automatic_report_on_correspond.RTClient.edit_ticket"
        )
        edit_ticket_mock.return_value = None

        activities = ChangeSubjectOfAutomaticReportOnCorrespondActivities(RTClient(worker_config.rt))
        await test_activity_env.run(activities.change_subject_on_automatic_report, mock_transaction_obj)

        get_ticket_data_mock.assert_called_once_with(mock_transaction_obj)
        edit_ticket_mock.assert_called_once_with(mock_transaction_obj.ticket_obj.id, Subject="Should be in result")
