from unittest.mock import patch

import pytest

from apps.core.notifications.models import Notification
from apps.core.notifications.services import send_notification


@pytest.mark.django_db
def test_send_notification_creates_row():
    from django.contrib.auth import get_user_model

    User = get_user_model()
    u = User.objects.create_user(email="n@example.com", password="x")
    with patch("apps.core.notifications.services.dispatch_notification_channel.delay"):
        n = send_notification(u, "Hello", channels=[])
    assert Notification.objects.filter(pk=n.pk).exists()
    assert n.message == "Hello"
