mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-08 09:24:17 +00:00
Separating private message tests.
This commit is contained in:
parent
03fd521cc2
commit
7608774fb3
|
@ -140,6 +140,15 @@ impl LocalUser {
|
|||
}
|
||||
}
|
||||
|
||||
impl LocalUserInsertForm {
|
||||
pub fn test_form(person_id: PersonId) -> Self {
|
||||
Self::builder()
|
||||
.person_id(person_id)
|
||||
.password_encrypted(String::new())
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UserBackupLists {
|
||||
pub followed_communities: Vec<DbUrl>,
|
||||
pub saved_posts: Vec<DbUrl>,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
newtypes::{CommunityId, DbUrl, PersonId},
|
||||
newtypes::{CommunityId, DbUrl, InstanceId, PersonId},
|
||||
schema::{instance, local_user, person, person_follower},
|
||||
source::person::{
|
||||
Person,
|
||||
|
@ -86,6 +86,16 @@ impl Person {
|
|||
}
|
||||
}
|
||||
|
||||
impl PersonInsertForm {
|
||||
pub fn test_form(instance_id: InstanceId, name: &str) -> Self {
|
||||
Self::builder()
|
||||
.name(name.to_owned())
|
||||
.public_key("pubkey".to_string())
|
||||
.instance_id(instance_id)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ApubActor for Person {
|
||||
async fn read_from_apub_id(
|
||||
|
|
|
@ -698,7 +698,7 @@ mod tests {
|
|||
use lemmy_db_schema::{
|
||||
aggregates::structs::PostAggregates,
|
||||
impls::actor_language::UNDETERMINED_ID,
|
||||
newtypes::{InstanceId, LanguageId, PersonId},
|
||||
newtypes::LanguageId,
|
||||
source::{
|
||||
actor_language::LocalUserLanguage,
|
||||
comment::{Comment, CommentInsertForm},
|
||||
|
@ -757,37 +757,22 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn default_person_insert_form(instance_id: InstanceId, name: &str) -> PersonInsertForm {
|
||||
PersonInsertForm::builder()
|
||||
.name(name.to_owned())
|
||||
.public_key("pubkey".to_string())
|
||||
.instance_id(instance_id)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn default_local_user_form(person_id: PersonId) -> LocalUserInsertForm {
|
||||
LocalUserInsertForm::builder()
|
||||
.person_id(person_id)
|
||||
.password_encrypted(String::new())
|
||||
.build()
|
||||
}
|
||||
|
||||
async fn init_data(pool: &mut DbPool<'_>) -> LemmyResult<Data> {
|
||||
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
|
||||
|
||||
let new_person = default_person_insert_form(inserted_instance.id, "tegan");
|
||||
let new_person = PersonInsertForm::test_form(inserted_instance.id, "tegan");
|
||||
|
||||
let inserted_person = Person::create(pool, &new_person).await?;
|
||||
|
||||
let local_user_form = LocalUserInsertForm {
|
||||
admin: Some(true),
|
||||
..default_local_user_form(inserted_person.id)
|
||||
..LocalUserInsertForm::test_form(inserted_person.id)
|
||||
};
|
||||
let inserted_local_user = LocalUser::create(pool, &local_user_form).await?;
|
||||
|
||||
let new_bot = PersonInsertForm {
|
||||
bot_account: Some(true),
|
||||
..default_person_insert_form(inserted_instance.id, "mybot")
|
||||
..PersonInsertForm::test_form(inserted_instance.id, "mybot")
|
||||
};
|
||||
|
||||
let inserted_bot = Person::create(pool, &new_bot).await?;
|
||||
|
@ -802,12 +787,15 @@ mod tests {
|
|||
let inserted_community = Community::create(pool, &new_community).await?;
|
||||
|
||||
// Test a person block, make sure the post query doesn't include their post
|
||||
let blocked_person = default_person_insert_form(inserted_instance.id, "john");
|
||||
let blocked_person = PersonInsertForm::test_form(inserted_instance.id, "john");
|
||||
|
||||
let inserted_blocked_person = Person::create(pool, &blocked_person).await?;
|
||||
|
||||
let inserted_blocked_local_user =
|
||||
LocalUser::create(pool, &default_local_user_form(inserted_blocked_person.id)).await?;
|
||||
let inserted_blocked_local_user = LocalUser::create(
|
||||
pool,
|
||||
&LocalUserInsertForm::test_form(inserted_blocked_person.id),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let post_from_blocked_person = PostInsertForm::builder()
|
||||
.name(POST_BY_BLOCKED_PERSON.to_string())
|
||||
|
|
|
@ -180,6 +180,7 @@ mod tests {
|
|||
use crate::{private_message_view::PrivateMessageQuery, structs::PrivateMessageView};
|
||||
use lemmy_db_schema::{
|
||||
assert_length,
|
||||
newtypes::InstanceId,
|
||||
source::{
|
||||
instance::Instance,
|
||||
instance_block::{InstanceBlock, InstanceBlockForm},
|
||||
|
@ -188,17 +189,21 @@ mod tests {
|
|||
private_message::{PrivateMessage, PrivateMessageInsertForm},
|
||||
},
|
||||
traits::{Blockable, Crud},
|
||||
utils::build_db_pool_for_tests,
|
||||
utils::{build_db_pool_for_tests, DbPool},
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serial_test::serial;
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_crud() {
|
||||
struct Data {
|
||||
instance: Instance,
|
||||
timmy: Person,
|
||||
jess: Person,
|
||||
sara: Person,
|
||||
}
|
||||
|
||||
async fn init_data(pool: &mut DbPool<'_>) -> LemmyResult<Data> {
|
||||
let message_content = String::new();
|
||||
let pool = &build_db_pool_for_tests().await;
|
||||
let pool = &mut pool.into();
|
||||
|
||||
let instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
|
||||
.await
|
||||
|
@ -264,6 +269,32 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
Ok(Data {
|
||||
instance,
|
||||
timmy,
|
||||
jess,
|
||||
sara,
|
||||
})
|
||||
}
|
||||
|
||||
async fn cleanup(instance_id: InstanceId, pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||
// This also deletes all persons and private messages thanks to sql `on delete cascade`
|
||||
Instance::delete(pool, instance_id).await.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn read_private_messages() -> LemmyResult<()> {
|
||||
let pool = &build_db_pool_for_tests().await;
|
||||
let pool = &mut pool.into();
|
||||
let Data {
|
||||
timmy,
|
||||
jess,
|
||||
sara,
|
||||
instance,
|
||||
} = init_data(pool).await?;
|
||||
|
||||
let timmy_messages = PrivateMessageQuery {
|
||||
unread_only: false,
|
||||
creator_id: None,
|
||||
|
@ -324,6 +355,21 @@ mod tests {
|
|||
assert_eq!(timmy_sara_unread_messages[0].creator.id, sara.id);
|
||||
assert_eq!(timmy_sara_unread_messages[0].recipient.id, timmy.id);
|
||||
|
||||
cleanup(instance.id, pool).await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn ensure_person_block() -> LemmyResult<()> {
|
||||
let pool = &build_db_pool_for_tests().await;
|
||||
let pool = &mut pool.into();
|
||||
let Data {
|
||||
timmy,
|
||||
sara,
|
||||
instance,
|
||||
jess: _,
|
||||
} = init_data(pool).await?;
|
||||
|
||||
// Make sure blocks are working
|
||||
let timmy_blocks_sara_form = PersonBlockForm {
|
||||
person_id: timmy.id,
|
||||
|
@ -357,6 +403,20 @@ mod tests {
|
|||
.unwrap();
|
||||
assert_eq!(timmy_unread_messages, 1);
|
||||
|
||||
cleanup(instance.id, pool).await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn ensure_instance_block() -> LemmyResult<()> {
|
||||
let pool = &build_db_pool_for_tests().await;
|
||||
let pool = &mut pool.into();
|
||||
let Data {
|
||||
timmy,
|
||||
jess: _,
|
||||
sara,
|
||||
instance,
|
||||
} = init_data(pool).await?;
|
||||
// Make sure instance_blocks are working
|
||||
let timmy_blocks_instance_form = InstanceBlockForm {
|
||||
person_id: timmy.id,
|
||||
|
@ -389,8 +449,6 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
assert_eq!(timmy_unread_messages, 0);
|
||||
|
||||
// This also deletes all persons and private messages thanks to sql `on delete cascade`
|
||||
Instance::delete(pool, instance.id).await.unwrap();
|
||||
cleanup(instance.id, pool).await
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue