clean warnings and add tests
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
use mini_admin_bot::ban_stiker;
|
||||
|
||||
#[test]
|
||||
pub fn db_media_is_banned() {
|
||||
assert_eq!(0, 0);
|
||||
}
|
||||
1
tests/mocks/mod.rs
Normal file
1
tests/mocks/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod teloxide_mocks;
|
||||
54
tests/mocks/teloxide_mocks.rs
Normal file
54
tests/mocks/teloxide_mocks.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use chrono::DateTime;
|
||||
use teloxide::types::{
|
||||
Chat, ChatId, ChatKind, ChatPublic, MediaKind::Text, MediaText, Message, MessageCommon,
|
||||
MessageId, MessageKind::Common, PublicChatGroup, PublicChatKind::Group,
|
||||
};
|
||||
|
||||
pub fn generate_msg_mock(text: &str) -> Message {
|
||||
let chat_id = ChatId { 0: 0 };
|
||||
let public_chat_kind = Group(PublicChatGroup { permissions: None });
|
||||
let chat_kind = ChatKind::Public(ChatPublic {
|
||||
title: None,
|
||||
kind: public_chat_kind,
|
||||
description: None,
|
||||
invite_link: None,
|
||||
has_protected_content: None,
|
||||
});
|
||||
|
||||
let chat = Chat {
|
||||
has_aggressive_anti_spam_enabled: false,
|
||||
has_hidden_members: false,
|
||||
id: chat_id,
|
||||
pinned_message: None,
|
||||
photo: None,
|
||||
message_auto_delete_time: None,
|
||||
kind: chat_kind,
|
||||
};
|
||||
|
||||
let media_kind = Text(MediaText {
|
||||
text: text.to_string(),
|
||||
entities: Vec::new(),
|
||||
});
|
||||
|
||||
let message_kind = Common(MessageCommon {
|
||||
from: None,
|
||||
sender_chat: None,
|
||||
author_signature: None,
|
||||
forward: None,
|
||||
reply_to_message: None,
|
||||
edit_date: None,
|
||||
media_kind,
|
||||
reply_markup: None,
|
||||
is_topic_message: false,
|
||||
is_automatic_forward: false,
|
||||
has_protected_content: false,
|
||||
});
|
||||
Message {
|
||||
chat,
|
||||
via_bot: None,
|
||||
thread_id: None,
|
||||
kind: message_kind,
|
||||
date: DateTime::from_timestamp_nanos(0),
|
||||
id: MessageId { 0: 0 },
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
use mini_admin_bot::check_permissions;
|
||||
use mockall::{automock, mock, predicate::*};
|
||||
|
||||
#[test]
|
||||
fn test_permissions() {
|
||||
let mut mock = check_permissions::MockGroupPermissions::new();
|
||||
mock.expect_compare()
|
||||
.with("user_id")
|
||||
.times(1)
|
||||
.returning(true);
|
||||
assert_eq!(true, mock.compare("user_id"));
|
||||
}
|
||||
19
tests/test_links_to_rewrite.rs
Normal file
19
tests/test_links_to_rewrite.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use mini_admin_bot::rewrite_links;
|
||||
|
||||
mod mocks;
|
||||
#[test]
|
||||
pub fn test_contain_links() {
|
||||
assert_eq!(
|
||||
false,
|
||||
rewrite_links::check_contain_links::contain_links(
|
||||
mocks::teloxide_mocks::generate_msg_mock("hola")
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
true,
|
||||
rewrite_links::check_contain_links::contain_links(
|
||||
mocks::teloxide_mocks::generate_msg_mock("https://x.com")
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user