diff --git a/api/tests/routers/test_search.py b/api/tests/routers/test_search.py index 7bc4a9d..c70fadb 100644 --- a/api/tests/routers/test_search.py +++ b/api/tests/routers/test_search.py @@ -91,6 +91,63 @@ def test_search_pagination(client: TestClient, mock_storage: MagicMock) -> None: assert data["meta"]["prev"] is not None # Should have prev page +def test_search_empty_parameters(client: TestClient, mock_storage: MagicMock) -> None: + # Mock data + timestamp = TwitterTimestamp.from_int(int(datetime(2023, 1, 1, tzinfo=timezone.utc).timestamp() * 1000)) + + note = Note( + note_id="1234567890123456789", + post_id="2234567890123456789", + language="ja", + topics=[Topic(topic_id=1, label={"ja": "ใƒ†ใ‚นใƒˆ", "en": "test"}, reference_count=1)], + summary="Test summary", + current_status="NEEDS_MORE_RATINGS", + created_at=timestamp, + ) + + post = Post( + post_id="2234567890123456789", + x_user_id="9876543210123456789", + x_user=XUser( + user_id="9876543210123456789", + name="test_user", + profile_image="http://example.com/image.jpg", + followers_count=100, + following_count=50, + ), + text="Test post", + media_details=[], + created_at=timestamp, + like_count=10, + repost_count=5, + impression_count=100, + links=[], + link="http://x.com/test_user/status/2234567890123456789", + ) + + # Mock storage response for empty parameters + mock_storage.search_notes_with_posts.return_value = [(note, post)] + mock_storage.count_search_results.return_value = 1 + + # Test search with no parameters + response = client.get("/api/v1/data/search") + assert response.status_code == 200 + + data = response.json() + assert "data" in data + assert "meta" in data + assert len(data["data"]) == 1 + + # Verify response structure + result = data["data"][0] + assert result["noteId"] == "1234567890123456789" + assert result["postId"] == "2234567890123456789" + assert result["language"] == "ja" + assert result["summary"] == "Test summary" + assert result["currentStatus"] == "NEEDS_MORE_RATINGS" + assert result["post"]["postId"] == "2234567890123456789" + + def test_search_parameters(client: TestClient, mock_storage: MagicMock) -> None: mock_storage.search_notes_with_posts.return_value = [] mock_storage.count_search_results.return_value = 0 diff --git a/common/birdxplorer_common/storage.py b/common/birdxplorer_common/storage.py index 7836005..9951e7a 100644 --- a/common/birdxplorer_common/storage.py +++ b/common/birdxplorer_common/storage.py @@ -623,8 +623,8 @@ def count_search_results( with Session(self.engine) as sess: query = ( sess.query(NoteRecord) - .join(PostRecord, NoteRecord.post_id == PostRecord.post_id) - .join(XUserRecord, PostRecord.user_id == XUserRecord.user_id) + .outerjoin(PostRecord, NoteRecord.post_id == PostRecord.post_id) + .outerjoin(XUserRecord, PostRecord.user_id == XUserRecord.user_id) ) # Apply note filters