use crate::channels::telegram::rich::api::{build_body, build_body_html};
use crate::channels::telegram::rich::detect::{contains_task_list, has_rich_structure};
use teloxide::types::{MessageId, ThreadId};
#[test]
fn task_list_asterisk_prefix_detected() {
assert!(contains_task_list("* [ ] star task\n* [x] done"));
}
#[test]
fn task_list_plus_prefix_detected() {
assert!(contains_task_list("+ [ ] plus task"));
}
#[test]
fn task_list_mixed_prefixes() {
assert!(contains_task_list("- [ ] dash\n* [x] star\n+ [ ] plus"));
}
#[test]
fn task_list_indented_detected() {
assert!(contains_task_list(" - [ ] indented"));
}
#[test]
fn rich_structure_ordered_list_detected() {
assert!(has_rich_structure("1. first\n2. second\n3. third"));
}
#[test]
fn rich_structure_empty_text_false() {
assert!(!has_rich_structure(""));
}
#[test]
fn rich_structure_whitespace_only_false() {
assert!(!has_rich_structure(" \n \n "));
}
#[test]
fn rich_request_body_with_thread_id() {
let body = build_body(
99,
Some(ThreadId(MessageId(42))),
"| A |\n| - |\n| 1 |",
None,
);
assert_eq!(body["chat_id"], 99);
assert_eq!(body["message_thread_id"], 42);
assert_eq!(body["rich_message"]["markdown"], "| A |\n| - |\n| 1 |");
}
#[test]
fn rich_request_body_without_thread_id() {
let body = build_body(100, None, "hello", None);
assert_eq!(body["chat_id"], 100);
assert!(body.get("message_thread_id").is_none());
assert_eq!(body["rich_message"]["markdown"], "hello");
}
#[test]
fn rich_html_body_uses_html_key() {
let body = build_body_html(100, None, "<details><summary>x</summary>y</details>");
assert_eq!(body["chat_id"], 100);
assert!(body.get("message_thread_id").is_none());
assert!(body["rich_message"].get("markdown").is_none());
assert_eq!(
body["rich_message"]["html"],
"<details><summary>x</summary>y</details>"
);
}
#[test]
fn rich_html_body_with_thread_id() {
let body = build_body_html(99, Some(ThreadId(MessageId(42))), "<b>hi</b>");
assert_eq!(body["message_thread_id"], 42);
assert_eq!(body["rich_message"]["html"], "<b>hi</b>");
}