Some checks failed
ci/woodpecker/pr/check Pipeline was successful
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
- Add #[allow(unused_imports)] on pub re-exports used only by lib/tests - Add #[allow(dead_code)] on public API items unused in binary target - Fix collapsible_if, redundant_closure, unnecessary_map_or in main.rs - Prefix unused test variables with underscore Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
251 lines
6.7 KiB
Rust
251 lines
6.7 KiB
Rust
// Test data builders and fixtures
|
|
|
|
use tele_tui::tdlib::types::{ForwardInfo, ReactionInfo};
|
|
use tele_tui::tdlib::{ChatInfo, MessageInfo, ProfileInfo, ReplyInfo};
|
|
use tele_tui::types::{ChatId, MessageId};
|
|
|
|
/// Builder для создания тестового чата
|
|
#[allow(dead_code)]
|
|
pub struct TestChatBuilder {
|
|
id: i64,
|
|
title: String,
|
|
username: Option<String>,
|
|
last_message: String,
|
|
last_message_date: i32,
|
|
unread_count: i32,
|
|
unread_mention_count: i32,
|
|
is_pinned: bool,
|
|
order: i64,
|
|
last_read_outbox_message_id: i64,
|
|
folder_ids: Vec<i32>,
|
|
is_muted: bool,
|
|
draft_text: Option<String>,
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
impl TestChatBuilder {
|
|
pub fn new(title: &str, id: i64) -> Self {
|
|
Self {
|
|
id,
|
|
title: title.to_string(),
|
|
username: None,
|
|
last_message: "".to_string(),
|
|
last_message_date: 1640000000,
|
|
unread_count: 0,
|
|
unread_mention_count: 0,
|
|
is_pinned: false,
|
|
order: id,
|
|
last_read_outbox_message_id: 0,
|
|
folder_ids: vec![0],
|
|
is_muted: false,
|
|
draft_text: None,
|
|
}
|
|
}
|
|
|
|
pub fn username(mut self, username: &str) -> Self {
|
|
self.username = Some(username.to_string());
|
|
self
|
|
}
|
|
|
|
pub fn last_message(mut self, text: &str) -> Self {
|
|
self.last_message = text.to_string();
|
|
self
|
|
}
|
|
|
|
pub fn unread_count(mut self, count: i32) -> Self {
|
|
self.unread_count = count;
|
|
self
|
|
}
|
|
|
|
pub fn unread_mentions(mut self, count: i32) -> Self {
|
|
self.unread_mention_count = count;
|
|
self
|
|
}
|
|
|
|
pub fn pinned(mut self) -> Self {
|
|
self.is_pinned = true;
|
|
self
|
|
}
|
|
|
|
pub fn muted(mut self) -> Self {
|
|
self.is_muted = true;
|
|
self
|
|
}
|
|
|
|
pub fn draft(mut self, text: &str) -> Self {
|
|
self.draft_text = Some(text.to_string());
|
|
self
|
|
}
|
|
|
|
pub fn folder(mut self, folder_id: i32) -> Self {
|
|
self.folder_ids = vec![folder_id];
|
|
self
|
|
}
|
|
|
|
pub fn build(self) -> ChatInfo {
|
|
ChatInfo {
|
|
id: ChatId::new(self.id),
|
|
title: self.title,
|
|
username: self.username,
|
|
last_message: self.last_message,
|
|
last_message_date: self.last_message_date,
|
|
unread_count: self.unread_count,
|
|
unread_mention_count: self.unread_mention_count,
|
|
is_pinned: self.is_pinned,
|
|
order: self.order,
|
|
last_read_outbox_message_id: MessageId::new(self.last_read_outbox_message_id),
|
|
folder_ids: self.folder_ids,
|
|
is_muted: self.is_muted,
|
|
draft_text: self.draft_text,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Builder для создания тестового сообщения
|
|
#[allow(dead_code)]
|
|
pub struct TestMessageBuilder {
|
|
id: i64,
|
|
sender_name: String,
|
|
is_outgoing: bool,
|
|
content: String,
|
|
entities: Vec<tdlib_rs::types::TextEntity>,
|
|
date: i32,
|
|
edit_date: i32,
|
|
is_read: bool,
|
|
can_be_edited: bool,
|
|
can_be_deleted_only_for_self: bool,
|
|
can_be_deleted_for_all_users: bool,
|
|
reply_to: Option<ReplyInfo>,
|
|
forward_from: Option<ForwardInfo>,
|
|
reactions: Vec<ReactionInfo>,
|
|
media_album_id: i64,
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
impl TestMessageBuilder {
|
|
pub fn new(content: &str, id: i64) -> Self {
|
|
Self {
|
|
id,
|
|
sender_name: "User".to_string(),
|
|
is_outgoing: false,
|
|
content: content.to_string(),
|
|
entities: vec![],
|
|
date: 1640000000,
|
|
edit_date: 0,
|
|
is_read: true,
|
|
can_be_edited: false,
|
|
can_be_deleted_only_for_self: true,
|
|
can_be_deleted_for_all_users: false,
|
|
reply_to: None,
|
|
forward_from: None,
|
|
reactions: vec![],
|
|
media_album_id: 0,
|
|
}
|
|
}
|
|
|
|
pub fn outgoing(mut self) -> Self {
|
|
self.is_outgoing = true;
|
|
self.sender_name = "You".to_string();
|
|
self.can_be_edited = true;
|
|
self.can_be_deleted_for_all_users = true;
|
|
self
|
|
}
|
|
|
|
pub fn sender(mut self, name: &str) -> Self {
|
|
self.sender_name = name.to_string();
|
|
self
|
|
}
|
|
|
|
pub fn date(mut self, timestamp: i32) -> Self {
|
|
self.date = timestamp;
|
|
self
|
|
}
|
|
|
|
pub fn edited(mut self) -> Self {
|
|
self.edit_date = self.date + 60;
|
|
self
|
|
}
|
|
|
|
pub fn unread(mut self) -> Self {
|
|
self.is_read = false;
|
|
self
|
|
}
|
|
|
|
pub fn reply_to(mut self, message_id: i64, sender: &str, text: &str) -> Self {
|
|
self.reply_to = Some(ReplyInfo {
|
|
message_id: MessageId::new(message_id),
|
|
sender_name: sender.to_string(),
|
|
text: text.to_string(),
|
|
});
|
|
self
|
|
}
|
|
|
|
pub fn forwarded_from(mut self, sender: &str) -> Self {
|
|
self.forward_from = Some(ForwardInfo { sender_name: sender.to_string() });
|
|
self
|
|
}
|
|
|
|
pub fn reaction(mut self, emoji: &str, count: i32, chosen: bool) -> Self {
|
|
self.reactions
|
|
.push(ReactionInfo { emoji: emoji.to_string(), count, is_chosen: chosen });
|
|
self
|
|
}
|
|
|
|
pub fn media_album_id(mut self, id: i64) -> Self {
|
|
self.media_album_id = id;
|
|
self
|
|
}
|
|
|
|
pub fn build(self) -> MessageInfo {
|
|
let mut msg = MessageInfo::new(
|
|
MessageId::new(self.id),
|
|
self.sender_name,
|
|
self.is_outgoing,
|
|
self.content,
|
|
self.entities,
|
|
self.date,
|
|
self.edit_date,
|
|
self.is_read,
|
|
self.can_be_edited,
|
|
self.can_be_deleted_only_for_self,
|
|
self.can_be_deleted_for_all_users,
|
|
self.reply_to,
|
|
self.forward_from,
|
|
self.reactions,
|
|
);
|
|
msg.metadata.media_album_id = self.media_album_id;
|
|
msg
|
|
}
|
|
}
|
|
|
|
/// Хелперы для быстрого создания тестовых данных
|
|
|
|
pub fn create_test_chat(title: &str, id: i64) -> ChatInfo {
|
|
TestChatBuilder::new(title, id).build()
|
|
}
|
|
|
|
pub fn create_test_message(content: &str, id: i64) -> MessageInfo {
|
|
TestMessageBuilder::new(content, id).build()
|
|
}
|
|
|
|
pub fn create_test_user(name: &str, id: i64) -> (i64, String) {
|
|
(id, name.to_string())
|
|
}
|
|
|
|
/// Хелпер для создания профиля
|
|
pub fn create_test_profile(title: &str, chat_id: i64) -> ProfileInfo {
|
|
ProfileInfo {
|
|
chat_id: ChatId::new(chat_id),
|
|
title: title.to_string(),
|
|
username: None,
|
|
bio: None,
|
|
phone_number: None,
|
|
chat_type: "Личный чат".to_string(),
|
|
member_count: None,
|
|
description: None,
|
|
invite_link: None,
|
|
is_group: false,
|
|
online_status: None,
|
|
}
|
|
}
|