from app.platforms.xiaohongshu import XiaohongshuPlatform def test_xiaohongshu_maps_hotspots_from_items_not_outer_title(): platform = XiaohongshuPlatform(client=None) payload = { "data": { "data": { "title": "搜索发现", "items": [ {"id": "hot-1", "title": "真实热点", "score": "999", "rank_change": 1} ], } } } hotspots = platform.map_hotspots(payload, limit=5) assert hotspots[0].source_hot_id == "hot-1" assert hotspots[0].title == "真实热点" assert hotspots[0].heat_value == "999" def test_xiaohongshu_prefers_notes_with_comments_and_falls_back_to_zero_comment_notes(): platform = XiaohongshuPlatform(client=None) payload = { "data": { "data": { "items": [ {"note": {"id": "n0", "title": "无评论", "desc": "", "comments_count": 0}}, {"note": {"id": "n1", "title": "有评论1", "desc": "d1", "comments_count": 3}}, {"note": {"id": "n2", "title": "有评论2", "desc": "d2", "comments_count": 1}}, ] } } } items = platform.map_items(payload, limit=3) assert [item.source_item_id for item in items] == ["n1", "n2", "n0"] assert all(item.item_type == "note" for item in items) def test_xiaohongshu_maps_comment_id_content_and_missing_optional_fields(): platform = XiaohongshuPlatform(client=None) payload = { "data": { "data": { "comments": [ {"comment_id": "preferred", "id": "fallback", "content": "正文"}, {"id": "fallback-only", "text": "文本字段", "like_count": 7}, ] } } } comments = platform.map_comments(payload, limit=10) assert comments[0].source_comment_id == "preferred" assert comments[0].content == "正文" assert comments[0].like_count is None assert comments[0].comment_time is None assert comments[1].source_comment_id == "fallback-only" assert comments[1].content == "文本字段" assert comments[1].like_count == 7