test: add TestContext.create_chat_id

This commit is contained in:
link2xt
2025-08-17 01:44:43 +00:00
committed by l
parent 66c9982822
commit 683561374d

View File

@@ -186,8 +186,8 @@ impl TestContextManager {
msg,
to.name()
));
let chat = from.create_chat(to).await;
let sent = from.send_text(chat.id, msg).await;
let chat_id = from.create_chat_id(to).await;
let sent = from.send_text(chat_id, msg).await;
to.recv_msg(&sent).await
}
@@ -852,14 +852,23 @@ impl TestContext {
Chat::load_from_db(&self.ctx, chat_id).await.unwrap()
}
/// Creates or returns an existing 1:1 [`ChatId`] with another account.
///
/// This first creates a contact by exporting a vCard from the `other`
/// and importing it into `self`,
/// then creates a 1:1 chat with this contact.
pub async fn create_chat_id(&self, other: &TestContext) -> ChatId {
let contact_id = self.add_or_lookup_contact_id(other).await;
ChatId::create_for_contact(self, contact_id).await.unwrap()
}
/// Creates or returns an existing 1:1 [`Chat`] with another account.
///
/// This first creates a contact by exporting a vCard from the `other`
/// and importing it into `self`,
/// then creates a 1:1 chat with this contact.
pub async fn create_chat(&self, other: &TestContext) -> Chat {
let contact_id = self.add_or_lookup_contact_id(other).await;
let chat_id = ChatId::create_for_contact(self, contact_id).await.unwrap();
let chat_id = self.create_chat_id(other).await;
Chat::load_from_db(self, chat_id).await.unwrap()
}