summaryrefslogtreecommitdiff
path: root/services/news-collector/tests/test_truth_social.py
blob: 52f1e4615a9c74ece6a073b6fbd2abc32a8bc46f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Tests for Truth Social collector."""

from unittest.mock import AsyncMock, patch

import pytest
from news_collector.collectors.truth_social import TruthSocialCollector


@pytest.fixture
def collector():
    return TruthSocialCollector()


def test_collector_name(collector):
    assert collector.name == "truth_social"
    assert collector.poll_interval == 900


async def test_is_available(collector):
    assert await collector.is_available() is True


async def test_collect_parses_posts(collector):
    mock_posts = [
        {
            "content": "<p>We are imposing 25% tariffs on all steel imports!</p>",
            "created_at": "2026-04-02T12:00:00.000Z",
            "url": "https://truthsocial.com/@realDonaldTrump/12345",
            "id": "12345",
        },
    ]
    with patch.object(collector, "_fetch_posts", new_callable=AsyncMock, return_value=mock_posts):
        items = await collector.collect()
    assert len(items) == 1
    assert items[0].source == "truth_social"
    assert items[0].category.value == "policy"


async def test_collect_handles_empty(collector):
    with patch.object(collector, "_fetch_posts", new_callable=AsyncMock, return_value=[]):
        items = await collector.collect()
    assert items == []