feat(domain): SearchPort trait with thought and user search

This commit is contained in:
2026-05-14 09:23:22 +02:00
parent 6e5d0de636
commit a3534317de
2 changed files with 47 additions and 0 deletions

View File

@@ -282,6 +282,15 @@ pub struct TestStore {
}
}
#[async_trait] impl SearchPort for TestStore {
async fn search_thoughts(&self, _q: &str, _p: &PageParams, _v: Option<&UserId>) -> Result<Paginated<FeedEntry>, DomainError> {
Ok(Paginated { items: vec![], total: 0, page: 1, per_page: 20 })
}
async fn search_users(&self, _q: &str, _p: &PageParams) -> Result<Paginated<User>, DomainError> {
Ok(Paginated { items: vec![], total: 0, page: 1, per_page: 20 })
}
}
#[async_trait] impl EventPublisher for TestStore {
async fn publish(&self, event: &DomainEvent) -> Result<(), DomainError> {
self.events.lock().unwrap().push(event.clone());
@@ -293,3 +302,23 @@ pub struct NoOpEventPublisher;
#[async_trait] impl EventPublisher for NoOpEventPublisher {
async fn publish(&self, _e: &DomainEvent) -> Result<(), DomainError> { Ok(()) }
}
#[cfg(test)]
mod search_tests {
use super::*;
use crate::models::feed::PageParams;
#[tokio::test]
async fn test_store_search_thoughts_returns_empty() {
let store = TestStore::default();
let result = store.search_thoughts("hello", &PageParams { page: 1, per_page: 20 }, None).await.unwrap();
assert_eq!(result.total, 0);
}
#[tokio::test]
async fn test_store_search_users_returns_empty() {
let store = TestStore::default();
let result = store.search_users("alice", &PageParams { page: 1, per_page: 20 }).await.unwrap();
assert_eq!(result.total, 0);
}
}