from unittest.mock import MagicMock

import pytest

from app.core.exceptions import ValidationError
from app.services.whatsapp_service import WhatsAppService


def test_ensure_can_message_blocks_opt_out():
    policy = MagicMock()
    policy.customer = MagicMock()
    policy.customer.whatsapp_opt_out = True

    with pytest.raises(ValidationError, match="opted out"):
        WhatsAppService._ensure_can_message(policy)


def test_ensure_can_message_allows_opted_in():
    policy = MagicMock()
    policy.customer = MagicMock()
    policy.customer.whatsapp_opt_out = False

    WhatsAppService._ensure_can_message(policy)
