|
| 1 | +use fs_bots::{ |
| 2 | + bot_strategy::BotAction, |
| 3 | + model::{ApprovalAction, BotKind, ChannelTarget, MessagingBot, Platform}, |
| 4 | +}; |
| 5 | + |
| 6 | +fn make_bot(kind: BotKind) -> MessagingBot { |
| 7 | + MessagingBot { |
| 8 | + id: "test".into(), |
| 9 | + name: "Test Bot".into(), |
| 10 | + kind, |
| 11 | + enabled: true, |
| 12 | + targets: vec![], |
| 13 | + recent_broadcasts: vec![], |
| 14 | + pending_approvals: vec![], |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +fn enabled_target() -> ChannelTarget { |
| 19 | + ChannelTarget { |
| 20 | + platform: "telegram".into(), |
| 21 | + name: "@test".into(), |
| 22 | + id: "t1".into(), |
| 23 | + enabled: true, |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +#[test] |
| 28 | +fn bot_kind_label_broadcast() { |
| 29 | + assert_eq!(BotKind::Broadcast.label(), "Broadcast"); |
| 30 | +} |
| 31 | + |
| 32 | +#[test] |
| 33 | +fn bot_kind_label_gatekeeper() { |
| 34 | + assert_eq!(BotKind::Gatekeeper.label(), "Gatekeeper"); |
| 35 | +} |
| 36 | + |
| 37 | +#[test] |
| 38 | +fn bot_kind_label_monitor() { |
| 39 | + assert_eq!(BotKind::Monitor.label(), "Monitor"); |
| 40 | +} |
| 41 | + |
| 42 | +#[test] |
| 43 | +fn platform_all_has_seven_entries() { |
| 44 | + assert_eq!(Platform::all().len(), 7); |
| 45 | +} |
| 46 | + |
| 47 | +#[test] |
| 48 | +fn platform_telegram_label() { |
| 49 | + assert_eq!(Platform::Telegram.label(), "Telegram"); |
| 50 | +} |
| 51 | + |
| 52 | +#[test] |
| 53 | +fn platform_matrix_label() { |
| 54 | + assert_eq!(Platform::Matrix.label(), "Matrix"); |
| 55 | +} |
| 56 | + |
| 57 | +#[test] |
| 58 | +fn platform_credential_fields_telegram_nonempty() { |
| 59 | + assert!(!Platform::Telegram.credential_fields().is_empty()); |
| 60 | +} |
| 61 | + |
| 62 | +#[test] |
| 63 | +fn broadcast_strategy_rejects_resolve_approval() { |
| 64 | + let mut bot = make_bot(BotKind::Broadcast); |
| 65 | + let strategy = BotKind::Broadcast.strategy(); |
| 66 | + let result = strategy.apply( |
| 67 | + &mut bot, |
| 68 | + BotAction::ResolveApproval { |
| 69 | + id: "x".into(), |
| 70 | + action: ApprovalAction::Allow, |
| 71 | + }, |
| 72 | + ); |
| 73 | + assert!(result.is_err()); |
| 74 | +} |
| 75 | + |
| 76 | +#[test] |
| 77 | +fn gatekeeper_strategy_rejects_send_broadcast() { |
| 78 | + let mut bot = make_bot(BotKind::Gatekeeper); |
| 79 | + bot.targets.push(enabled_target()); |
| 80 | + let strategy = BotKind::Gatekeeper.strategy(); |
| 81 | + let result = strategy.apply( |
| 82 | + &mut bot, |
| 83 | + BotAction::SendBroadcast { |
| 84 | + message: "hello".into(), |
| 85 | + target_count: 1, |
| 86 | + }, |
| 87 | + ); |
| 88 | + assert!(result.is_err()); |
| 89 | +} |
0 commit comments