|
|
@ -179,6 +179,7 @@ mod tests {
|
|
|
|
traits::Crud,
|
|
|
|
traits::Crud,
|
|
|
|
utils::build_db_pool_for_tests,
|
|
|
|
utils::build_db_pool_for_tests,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
use lemmy_utils::error::LemmyResult;
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use pretty_assertions::assert_eq;
|
|
|
|
use serial_test::serial;
|
|
|
|
use serial_test::serial;
|
|
|
|
|
|
|
|
|
|
|
@ -189,64 +190,59 @@ mod tests {
|
|
|
|
bob_local_user: LocalUser,
|
|
|
|
bob_local_user: LocalUser,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn init_data(pool: &mut DbPool<'_>) -> Data {
|
|
|
|
async fn init_data(pool: &mut DbPool<'_>) -> LemmyResult<Data> {
|
|
|
|
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
|
|
|
|
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
|
|
|
|
.await
|
|
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let alice_form = PersonInsertForm::builder()
|
|
|
|
let alice_form = PersonInsertForm::builder()
|
|
|
|
.name("alice".to_string())
|
|
|
|
.name("alice".to_string())
|
|
|
|
.public_key("pubkey".to_string())
|
|
|
|
.public_key("pubkey".to_string())
|
|
|
|
.instance_id(inserted_instance.id)
|
|
|
|
.instance_id(inserted_instance.id)
|
|
|
|
|
|
|
|
.local(Some(true))
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
let alice = Person::create(pool, &alice_form).await.unwrap();
|
|
|
|
let alice = Person::create(pool, &alice_form).await?;
|
|
|
|
let alice_local_user_form = LocalUserInsertForm::builder()
|
|
|
|
let alice_local_user_form = LocalUserInsertForm::builder()
|
|
|
|
.person_id(alice.id)
|
|
|
|
.person_id(alice.id)
|
|
|
|
.password_encrypted(String::new())
|
|
|
|
.password_encrypted(String::new())
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
let alice_local_user = LocalUser::create(pool, &alice_local_user_form)
|
|
|
|
let alice_local_user = LocalUser::create(pool, &alice_local_user_form).await?;
|
|
|
|
.await
|
|
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let bob_form = PersonInsertForm::builder()
|
|
|
|
let bob_form = PersonInsertForm::builder()
|
|
|
|
.name("bob".to_string())
|
|
|
|
.name("bob".to_string())
|
|
|
|
.bot_account(Some(true))
|
|
|
|
.bot_account(Some(true))
|
|
|
|
.public_key("pubkey".to_string())
|
|
|
|
.public_key("pubkey".to_string())
|
|
|
|
.instance_id(inserted_instance.id)
|
|
|
|
.instance_id(inserted_instance.id)
|
|
|
|
|
|
|
|
.local(Some(false))
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
let bob = Person::create(pool, &bob_form).await.unwrap();
|
|
|
|
let bob = Person::create(pool, &bob_form).await?;
|
|
|
|
let bob_local_user_form = LocalUserInsertForm::builder()
|
|
|
|
let bob_local_user_form = LocalUserInsertForm::builder()
|
|
|
|
.person_id(bob.id)
|
|
|
|
.person_id(bob.id)
|
|
|
|
.password_encrypted(String::new())
|
|
|
|
.password_encrypted(String::new())
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
let bob_local_user = LocalUser::create(pool, &bob_local_user_form).await.unwrap();
|
|
|
|
let bob_local_user = LocalUser::create(pool, &bob_local_user_form).await?;
|
|
|
|
|
|
|
|
|
|
|
|
Data {
|
|
|
|
Ok(Data {
|
|
|
|
alice,
|
|
|
|
alice,
|
|
|
|
alice_local_user,
|
|
|
|
alice_local_user,
|
|
|
|
bob,
|
|
|
|
bob,
|
|
|
|
bob_local_user,
|
|
|
|
bob_local_user,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn cleanup(data: Data, pool: &mut DbPool<'_>) {
|
|
|
|
async fn cleanup(data: Data, pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
|
|
|
LocalUser::delete(pool, data.alice_local_user.id)
|
|
|
|
LocalUser::delete(pool, data.alice_local_user.id).await?;
|
|
|
|
.await
|
|
|
|
LocalUser::delete(pool, data.bob_local_user.id).await?;
|
|
|
|
.unwrap();
|
|
|
|
Person::delete(pool, data.alice.id).await?;
|
|
|
|
LocalUser::delete(pool, data.bob_local_user.id)
|
|
|
|
Person::delete(pool, data.bob.id).await?;
|
|
|
|
.await
|
|
|
|
Instance::delete(pool, data.bob.instance_id).await?;
|
|
|
|
.unwrap();
|
|
|
|
Ok(())
|
|
|
|
Person::delete(pool, data.alice.id).await.unwrap();
|
|
|
|
|
|
|
|
Person::delete(pool, data.bob.id).await.unwrap();
|
|
|
|
|
|
|
|
Instance::delete(pool, data.bob.instance_id).await.unwrap();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
#[tokio::test]
|
|
|
|
#[serial]
|
|
|
|
#[serial]
|
|
|
|
async fn exclude_deleted() {
|
|
|
|
async fn exclude_deleted() -> LemmyResult<()> {
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
|
|
|
let pool = &mut pool.into();
|
|
|
|
let pool = &mut pool.into();
|
|
|
|
let data = init_data(pool).await;
|
|
|
|
let data = init_data(pool).await?;
|
|
|
|
|
|
|
|
|
|
|
|
Person::update(
|
|
|
|
Person::update(
|
|
|
|
pool,
|
|
|
|
pool,
|
|
|
@ -256,8 +252,7 @@ mod tests {
|
|
|
|
..Default::default()
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.await?;
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let read = PersonView::read(pool, data.alice.id).await;
|
|
|
|
let read = PersonView::read(pool, data.alice.id).await;
|
|
|
|
assert_eq!(read.err(), Some(NotFound));
|
|
|
|
assert_eq!(read.err(), Some(NotFound));
|
|
|
@ -267,20 +262,19 @@ mod tests {
|
|
|
|
..Default::default()
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.list(pool)
|
|
|
|
.list(pool)
|
|
|
|
.await
|
|
|
|
.await?;
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert_length!(1, list);
|
|
|
|
assert_length!(1, list);
|
|
|
|
assert_eq!(list[0].person.id, data.bob.id);
|
|
|
|
assert_eq!(list[0].person.id, data.bob.id);
|
|
|
|
|
|
|
|
|
|
|
|
cleanup(data, pool).await;
|
|
|
|
cleanup(data, pool).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
#[tokio::test]
|
|
|
|
#[serial]
|
|
|
|
#[serial]
|
|
|
|
async fn list_banned() {
|
|
|
|
async fn list_banned() -> LemmyResult<()> {
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
|
|
|
let pool = &mut pool.into();
|
|
|
|
let pool = &mut pool.into();
|
|
|
|
let data = init_data(pool).await;
|
|
|
|
let data = init_data(pool).await?;
|
|
|
|
|
|
|
|
|
|
|
|
Person::update(
|
|
|
|
Person::update(
|
|
|
|
pool,
|
|
|
|
pool,
|
|
|
@ -290,22 +284,21 @@ mod tests {
|
|
|
|
..Default::default()
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.await?;
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let list = PersonView::banned(pool).await.unwrap();
|
|
|
|
let list = PersonView::banned(pool).await?;
|
|
|
|
assert_length!(1, list);
|
|
|
|
assert_length!(1, list);
|
|
|
|
assert_eq!(list[0].person.id, data.alice.id);
|
|
|
|
assert_eq!(list[0].person.id, data.alice.id);
|
|
|
|
|
|
|
|
|
|
|
|
cleanup(data, pool).await;
|
|
|
|
cleanup(data, pool).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
#[tokio::test]
|
|
|
|
#[serial]
|
|
|
|
#[serial]
|
|
|
|
async fn list_admins() {
|
|
|
|
async fn list_admins() -> LemmyResult<()> {
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
|
|
|
let pool = &mut pool.into();
|
|
|
|
let pool = &mut pool.into();
|
|
|
|
let data = init_data(pool).await;
|
|
|
|
let data = init_data(pool).await?;
|
|
|
|
|
|
|
|
|
|
|
|
LocalUser::update(
|
|
|
|
LocalUser::update(
|
|
|
|
pool,
|
|
|
|
pool,
|
|
|
@ -315,22 +308,45 @@ mod tests {
|
|
|
|
..Default::default()
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.await?;
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let list = PersonView::admins(pool).await.unwrap();
|
|
|
|
let list = PersonView::admins(pool).await?;
|
|
|
|
assert_length!(1, list);
|
|
|
|
assert_length!(1, list);
|
|
|
|
assert_eq!(list[0].person.id, data.alice.id);
|
|
|
|
assert_eq!(list[0].person.id, data.alice.id);
|
|
|
|
|
|
|
|
|
|
|
|
let is_admin = PersonView::read(pool, data.alice.id)
|
|
|
|
let is_admin = PersonView::read(pool, data.alice.id).await?.is_admin;
|
|
|
|
.await
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.is_admin;
|
|
|
|
|
|
|
|
assert!(is_admin);
|
|
|
|
assert!(is_admin);
|
|
|
|
|
|
|
|
|
|
|
|
let is_admin = PersonView::read(pool, data.bob.id).await.unwrap().is_admin;
|
|
|
|
let is_admin = PersonView::read(pool, data.bob.id).await?.is_admin;
|
|
|
|
assert!(!is_admin);
|
|
|
|
assert!(!is_admin);
|
|
|
|
|
|
|
|
|
|
|
|
cleanup(data, pool).await;
|
|
|
|
cleanup(data, pool).await
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
|
|
|
#[serial]
|
|
|
|
|
|
|
|
async fn listing_type() -> LemmyResult<()> {
|
|
|
|
|
|
|
|
let pool = &build_db_pool_for_tests().await;
|
|
|
|
|
|
|
|
let pool = &mut pool.into();
|
|
|
|
|
|
|
|
let data = init_data(pool).await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let list = PersonQuery {
|
|
|
|
|
|
|
|
listing_type: Some(ListingType::Local),
|
|
|
|
|
|
|
|
..Default::default()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
.list(pool)
|
|
|
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
assert_length!(1, list);
|
|
|
|
|
|
|
|
assert_eq!(list[0].person.id, data.alice.id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let list = PersonQuery {
|
|
|
|
|
|
|
|
listing_type: Some(ListingType::All),
|
|
|
|
|
|
|
|
..Default::default()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
.list(pool)
|
|
|
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
assert_length!(2, list);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cleanup(data, pool).await
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|