import json
from unittest.mock import patch

from CommonServerPython import *
from BMCHelixRemedyforceCreateIncident import remove_extra_space_from_args, main,\
    ERROR_MESSAGES, get_field_id

DUMMY_COMMAND_RESPONSE = [{"Contents": {}}]


def fetch_dummy_incidents():
    """
    To fetch dummy response of incident.

    :return: dummy incident response
    :rtype: ``dict``
    """
    with open('./TestData/Incident.json', encoding='utf-8') as f:
        data = json.load(f)
    return data


def test_get_field_id_with_id():
    """
    Test-case to check field_id is passed then it should return that field_id.

    :return: None
    """
    actual_result = get_field_id("id", "name", "", {}, "ins")
    assert actual_result == "id"


@patch('demistomock.executeCommand')
def test_get_field_id_positive_scenario(mocker_execute_command):
    """
    When field_id is not passed and field_name passed as argument
    Then method should return field_id.

    :param mocker_execute_command: mocker object for executeCommand
    :return: None
    """
    mocker_execute_command.return_value = [{"Contents": {"records": [{"Id": "abc"}]}}]
    actual_result = get_field_id(None, "name", "", {}, "ins")