Files
SigHej/backend/tests/test_match.py
Henrik Jess Nielsen 99e9b509a0
Some checks failed
Backend CI / test (push) Has been cancelled
Flutter CI / analyze-and-test (push) Has been cancelled
eksplicit mapping af envs
2026-05-12 18:21:25 +02:00

62 lines
1.9 KiB
Python

from unittest.mock import AsyncMock, patch
import pytest
from app.services.match_service import attempt_match, _format_interests
@pytest.mark.asyncio
async def test_no_match_when_sessions_missing() -> None:
with patch("app.services.match_service.get_session", return_value=None):
result = await attempt_match("token_a", "token_b")
assert result["match"] is False
assert result["nudge_sent"] is False
@pytest.mark.asyncio
async def test_no_match_when_no_shared_interests() -> None:
sessions = {
"token_a": {"interests": ["devops"]},
"token_b": {"interests": ["cooking"]},
}
async def fake_get(token: str) -> dict:
return sessions.get(token)
with patch("app.services.match_service.get_session", side_effect=fake_get):
with patch("app.services.match_service.manager") as mock_mgr:
result = await attempt_match("token_a", "token_b")
assert result["match"] is False
mock_mgr.send.assert_not_called()
@pytest.mark.asyncio
async def test_match_with_shared_interests() -> None:
sessions = {
"token_a": {"interests": ["devops", "hardstyle"]},
"token_b": {"interests": ["hardstyle", "philosophy"]},
}
async def fake_get(token: str) -> dict:
return sessions.get(token)
with patch("app.services.match_service.get_session", side_effect=fake_get):
with patch("app.services.match_service.manager") as mock_mgr:
mock_mgr.send = AsyncMock()
result = await attempt_match("token_a", "token_b")
assert result["match"] is True
assert "hardstyle" in result["shared_interests"]
assert result["nudge_sent"] is True
assert mock_mgr.send.call_count == 2
def test_format_interests_single() -> None:
assert _format_interests(["devops"]) == "devops"
def test_format_interests_multiple() -> None:
result = _format_interests(["devops", "hardstyle"])
assert result == "devops and hardstyle"