import pytest

from workflow_engine.nodes import ConstantStringNode


@pytest.mark.unit
def test_constant_string_node_type_info():
    """Test ConstantStringNode TYPE_INFO metadata."""
    assert ConstantStringNode.TYPE_INFO.model_dump() == {
        "description": "A node that outputs a constant string value.",
        "display_name": "ConstantString",
        "max_retries": None,
        "name": "ConstantString",
        "parameter_schema": {  # generated by Pydantic, we have little control over this
            "$defs": {
                "StringValue": {
                    "type": "string",
                    "title": "StringValue",
                },
            },
            "additionalProperties": False,
            "properties": {
                "value": {
                    "$ref": "#/$defs/StringValue",
                    "title": "Value",
                    "description": "The constant string value.",
                },
            },
            "required": ["value"],
            "title": "ConstantString",
            "type": "object",
        },
        "version": "0.4.0",
    }


@pytest.mark.unit
def test_constant_string_node_output_schema_has_field_title_and_description():
    """Field titles and descriptions should appear in the output schema."""
    node = ConstantStringNode.from_value(id="test_node", value="test")
    value_prop = node.output_schema.model_dump()["properties"]["value"]
    assert value_prop["title"] == "Value"
    assert value_prop["description"] == "The constant string value."


@pytest.mark.unit
def test_constant_string_node_input_schema():
    node = ConstantStringNode.from_value(id="test_node", value="test")
    assert node.input_schema.model_dump() == {
        "additionalProperties": False,
        "description": "A Data and Params class that is explicitly not allowed to have any\nparameters.",
        "properties": {},
        "title": "Empty",
        "type": "object",
    }


@pytest.mark.unit
def test_constant_string_node_output_schema():
    node = ConstantStringNode.from_value(id="test_node", value="test")
    assert node.output_schema.model_dump() == {
        "$defs": {
            "StringValue": {
                "type": "string",
                "title": "StringValue",
            },
        },
        "additionalProperties": False,
        "properties": {
            "value": {
                "$ref": "#/$defs/StringValue",
                "title": "Value",
                "description": "The constant string value.",
            },
        },
        "required": ["value"],
        "title": "ConstantString",
        "type": "object",
    }
