use std::time::Duration;
use crate::channels::telegram::TelegramState;
#[test]
fn newest_msg_id_starts_empty() {
let state = TelegramState::new();
assert_eq!(state.newest_incoming_msg_id(100), None);
}
#[test]
fn newest_msg_id_keeps_the_per_chat_maximum() {
let state = TelegramState::new();
state.note_incoming_msg(100, 10);
state.note_incoming_msg(100, 25);
state.note_incoming_msg(100, 25);
assert_eq!(state.newest_incoming_msg_id(100), Some(25));
state.note_incoming_msg(100, 12);
assert_eq!(state.newest_incoming_msg_id(100), Some(25));
}
#[test]
fn newest_msg_id_is_isolated_per_chat() {
let state = TelegramState::new();
state.note_incoming_msg(100, 50);
state.note_incoming_msg(200, 7);
assert_eq!(state.newest_incoming_msg_id(100), Some(50));
assert_eq!(state.newest_incoming_msg_id(200), Some(7));
assert_eq!(state.newest_incoming_msg_id(300), None);
}
#[test]
fn block_is_buried_only_when_a_newer_message_landed() {
let state = TelegramState::new();
let block_mid = 40;
state.note_incoming_msg(100, 40);
assert!(state.newest_incoming_msg_id(100).unwrap() <= block_mid);
state.note_incoming_msg(100, 41);
assert!(state.newest_incoming_msg_id(100).unwrap() > block_mid);
}
#[test]
fn bot_bubbles_count_as_burial_evidence() {
let state = TelegramState::new();
state.note_incoming_msg(100, 40); assert!(state.newest_incoming_msg_id(100).unwrap() <= 40);
state.note_bot_bubble(100, 55);
assert_eq!(state.newest_incoming_msg_id(100), Some(55));
}
#[test]
fn budget_admits_one_action_then_gates_within_the_interval() {
let state = TelegramState::new();
assert!(
state.claim_sticky_action(100, Duration::from_secs(15)),
"first action is always admitted"
);
assert!(
!state.claim_sticky_action(100, Duration::from_secs(15)),
"a second delete+create inside the window must be denied (#814)"
);
assert!(state.claim_sticky_action(200, Duration::from_secs(15)));
}
#[test]
fn zero_interval_budget_is_always_admissible() {
let state = TelegramState::new();
assert!(state.claim_sticky_action(100, Duration::ZERO));
assert!(state.claim_sticky_action(100, Duration::ZERO));
}