"""Tests for Store Value node."""

import pytest

from fw_nodes_core.nodes.store_value import StoreValueNode, StoreValueOutput


@pytest.mark.asyncio
async def test_store_value(mock_context):
    """Test storing a simple string value."""
    node = StoreValueNode()
    result = await node.execute({"key": "my_key", "value": "hello"}, mock_context)

    assert isinstance(result, StoreValueOutput)
    assert result.key == "my_key"
    assert result.value == "hello"
    assert mock_context._data_store["my_key"] == "hello"


@pytest.mark.asyncio
async def test_store_value_overwrites(mock_context):
    """Test that storing with the same key overwrites the previous value."""
    node = StoreValueNode()

    await node.execute({"key": "counter", "value": "1"}, mock_context)
    assert mock_context._data_store["counter"] == "1"

    result = await node.execute({"key": "counter", "value": "2"}, mock_context)
    assert result.value == "2"
    assert mock_context._data_store["counter"] == "2"


@pytest.mark.asyncio
async def test_store_value_numeric_string(mock_context):
    """Test storing a numeric value as string."""
    node = StoreValueNode()
    result = await node.execute({"key": "count", "value": "42"}, mock_context)

    assert result.value == "42"
    assert mock_context._data_store["count"] == "42"
