unit tests
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful

This commit is contained in:
ModulatingForce 2024-03-25 21:26:32 -04:00
parent e66985814a
commit feff709714
2 changed files with 221 additions and 3 deletions

View file

@ -37,6 +37,15 @@ pub enum ChangeResult {
pub struct Channel(pub String); pub struct Channel(pub String);
// impl PartialEq for Channel {
// fn eq(&self, other: &Self) -> bool {
// let Channel(name1) = self.clone();
// let Channel(name2) = other.clone();
// name1.to_lowercase() == name2.to_lowercase()
// }
// }
// impl Eq for Channel {}
use super::bot_actions::ExecBodyParams; use super::bot_actions::ExecBodyParams;
use super::botmodules::StatusType; use super::botmodules::StatusType;

View file

@ -2017,7 +2017,7 @@ impl IdentityManager {
) )
&& trg_role == Some(UserRole::VIP(channel.clone())) { && trg_role == Some(UserRole::VIP(channel.clone())) {
if !trgusrroles.contains(&UserRole::VIP(channel.clone())) { if !trgusrroles.contains(&UserRole::VIP(channel.clone())) {
return ChangeResult::NoChange("Already does not haev VIP role".to_string()); return ChangeResult::NoChange("Already does not have VIP role".to_string());
} }
else { else {
// self.affirm_chatter_in_db(trgchatter.clone()).await; // self.affirm_chatter_in_db(trgchatter.clone()).await;
@ -2108,7 +2108,8 @@ impl IdentityManager {
Some(chnl) => { Some(chnl) => {
// In this block, Some input channel is given // In this block, Some input channel is given
// We're comparing the channel name with chattername to determine if they're a broadcaster // We're comparing the channel name with chattername to determine if they're a broadcaster
if chattername == chnl.0 // if chattername == chnl.0
if chattername == chnl.0.to_lowercase()
{ {
evalsproles.push(UserRole::Broadcaster); evalsproles.push(UserRole::Broadcaster);
} }
@ -2193,7 +2194,7 @@ impl IdentityManager {
#[cfg(test)] #[cfg(test)]
mod core_identity { mod core_identity {
use casual_logger::Extension; use casual_logger::{Extension, Level};
use super::*; use super::*;
@ -2630,4 +2631,212 @@ mod core_identity {
) )
); );
} }
#[tokio::test]
async fn vip_workflow_01() {
Log::set_file_ext(Extension::Log);
//Log::set_level(Level::Trace);
// Channel Elevated User Promotes/Demotes VIP
let test_id_mgr = IdentityManager::init();
// [x] 1. Requester has a Mod Role
let channel = Some(Channel("somechannel".to_string()));
let authorizer_badge = &Some(ChatBadge::Mod);
let authorizer = "chatMod".to_string();
let trgchatter = "regularChatter".to_string();
let trg_role = Some(UserRole::VIP(channel.clone().unwrap()));
let authorizer = authorizer.to_lowercase();
let trgchatter = trgchatter.to_lowercase();
test_id_mgr.affirm_chatter_in_db(authorizer.clone()).await;
test_id_mgr.affirm_chatter_in_db(trgchatter.clone()).await;
test_id_mgr
.add_role(authorizer.clone(), UserRole::Mod(channel.clone().unwrap()))
.await;
let rslt = test_id_mgr
.getspecialuserroles(authorizer.clone(), channel.clone())
.await;
assert_eq!(rslt,vec![UserRole::Mod(channel.clone().unwrap())]);
// [x] 2. assert getspecialuserroles for Target Chatter
let rslt = test_id_mgr
.getspecialuserroles(trgchatter.clone(), channel.clone())
.await;
assert_eq!(rslt,vec![]);
// [x] 3. Requester Promotes a Target Chatter to VIP
let rslt = test_id_mgr
.promote(
authorizer.clone(),
authorizer_badge,
trgchatter.clone(),
channel.clone(),
trg_role.clone(),
)
.await;
assert_eq!(
rslt,
ChangeResult::Success("Promotion Successful".to_string())
);
// [x] 4. assert getspecialuserroles for Target Chatter
let rslt = test_id_mgr
.getspecialuserroles(trgchatter.clone(), channel.clone())
.await;
assert!(rslt.contains(&UserRole::VIP(channel.clone().unwrap())));
// [x] 5. Requester Promotes a Target Chatter to VIP
let rslt = test_id_mgr
.promote(
authorizer.clone(),
authorizer_badge,
trgchatter.clone(),
channel.clone(),
trg_role.clone(),
)
.await;
assert_eq!(
rslt,
ChangeResult::NoChange("Already has the role".to_string())
);
// [x] 6. assert getspecialuserroles for Target Chatter
let rslt = test_id_mgr
.getspecialuserroles(trgchatter.clone(), channel.clone())
.await;
assert!(rslt.contains(&UserRole::VIP(channel.clone().unwrap())));
// [x] 7. Requester Demotes a Target Chatter from VIP
let rslt = test_id_mgr
.demote(
authorizer.clone(),
authorizer_badge,
trgchatter.clone(),
channel.clone(),
trg_role.clone(),
)
.await;
assert_eq!(
rslt,
ChangeResult::Success("Demotion Successful".to_string())
);
// [x] 8. assert getspecialuserroles for Target Chatter
let rslt = test_id_mgr
.getspecialuserroles(trgchatter.clone(), channel.clone())
.await;
// assert!(rslt.contains(&UserRole::VIP(channel.clone().unwrap())));
assert_eq!(rslt,vec![]);
// [x] 9. Requester Demotes a Target Chatter from VIP
let rslt = test_id_mgr
.demote(
authorizer.clone(),
authorizer_badge,
trgchatter.clone(),
channel.clone(),
trg_role.clone(),
)
.await;
assert_eq!(
rslt,
ChangeResult::NoChange("Already does not have VIP role".to_string())
);
// [x] 10. assert getspecialuserroles for Target Chatter
let rslt = test_id_mgr
.getspecialuserroles(trgchatter.clone(), channel.clone())
.await;
assert_eq!(rslt,vec![]);
}
#[tokio::test]
async fn auto_vip_workflow() {
Log::set_file_ext(Extension::Log);
let mut test_id_mgr = IdentityManager::init();
let channel = Some(Channel("somechannel".to_string()));
let authorizer_badge = Some(ChatBadge::VIP);
let authorizer = "chatMod".to_string();
let authorizer = authorizer.to_lowercase();
// [x] 1. assert getspecialuserroles for Target Chatter
let rslt = test_id_mgr
.getspecialuserroles(authorizer.clone(), channel.clone())
.await;
assert_eq!(rslt,vec![]);
// [x] 2. Run canuserrun() for the Requester . (This is ran after BotCommands are ran)
let rslt = test_id_mgr
.can_user_run(
authorizer.clone(),
channel.clone().unwrap(),
authorizer_badge,
vec![
UserRole::VIP(OF_CMD_CHANNEL),
]
).await;
assert_eq!(rslt,
(Permissible::Allow,ChangeResult::Success("Auto Promoted VIP".to_string())));
// [x] 3. assert getspecialuserroles for Target Chatter
let rslt = test_id_mgr
.getspecialuserroles(authorizer.clone(), channel.clone())
.await;
assert_eq!(rslt,vec![UserRole::VIP(channel.unwrap())]);
}
} }