1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! "Not a member here" is not a failure (#839).
//!
//! Global `allowed_users` are admins allowed in every group. Clearing their
//! per-member menu in a group they do not belong to comes back as an invalid-id
//! error, which was logged as a warning: four errors per group across nine
//! groups on every registration pass, burying real failures.
//!
//! The first proposed fix was to stop consulting the global list. That would
//! have regressed the admins who ARE members, leaving them the default menu
//! offering /start. These pin the classification instead.
//!
//! Fixtures are synthetic and carry no user identifiers.
use crate::channels::telegram::menu_scope::means_not_a_member;
#[test]
fn the_observed_error_is_recognised() {
assert!(means_not_a_member("USER_ID_INVALID"));
}
#[test]
fn the_error_is_recognised_inside_a_wrapped_message() {
// teloxide renders these as opaque API strings, so the code arrives
// embedded in surrounding text rather than as a typed variant.
assert!(means_not_a_member(
"Telegram API error: Bad Request: USER_ID_INVALID"
));
}
#[test]
fn the_other_non_membership_codes_are_recognised() {
for code in ["PARTICIPANT_ID_INVALID", "USER_NOT_PARTICIPANT"] {
assert!(means_not_a_member(code), "must recognise: {code}");
}
}
#[test]
fn matching_is_case_insensitive() {
assert!(means_not_a_member("bad request: user_id_invalid"));
}
#[test]
fn real_failures_still_warn() {
// The point of the change is that genuine faults stay visible. If any of
// these were swallowed the log would go quiet on problems worth seeing.
for err in [
"CHAT_NOT_FOUND",
"BOT_WAS_KICKED",
"Retry after 30",
"connection closed before message completed",
"TOO_MANY_REQUESTS",
"CHAT_ADMIN_REQUIRED",
] {
assert!(!means_not_a_member(err), "must stay a warning: {err}");
}
}
#[test]
fn an_empty_error_is_not_a_membership_answer() {
assert!(!means_not_a_member(""));
}