Test that all possible updates are specified in Kind::full_set()

This commit is contained in:
Andrey Brusnik 2024-08-15 17:04:19 +04:00
parent ae88d56e0d
commit ccdeb3f2b0
No known key found for this signature in database
GPG key ID: D33232F28CFF442C

View file

@ -95,10 +95,12 @@ mod tests {
#[cfg(feature = "macros")]
use crate::{
self as teloxide, // fixup for the `BotCommands` macro
dispatching::{HandlerExt, UpdateFilterExt},
dispatching::{handler_description::Kind, HandlerExt, UpdateFilterExt},
types::{AllowedUpdate::*, Update},
utils::command::BotCommands,
};
#[cfg(feature = "macros")]
use dptree::description::EventKind;
#[cfg(feature = "macros")]
#[derive(BotCommands, Clone)]
@ -132,4 +134,43 @@ mod tests {
fn discussion_648() {
panic!("this test requires `macros` feature")
}
// Test that all possible updates are specified in `Kind::full_set()`
#[test]
#[cfg(feature = "macros")]
fn allowed_updates_full_set() {
let full_set = Kind::full_set();
let allowed_updates_reference = vec![
Message,
EditedMessage,
ChannelPost,
EditedChannelPost,
MessageReaction,
MessageReactionCount,
InlineQuery,
ChosenInlineResult,
CallbackQuery,
ShippingQuery,
PreCheckoutQuery,
Poll,
PollAnswer,
MyChatMember,
ChatMember,
ChatJoinRequest,
ChatBoost,
RemovedChatBoost,
];
for update in allowed_updates_reference {
match update {
// CAUTION: Don't forget to add new `UpdateKind` to `allowed_updates_reference`!
Message | EditedMessage | ChannelPost | EditedChannelPost | MessageReaction
| MessageReactionCount | InlineQuery | ChosenInlineResult | CallbackQuery
| ShippingQuery | PreCheckoutQuery | Poll | PollAnswer | MyChatMember
| ChatMember | ChatJoinRequest | ChatBoost | RemovedChatBoost => {
assert!(full_set.contains(&Kind(update)))
}
}
}
}
}