mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-07 07:35:25 +00:00
add back test
This commit is contained in:
parent
6dd1fcd2bc
commit
ebcde207ac
1 changed files with 58 additions and 0 deletions
|
@ -46,3 +46,61 @@ impl AdminAllowInstance {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
source::{
|
||||
instance::Instance,
|
||||
person::{Person, PersonInsertForm},
|
||||
},
|
||||
traits::Crud,
|
||||
utils::build_db_pool_for_tests,
|
||||
};
|
||||
use pretty_assertions::assert_eq;
|
||||
use serial_test::serial;
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_allowlist_insert_and_clear() -> Result<(), Error> {
|
||||
let pool = &build_db_pool_for_tests();
|
||||
let pool = &mut pool.into();
|
||||
let instances = vec![
|
||||
Instance::read_or_create(pool, "tld1.xyz".to_string()).await?,
|
||||
Instance::read_or_create(pool, "tld2.xyz".to_string()).await?,
|
||||
Instance::read_or_create(pool, "tld3.xyz".to_string()).await?,
|
||||
];
|
||||
let new_person_3 = PersonInsertForm::test_form(instances[0].id, "xyz");
|
||||
let person = Person::create(pool, &new_person_3).await?;
|
||||
let forms: Vec<_> = instances
|
||||
.iter()
|
||||
.map(|i| AdminAllowInstanceForm {
|
||||
instance_id: i.id,
|
||||
admin_person_id: person.id,
|
||||
reason: None,
|
||||
})
|
||||
.collect();
|
||||
|
||||
for f in &forms {
|
||||
AdminAllowInstance::allow(pool, &f).await?;
|
||||
}
|
||||
|
||||
let allows = Instance::allowlist(pool).await?;
|
||||
|
||||
assert_eq!(3, allows.len());
|
||||
assert_eq!(instances, allows);
|
||||
|
||||
// Now test clearing them
|
||||
for f in forms {
|
||||
AdminAllowInstance::unallow(pool, f.instance_id).await?;
|
||||
}
|
||||
let allows = Instance::allowlist(pool).await?;
|
||||
assert_eq!(0, allows.len());
|
||||
|
||||
Instance::delete_all(pool).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue