mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 10:26:29 +03:00
add a test to check LIMIT on global searches
This commit is contained in:
@@ -911,11 +911,11 @@ mod tests {
|
|||||||
// Add messages to chat with Bob.
|
// Add messages to chat with Bob.
|
||||||
let mut msg1 = Message::new(Viewtype::Text);
|
let mut msg1 = Message::new(Viewtype::Text);
|
||||||
msg1.set_text(Some("foobar".to_string()));
|
msg1.set_text(Some("foobar".to_string()));
|
||||||
send_msg(&alice, chat.id, &mut msg1).await.unwrap();
|
send_msg(&alice, chat.id, &mut msg1).await?;
|
||||||
|
|
||||||
let mut msg2 = Message::new(Viewtype::Text);
|
let mut msg2 = Message::new(Viewtype::Text);
|
||||||
msg2.set_text(Some("barbaz".to_string()));
|
msg2.set_text(Some("barbaz".to_string()));
|
||||||
send_msg(&alice, chat.id, &mut msg2).await.unwrap();
|
send_msg(&alice, chat.id, &mut msg2).await?;
|
||||||
|
|
||||||
// Global search with a part of text finds the message.
|
// Global search with a part of text finds the message.
|
||||||
let res = alice.search_msgs(None, "ob").await?;
|
let res = alice.search_msgs(None, "ob").await?;
|
||||||
@@ -947,4 +947,37 @@ mod tests {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_limit_search_msgs() -> Result<()> {
|
||||||
|
let alice = TestContext::new_alice().await;
|
||||||
|
let chat = alice
|
||||||
|
.create_chat_with_contact("Bob", "bob@example.org")
|
||||||
|
.await;
|
||||||
|
|
||||||
|
// Add 999 messages
|
||||||
|
let mut msg = Message::new(Viewtype::Text);
|
||||||
|
msg.set_text(Some("foobar".to_string()));
|
||||||
|
for _ in 0..999 {
|
||||||
|
send_msg(&alice, chat.id, &mut msg).await?;
|
||||||
|
}
|
||||||
|
let res = alice.search_msgs(None, "foo").await?;
|
||||||
|
assert_eq!(res.len(), 999);
|
||||||
|
|
||||||
|
// Add one more message, no limit yet
|
||||||
|
send_msg(&alice, chat.id, &mut msg).await?;
|
||||||
|
let res = alice.search_msgs(None, "foo").await?;
|
||||||
|
assert_eq!(res.len(), 1000);
|
||||||
|
|
||||||
|
// Add one more message, that one is truncated then
|
||||||
|
send_msg(&alice, chat.id, &mut msg).await?;
|
||||||
|
let res = alice.search_msgs(None, "foo").await?;
|
||||||
|
assert_eq!(res.len(), 1000);
|
||||||
|
|
||||||
|
// In-chat should not be not limited
|
||||||
|
let res = alice.search_msgs(Some(chat.id), "foo").await?;
|
||||||
|
assert_eq!(res.len(), 1001);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user