use crate::cron::send_scope::{SendPermission, may_send_to, permission, with_send_target};
const CONFIGURED: i64 = -1004252074515;
const SOMEWHERE_ELSE: i64 = -1004428873948;
#[tokio::test]
async fn outside_a_job_nothing_is_restricted() {
assert_eq!(permission(), SendPermission::Unscoped);
assert!(may_send_to(SOMEWHERE_ELSE));
}
#[tokio::test]
async fn a_job_may_send_to_the_chat_it_was_given() {
with_send_target(Some(CONFIGURED), async {
assert_eq!(permission(), SendPermission::OnlyChat(CONFIGURED));
assert!(may_send_to(CONFIGURED));
})
.await;
}
#[tokio::test]
async fn a_job_may_not_send_to_any_other_chat() {
with_send_target(Some(CONFIGURED), async {
assert!(
!may_send_to(SOMEWHERE_ELSE),
"a chat id found in memory is not permission to post there"
);
})
.await;
}
#[tokio::test]
async fn a_job_without_a_target_sends_nowhere() {
with_send_target(None, async {
assert_eq!(permission(), SendPermission::Nowhere);
assert!(!may_send_to(CONFIGURED));
assert!(!may_send_to(SOMEWHERE_ELSE));
})
.await;
}
#[tokio::test]
async fn the_scope_does_not_outlive_the_job() {
with_send_target(Some(CONFIGURED), async {
assert!(!may_send_to(SOMEWHERE_ELSE));
})
.await;
assert_eq!(permission(), SendPermission::Unscoped);
assert!(may_send_to(SOMEWHERE_ELSE));
}
#[tokio::test]
async fn the_refusal_names_what_to_change() {
with_send_target(Some(CONFIGURED), async {
let msg = crate::cron::send_scope::refusal(SOMEWHERE_ELSE);
assert!(msg.contains("deliver_to"), "got: {msg}");
assert!(msg.contains(&CONFIGURED.to_string()), "got: {msg}");
})
.await;
}