mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
Merge a697bb92c5
into 44dda08b13
This commit is contained in:
commit
215b67095c
@ -34,13 +34,10 @@ use lemmy_db_views::structs::LocalUserView;
|
|||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType, CACHE_DURATION_API};
|
use lemmy_utils::{error::LemmyResult, LemmyErrorType, CACHE_DURATION_API};
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
async fn create_test_site(context: &Data<LemmyContext>) -> LemmyResult<(Instance, LocalUserView)> {
|
async fn create_test_site(context: &Data<LemmyContext>) -> LemmyResult<(Instance, LocalUserView)> {
|
||||||
let pool = &mut context.pool();
|
let pool = &mut context.pool();
|
||||||
|
|
||||||
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
|
|
||||||
.expect("Create test instance");
|
|
||||||
|
|
||||||
let admin_person = Person::create(
|
let admin_person = Person::create(
|
||||||
pool,
|
pool,
|
||||||
@ -57,7 +54,7 @@ async fn create_test_site(context: &Data<LemmyContext>) -> LemmyResult<(Instance
|
|||||||
let admin_local_user_view = LocalUserView::read_person(pool, admin_person.id).await?;
|
let admin_local_user_view = LocalUserView::read_person(pool, admin_person.id).await?;
|
||||||
|
|
||||||
let site_form = SiteInsertForm::new("test site".to_string(), inserted_instance.id);
|
let site_form = SiteInsertForm::new("test site".to_string(), inserted_instance.id);
|
||||||
let site = Site::create(pool, &site_form).await.unwrap();
|
let site = Site::create(pool, &site_form).await?;
|
||||||
|
|
||||||
// Create a local site, since this is necessary for determining if email verification is
|
// Create a local site, since this is necessary for determining if email verification is
|
||||||
// required
|
// required
|
||||||
@ -68,14 +65,12 @@ async fn create_test_site(context: &Data<LemmyContext>) -> LemmyResult<(Instance
|
|||||||
site_setup: Some(true),
|
site_setup: Some(true),
|
||||||
..LocalSiteInsertForm::new(site.id)
|
..LocalSiteInsertForm::new(site.id)
|
||||||
};
|
};
|
||||||
let local_site = LocalSite::create(pool, &local_site_form).await.unwrap();
|
let local_site = LocalSite::create(pool, &local_site_form).await?;
|
||||||
|
|
||||||
// Required to have a working local SiteView when updating the site to change email verification
|
// Required to have a working local SiteView when updating the site to change email verification
|
||||||
// requirement or registration mode
|
// requirement or registration mode
|
||||||
let rate_limit_form = LocalSiteRateLimitInsertForm::new(local_site.id);
|
let rate_limit_form = LocalSiteRateLimitInsertForm::new(local_site.id);
|
||||||
LocalSiteRateLimit::create(pool, &rate_limit_form)
|
LocalSiteRateLimit::create(pool, &rate_limit_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Ok((inserted_instance, admin_local_user_view))
|
Ok((inserted_instance, admin_local_user_view))
|
||||||
}
|
}
|
||||||
@ -109,7 +104,6 @@ async fn signup(
|
|||||||
Ok((local_user, application))
|
Ok((local_user, application))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
async fn get_application_statuses(
|
async fn get_application_statuses(
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
admin: LocalUserView,
|
admin: LocalUserView,
|
||||||
@ -122,14 +116,14 @@ async fn get_application_statuses(
|
|||||||
get_unread_registration_application_count(context.reset_request_count(), admin.clone()).await?;
|
get_unread_registration_application_count(context.reset_request_count(), admin.clone()).await?;
|
||||||
|
|
||||||
let unread_applications = list_registration_applications(
|
let unread_applications = list_registration_applications(
|
||||||
Query::from_query("unread_only=true").unwrap(),
|
Query::from_query("unread_only=true")?,
|
||||||
context.reset_request_count(),
|
context.reset_request_count(),
|
||||||
admin.clone(),
|
admin.clone(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let all_applications = list_registration_applications(
|
let all_applications = list_registration_applications(
|
||||||
Query::from_query("unread_only=false").unwrap(),
|
Query::from_query("unread_only=false")?,
|
||||||
context.reset_request_count(),
|
context.reset_request_count(),
|
||||||
admin,
|
admin,
|
||||||
)
|
)
|
||||||
|
@ -49,14 +49,15 @@ pub(crate) mod tests {
|
|||||||
use chrono::{DateTime, NaiveDate, Utc};
|
use chrono::{DateTime, NaiveDate, Utc};
|
||||||
use elementtree::Element;
|
use elementtree::Element;
|
||||||
use lemmy_db_schema::newtypes::DbUrl;
|
use lemmy_db_schema::newtypes::DbUrl;
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_generate_urlset() {
|
async fn test_generate_urlset() -> LemmyResult<()> {
|
||||||
let posts: Vec<(DbUrl, DateTime<Utc>)> = vec![
|
let posts: Vec<(DbUrl, DateTime<Utc>)> = vec![
|
||||||
(
|
(
|
||||||
Url::parse("https://example.com").unwrap().into(),
|
Url::parse("https://example.com")?.into(),
|
||||||
NaiveDate::from_ymd_opt(2022, 12, 1)
|
NaiveDate::from_ymd_opt(2022, 12, 1)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.and_hms_opt(9, 10, 11)
|
.and_hms_opt(9, 10, 11)
|
||||||
@ -64,7 +65,7 @@ pub(crate) mod tests {
|
|||||||
.and_utc(),
|
.and_utc(),
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
Url::parse("https://lemmy.ml").unwrap().into(),
|
Url::parse("https://lemmy.ml")?.into(),
|
||||||
NaiveDate::from_ymd_opt(2023, 1, 1)
|
NaiveDate::from_ymd_opt(2023, 1, 1)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.and_hms_opt(1, 2, 3)
|
.and_hms_opt(1, 2, 3)
|
||||||
@ -74,12 +75,8 @@ pub(crate) mod tests {
|
|||||||
];
|
];
|
||||||
|
|
||||||
let mut buf = Vec::<u8>::new();
|
let mut buf = Vec::<u8>::new();
|
||||||
generate_urlset(posts)
|
generate_urlset(posts).await?.write(&mut buf)?;
|
||||||
.await
|
let root = Element::from_reader(buf.as_slice())?;
|
||||||
.unwrap()
|
|
||||||
.write(&mut buf)
|
|
||||||
.unwrap();
|
|
||||||
let root = Element::from_reader(buf.as_slice()).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(root.tag().name(), "urlset");
|
assert_eq!(root.tag().name(), "urlset");
|
||||||
assert_eq!(root.child_count(), 2);
|
assert_eq!(root.child_count(), 2);
|
||||||
@ -139,5 +136,7 @@ pub(crate) mod tests {
|
|||||||
.text(),
|
.text(),
|
||||||
"2023-01-01T01:02:03+00:00"
|
"2023-01-01T01:02:03+00:00"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ mod tests {
|
|||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::build_db_pool_for_tests,
|
utils::build_db_pool_for_tests,
|
||||||
};
|
};
|
||||||
use lemmy_utils::rate_limit::RateLimitCell;
|
use lemmy_utils::{error::LemmyResult, rate_limit::RateLimitCell};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use reqwest_middleware::ClientBuilder;
|
use reqwest_middleware::ClientBuilder;
|
||||||
@ -92,10 +92,10 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_should_not_validate_user_token_after_password_change() {
|
async fn test_should_not_validate_user_token_after_password_change() -> 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 secret = Secret::init(pool).await.unwrap().unwrap();
|
let secret = Secret::init(pool).await?.unwrap();
|
||||||
let context = LemmyContext::create(
|
let context = LemmyContext::create(
|
||||||
pool_.clone(),
|
pool_.clone(),
|
||||||
ClientBuilder::new(Client::default()).build(),
|
ClientBuilder::new(Client::default()).build(),
|
||||||
@ -103,29 +103,25 @@ mod tests {
|
|||||||
RateLimitCell::with_test_config(),
|
RateLimitCell::with_test_config(),
|
||||||
);
|
);
|
||||||
|
|
||||||
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 new_person = PersonInsertForm::test_form(inserted_instance.id, "Gerry9812");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "Gerry9812");
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
let inserted_person = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let local_user_form = LocalUserInsertForm::test_form(inserted_person.id);
|
let local_user_form = LocalUserInsertForm::test_form(inserted_person.id);
|
||||||
|
|
||||||
let inserted_local_user = LocalUser::create(pool, &local_user_form, vec![])
|
let inserted_local_user = LocalUser::create(pool, &local_user_form, vec![]).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let req = TestRequest::default().to_http_request();
|
let req = TestRequest::default().to_http_request();
|
||||||
let jwt = Claims::generate(inserted_local_user.id, req, &context)
|
let jwt = Claims::generate(inserted_local_user.id, req, &context).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let valid = Claims::validate(&jwt, &context).await;
|
let valid = Claims::validate(&jwt, &context).await;
|
||||||
assert!(valid.is_ok());
|
assert!(valid.is_ok());
|
||||||
|
|
||||||
let num_deleted = Person::delete(pool, inserted_person.id).await.unwrap();
|
let num_deleted = Person::delete(pool, inserted_person.id).await?;
|
||||||
assert_eq!(1, num_deleted);
|
assert_eq!(1, num_deleted);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -471,13 +471,13 @@ pub async fn replace_image(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
request::{extract_opengraph_data, fetch_link_metadata},
|
request::{extract_opengraph_data, fetch_link_metadata},
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
@ -485,10 +485,10 @@ mod tests {
|
|||||||
// These helped with testing
|
// These helped with testing
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_link_metadata() {
|
async fn test_link_metadata() -> LemmyResult<()> {
|
||||||
let context = LemmyContext::init_test_context().await;
|
let context = LemmyContext::init_test_context().await;
|
||||||
let sample_url = Url::parse("https://gitlab.com/IzzyOnDroid/repo/-/wikis/FAQ").unwrap();
|
let sample_url = Url::parse("https://gitlab.com/IzzyOnDroid/repo/-/wikis/FAQ")?;
|
||||||
let sample_res = fetch_link_metadata(&sample_url, &context).await.unwrap();
|
let sample_res = fetch_link_metadata(&sample_url, &context).await?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Some("FAQ · Wiki · IzzyOnDroid / repo · GitLab".to_string()),
|
Some("FAQ · Wiki · IzzyOnDroid / repo · GitLab".to_string()),
|
||||||
sample_res.opengraph_data.title
|
sample_res.opengraph_data.title
|
||||||
@ -499,8 +499,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Some(
|
Some(
|
||||||
Url::parse("https://gitlab.com/uploads/-/system/project/avatar/4877469/iod_logo.png")
|
Url::parse("https://gitlab.com/uploads/-/system/project/avatar/4877469/iod_logo.png")?
|
||||||
.unwrap()
|
|
||||||
.into()
|
.into()
|
||||||
),
|
),
|
||||||
sample_res.opengraph_data.image
|
sample_res.opengraph_data.image
|
||||||
@ -510,19 +509,21 @@ mod tests {
|
|||||||
Some(mime::TEXT_HTML_UTF_8.to_string()),
|
Some(mime::TEXT_HTML_UTF_8.to_string()),
|
||||||
sample_res.content_type
|
sample_res.content_type
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_resolve_image_url() {
|
fn test_resolve_image_url() -> LemmyResult<()> {
|
||||||
// url that lists the opengraph fields
|
// url that lists the opengraph fields
|
||||||
let url = Url::parse("https://example.com/one/two.html").unwrap();
|
let url = Url::parse("https://example.com/one/two.html")?;
|
||||||
|
|
||||||
// root relative url
|
// root relative url
|
||||||
let html_bytes = b"<!DOCTYPE html><html><head><meta property='og:image' content='/image.jpg'></head><body></body></html>";
|
let html_bytes = b"<!DOCTYPE html><html><head><meta property='og:image' content='/image.jpg'></head><body></body></html>";
|
||||||
let metadata = extract_opengraph_data(html_bytes, &url).expect("Unable to parse metadata");
|
let metadata = extract_opengraph_data(html_bytes, &url).expect("Unable to parse metadata");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
metadata.image,
|
metadata.image,
|
||||||
Some(Url::parse("https://example.com/image.jpg").unwrap().into())
|
Some(Url::parse("https://example.com/image.jpg")?.into())
|
||||||
);
|
);
|
||||||
|
|
||||||
// base relative url
|
// base relative url
|
||||||
@ -530,11 +531,7 @@ mod tests {
|
|||||||
let metadata = extract_opengraph_data(html_bytes, &url).expect("Unable to parse metadata");
|
let metadata = extract_opengraph_data(html_bytes, &url).expect("Unable to parse metadata");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
metadata.image,
|
metadata.image,
|
||||||
Some(
|
Some(Url::parse("https://example.com/one/image.jpg")?.into())
|
||||||
Url::parse("https://example.com/one/image.jpg")
|
|
||||||
.unwrap()
|
|
||||||
.into()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// absolute url
|
// absolute url
|
||||||
@ -542,7 +539,7 @@ mod tests {
|
|||||||
let metadata = extract_opengraph_data(html_bytes, &url).expect("Unable to parse metadata");
|
let metadata = extract_opengraph_data(html_bytes, &url).expect("Unable to parse metadata");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
metadata.image,
|
metadata.image,
|
||||||
Some(Url::parse("https://cdn.host.com/image.jpg").unwrap().into())
|
Some(Url::parse("https://cdn.host.com/image.jpg")?.into())
|
||||||
);
|
);
|
||||||
|
|
||||||
// protocol relative url
|
// protocol relative url
|
||||||
@ -550,7 +547,9 @@ mod tests {
|
|||||||
let metadata = extract_opengraph_data(html_bytes, &url).expect("Unable to parse metadata");
|
let metadata = extract_opengraph_data(html_bytes, &url).expect("Unable to parse metadata");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
metadata.image,
|
metadata.image,
|
||||||
Some(Url::parse("https://example.com/image.jpg").unwrap().into())
|
Some(Url::parse("https://example.com/image.jpg")?.into())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1067,7 +1067,6 @@ fn build_proxied_image_url(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -1092,48 +1091,42 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_limit_ban_term() {
|
fn test_limit_ban_term() -> LemmyResult<()> {
|
||||||
// Ban expires in past, should throw error
|
// Ban expires in past, should throw error
|
||||||
assert!(limit_expire_time(Utc::now() - Days::new(5)).is_err());
|
assert!(limit_expire_time(Utc::now() - Days::new(5)).is_err());
|
||||||
|
|
||||||
// Legitimate ban term, return same value
|
// Legitimate ban term, return same value
|
||||||
let fourteen_days = Utc::now() + Days::new(14);
|
let fourteen_days = Utc::now() + Days::new(14);
|
||||||
assert_eq!(
|
assert_eq!(limit_expire_time(fourteen_days)?, Some(fourteen_days));
|
||||||
limit_expire_time(fourteen_days).unwrap(),
|
|
||||||
Some(fourteen_days)
|
|
||||||
);
|
|
||||||
let nine_years = Utc::now() + Days::new(365 * 9);
|
let nine_years = Utc::now() + Days::new(365 * 9);
|
||||||
assert_eq!(limit_expire_time(nine_years).unwrap(), Some(nine_years));
|
assert_eq!(limit_expire_time(nine_years)?, Some(nine_years));
|
||||||
|
|
||||||
// Too long ban term, changes to None (permanent ban)
|
// Too long ban term, changes to None (permanent ban)
|
||||||
assert_eq!(
|
assert_eq!(limit_expire_time(Utc::now() + Days::new(365 * 11))?, None);
|
||||||
limit_expire_time(Utc::now() + Days::new(365 * 11)).unwrap(),
|
|
||||||
None
|
Ok(())
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_proxy_image_link() {
|
async fn test_proxy_image_link() -> LemmyResult<()> {
|
||||||
let context = LemmyContext::init_test_context().await;
|
let context = LemmyContext::init_test_context().await;
|
||||||
|
|
||||||
// image from local domain is unchanged
|
// image from local domain is unchanged
|
||||||
let local_url = Url::parse("http://lemmy-alpha/image.png").unwrap();
|
let local_url = Url::parse("http://lemmy-alpha/image.png")?;
|
||||||
let proxied =
|
let proxied =
|
||||||
proxy_image_link_internal(local_url.clone(), PictrsImageMode::ProxyAllImages, &context)
|
proxy_image_link_internal(local_url.clone(), PictrsImageMode::ProxyAllImages, &context)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(&local_url, proxied.inner());
|
assert_eq!(&local_url, proxied.inner());
|
||||||
|
|
||||||
// image from remote domain is proxied
|
// image from remote domain is proxied
|
||||||
let remote_image = Url::parse("http://lemmy-beta/image.png").unwrap();
|
let remote_image = Url::parse("http://lemmy-beta/image.png")?;
|
||||||
let proxied = proxy_image_link_internal(
|
let proxied = proxy_image_link_internal(
|
||||||
remote_image.clone(),
|
remote_image.clone(),
|
||||||
PictrsImageMode::ProxyAllImages,
|
PictrsImageMode::ProxyAllImages,
|
||||||
&context,
|
&context,
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Flemmy-beta%2Fimage.png",
|
"https://lemmy-alpha/api/v3/image_proxy?url=http%3A%2F%2Flemmy-beta%2Fimage.png",
|
||||||
proxied.as_str()
|
proxied.as_str()
|
||||||
@ -1146,5 +1139,7 @@ mod tests {
|
|||||||
.await
|
.await
|
||||||
.is_ok()
|
.is_ok()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ impl CommentAggregates {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -45,26 +44,25 @@ mod tests {
|
|||||||
traits::{Crud, Likeable},
|
traits::{Crud, Likeable},
|
||||||
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;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 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 new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_comment_agg");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_comment_agg");
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
let inserted_person = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let another_person = PersonInsertForm::test_form(inserted_instance.id, "jerry_comment_agg");
|
let another_person = PersonInsertForm::test_form(inserted_instance.id, "jerry_comment_agg");
|
||||||
|
|
||||||
let another_inserted_person = Person::create(pool, &another_person).await.unwrap();
|
let another_inserted_person = Person::create(pool, &another_person).await?;
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -72,21 +70,21 @@ mod tests {
|
|||||||
"nada".to_owned(),
|
"nada".to_owned(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
let new_post = PostInsertForm::new(
|
||||||
"A test post".into(),
|
"A test post".into(),
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
let inserted_post = Post::create(pool, &new_post).await.unwrap();
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::new(
|
let comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"A test comment".into(),
|
"A test comment".into(),
|
||||||
);
|
);
|
||||||
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
let inserted_comment = Comment::create(pool, &comment_form, None).await?;
|
||||||
|
|
||||||
let child_comment_form = CommentInsertForm::new(
|
let child_comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
@ -94,9 +92,7 @@ mod tests {
|
|||||||
"A test comment".into(),
|
"A test comment".into(),
|
||||||
);
|
);
|
||||||
let _inserted_child_comment =
|
let _inserted_child_comment =
|
||||||
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path))
|
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let comment_like = CommentLikeForm {
|
let comment_like = CommentLikeForm {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
@ -105,11 +101,9 @@ mod tests {
|
|||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommentLike::like(pool, &comment_like).await.unwrap();
|
CommentLike::like(pool, &comment_like).await?;
|
||||||
|
|
||||||
let comment_aggs_before_delete = CommentAggregates::read(pool, inserted_comment.id)
|
let comment_aggs_before_delete = CommentAggregates::read(pool, inserted_comment.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(1, comment_aggs_before_delete.score);
|
assert_eq!(1, comment_aggs_before_delete.score);
|
||||||
assert_eq!(1, comment_aggs_before_delete.upvotes);
|
assert_eq!(1, comment_aggs_before_delete.upvotes);
|
||||||
@ -123,47 +117,39 @@ mod tests {
|
|||||||
score: -1,
|
score: -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommentLike::like(pool, &comment_dislike).await.unwrap();
|
CommentLike::like(pool, &comment_dislike).await?;
|
||||||
|
|
||||||
let comment_aggs_after_dislike = CommentAggregates::read(pool, inserted_comment.id)
|
let comment_aggs_after_dislike = CommentAggregates::read(pool, inserted_comment.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(0, comment_aggs_after_dislike.score);
|
assert_eq!(0, comment_aggs_after_dislike.score);
|
||||||
assert_eq!(1, comment_aggs_after_dislike.upvotes);
|
assert_eq!(1, comment_aggs_after_dislike.upvotes);
|
||||||
assert_eq!(1, comment_aggs_after_dislike.downvotes);
|
assert_eq!(1, comment_aggs_after_dislike.downvotes);
|
||||||
|
|
||||||
// Remove the first comment like
|
// Remove the first comment like
|
||||||
CommentLike::remove(pool, inserted_person.id, inserted_comment.id)
|
CommentLike::remove(pool, inserted_person.id, inserted_comment.id).await?;
|
||||||
.await
|
let after_like_remove = CommentAggregates::read(pool, inserted_comment.id).await?;
|
||||||
.unwrap();
|
|
||||||
let after_like_remove = CommentAggregates::read(pool, inserted_comment.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(-1, after_like_remove.score);
|
assert_eq!(-1, after_like_remove.score);
|
||||||
assert_eq!(0, after_like_remove.upvotes);
|
assert_eq!(0, after_like_remove.upvotes);
|
||||||
assert_eq!(1, after_like_remove.downvotes);
|
assert_eq!(1, after_like_remove.downvotes);
|
||||||
|
|
||||||
// Remove the parent post
|
// Remove the parent post
|
||||||
Post::delete(pool, inserted_post.id).await.unwrap();
|
Post::delete(pool, inserted_post.id).await?;
|
||||||
|
|
||||||
// Should be none found, since the post was deleted
|
// Should be none found, since the post was deleted
|
||||||
let after_delete = CommentAggregates::read(pool, inserted_comment.id).await;
|
let after_delete = CommentAggregates::read(pool, inserted_comment.id).await;
|
||||||
assert!(after_delete.is_err());
|
assert!(after_delete.is_err());
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
Person::delete(pool, another_inserted_person.id)
|
Person::delete(pool, another_inserted_person.id).await?;
|
||||||
.await
|
let person_num_deleted = Person::delete(pool, inserted_person.id).await?;
|
||||||
.unwrap();
|
|
||||||
let person_num_deleted = Person::delete(pool, inserted_person.id).await.unwrap();
|
|
||||||
assert_eq!(1, person_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
|
|
||||||
// Delete the community
|
// Delete the community
|
||||||
let community_num_deleted = Community::delete(pool, inserted_community.id)
|
let community_num_deleted = Community::delete(pool, inserted_community.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(1, community_num_deleted);
|
assert_eq!(1, community_num_deleted);
|
||||||
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,26 +51,25 @@ mod tests {
|
|||||||
traits::{Crud, Followable},
|
traits::{Crud, Followable},
|
||||||
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;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 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 new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_community_agg");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_community_agg");
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
let inserted_person = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let another_person = PersonInsertForm::test_form(inserted_instance.id, "jerry_community_agg");
|
let another_person = PersonInsertForm::test_form(inserted_instance.id, "jerry_community_agg");
|
||||||
|
|
||||||
let another_inserted_person = Person::create(pool, &another_person).await.unwrap();
|
let another_inserted_person = Person::create(pool, &another_person).await?;
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -78,7 +77,7 @@ mod tests {
|
|||||||
"nada".to_owned(),
|
"nada".to_owned(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
|
|
||||||
let another_community = CommunityInsertForm::new(
|
let another_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -86,7 +85,7 @@ mod tests {
|
|||||||
"nada".to_owned(),
|
"nada".to_owned(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let another_inserted_community = Community::create(pool, &another_community).await.unwrap();
|
let another_inserted_community = Community::create(pool, &another_community).await?;
|
||||||
|
|
||||||
let first_person_follow = CommunityFollowerForm {
|
let first_person_follow = CommunityFollowerForm {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
@ -94,9 +93,7 @@ mod tests {
|
|||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommunityFollower::follow(pool, &first_person_follow)
|
CommunityFollower::follow(pool, &first_person_follow).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let second_person_follow = CommunityFollowerForm {
|
let second_person_follow = CommunityFollowerForm {
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
@ -104,9 +101,7 @@ mod tests {
|
|||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommunityFollower::follow(pool, &second_person_follow)
|
CommunityFollower::follow(pool, &second_person_follow).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let another_community_follow = CommunityFollowerForm {
|
let another_community_follow = CommunityFollowerForm {
|
||||||
community_id: another_inserted_community.id,
|
community_id: another_inserted_community.id,
|
||||||
@ -114,23 +109,21 @@ mod tests {
|
|||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommunityFollower::follow(pool, &another_community_follow)
|
CommunityFollower::follow(pool, &another_community_follow).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
let new_post = PostInsertForm::new(
|
||||||
"A test post".into(),
|
"A test post".into(),
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
let inserted_post = Post::create(pool, &new_post).await.unwrap();
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::new(
|
let comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"A test comment".into(),
|
"A test comment".into(),
|
||||||
);
|
);
|
||||||
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
let inserted_comment = Comment::create(pool, &comment_form, None).await?;
|
||||||
|
|
||||||
let child_comment_form = CommentInsertForm::new(
|
let child_comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
@ -138,13 +131,10 @@ mod tests {
|
|||||||
"A test comment".into(),
|
"A test comment".into(),
|
||||||
);
|
);
|
||||||
let _inserted_child_comment =
|
let _inserted_child_comment =
|
||||||
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path))
|
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let community_aggregates_before_delete = CommunityAggregates::read(pool, inserted_community.id)
|
let community_aggregates_before_delete = CommunityAggregates::read(pool, inserted_community.id)
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(2, community_aggregates_before_delete.subscribers);
|
assert_eq!(2, community_aggregates_before_delete.subscribers);
|
||||||
@ -154,8 +144,7 @@ mod tests {
|
|||||||
|
|
||||||
// Test the other community
|
// Test the other community
|
||||||
let another_community_aggs = CommunityAggregates::read(pool, another_inserted_community.id)
|
let another_community_aggs = CommunityAggregates::read(pool, another_inserted_community.id)
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, another_community_aggs.subscribers);
|
assert_eq!(1, another_community_aggs.subscribers);
|
||||||
assert_eq!(1, another_community_aggs.subscribers_local);
|
assert_eq!(1, another_community_aggs.subscribers_local);
|
||||||
@ -163,66 +152,53 @@ mod tests {
|
|||||||
assert_eq!(0, another_community_aggs.comments);
|
assert_eq!(0, another_community_aggs.comments);
|
||||||
|
|
||||||
// Unfollow test
|
// Unfollow test
|
||||||
CommunityFollower::unfollow(pool, &second_person_follow)
|
CommunityFollower::unfollow(pool, &second_person_follow).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let after_unfollow = CommunityAggregates::read(pool, inserted_community.id)
|
let after_unfollow = CommunityAggregates::read(pool, inserted_community.id)
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, after_unfollow.subscribers);
|
assert_eq!(1, after_unfollow.subscribers);
|
||||||
assert_eq!(1, after_unfollow.subscribers_local);
|
assert_eq!(1, after_unfollow.subscribers_local);
|
||||||
|
|
||||||
// Follow again just for the later tests
|
// Follow again just for the later tests
|
||||||
CommunityFollower::follow(pool, &second_person_follow)
|
CommunityFollower::follow(pool, &second_person_follow).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let after_follow_again = CommunityAggregates::read(pool, inserted_community.id)
|
let after_follow_again = CommunityAggregates::read(pool, inserted_community.id)
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(2, after_follow_again.subscribers);
|
assert_eq!(2, after_follow_again.subscribers);
|
||||||
assert_eq!(2, after_follow_again.subscribers_local);
|
assert_eq!(2, after_follow_again.subscribers_local);
|
||||||
|
|
||||||
// Remove a parent post (the comment count should also be 0)
|
// Remove a parent post (the comment count should also be 0)
|
||||||
Post::delete(pool, inserted_post.id).await.unwrap();
|
Post::delete(pool, inserted_post.id).await?;
|
||||||
let after_parent_post_delete = CommunityAggregates::read(pool, inserted_community.id)
|
let after_parent_post_delete = CommunityAggregates::read(pool, inserted_community.id)
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(0, after_parent_post_delete.comments);
|
assert_eq!(0, after_parent_post_delete.comments);
|
||||||
assert_eq!(0, after_parent_post_delete.posts);
|
assert_eq!(0, after_parent_post_delete.posts);
|
||||||
|
|
||||||
// Remove the 2nd person
|
// Remove the 2nd person
|
||||||
Person::delete(pool, another_inserted_person.id)
|
Person::delete(pool, another_inserted_person.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let after_person_delete = CommunityAggregates::read(pool, inserted_community.id)
|
let after_person_delete = CommunityAggregates::read(pool, inserted_community.id)
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(1, after_person_delete.subscribers);
|
assert_eq!(1, after_person_delete.subscribers);
|
||||||
assert_eq!(1, after_person_delete.subscribers_local);
|
assert_eq!(1, after_person_delete.subscribers_local);
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
let person_num_deleted = Person::delete(pool, inserted_person.id).await.unwrap();
|
let person_num_deleted = Person::delete(pool, inserted_person.id).await?;
|
||||||
assert_eq!(1, person_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
|
|
||||||
// Delete the community
|
// Delete the community
|
||||||
let community_num_deleted = Community::delete(pool, inserted_community.id)
|
let community_num_deleted = Community::delete(pool, inserted_community.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(1, community_num_deleted);
|
assert_eq!(1, community_num_deleted);
|
||||||
|
|
||||||
let another_community_num_deleted = Community::delete(pool, another_inserted_community.id)
|
let another_community_num_deleted =
|
||||||
.await
|
Community::delete(pool, another_inserted_community.id).await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(1, another_community_num_deleted);
|
assert_eq!(1, another_community_num_deleted);
|
||||||
|
|
||||||
// Should be none found, since the creator was deleted
|
// Should be none found, since the creator was deleted
|
||||||
let after_delete = CommunityAggregates::read(pool, inserted_community.id)
|
let after_delete = CommunityAggregates::read(pool, inserted_community.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert!(after_delete.is_none());
|
assert!(after_delete.is_none());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,26 +35,25 @@ mod tests {
|
|||||||
traits::{Crud, Likeable},
|
traits::{Crud, Likeable},
|
||||||
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;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 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 new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_user_agg");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_user_agg");
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
let inserted_person = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let another_person = PersonInsertForm::test_form(inserted_instance.id, "jerry_user_agg");
|
let another_person = PersonInsertForm::test_form(inserted_instance.id, "jerry_user_agg");
|
||||||
|
|
||||||
let another_inserted_person = Person::create(pool, &another_person).await.unwrap();
|
let another_inserted_person = Person::create(pool, &another_person).await?;
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -63,28 +62,28 @@ mod tests {
|
|||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
let new_post = PostInsertForm::new(
|
||||||
"A test post".into(),
|
"A test post".into(),
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
let inserted_post = Post::create(pool, &new_post).await.unwrap();
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let post_like = PostLikeForm {
|
let post_like = PostLikeForm {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
person_id: inserted_person.id,
|
person_id: inserted_person.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
let _inserted_post_like = PostLike::like(pool, &post_like).await.unwrap();
|
let _inserted_post_like = PostLike::like(pool, &post_like).await?;
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::new(
|
let comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"A test comment".into(),
|
"A test comment".into(),
|
||||||
);
|
);
|
||||||
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
let inserted_comment = Comment::create(pool, &comment_form, None).await?;
|
||||||
|
|
||||||
let mut comment_like = CommentLikeForm {
|
let mut comment_like = CommentLikeForm {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
@ -93,7 +92,7 @@ mod tests {
|
|||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _inserted_comment_like = CommentLike::like(pool, &comment_like).await.unwrap();
|
let _inserted_comment_like = CommentLike::like(pool, &comment_like).await?;
|
||||||
|
|
||||||
let child_comment_form = CommentInsertForm::new(
|
let child_comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
@ -101,9 +100,7 @@ mod tests {
|
|||||||
"A test comment".into(),
|
"A test comment".into(),
|
||||||
);
|
);
|
||||||
let inserted_child_comment =
|
let inserted_child_comment =
|
||||||
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path))
|
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let child_comment_like = CommentLikeForm {
|
let child_comment_like = CommentLikeForm {
|
||||||
comment_id: inserted_child_comment.id,
|
comment_id: inserted_child_comment.id,
|
||||||
@ -112,11 +109,10 @@ mod tests {
|
|||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _inserted_child_comment_like = CommentLike::like(pool, &child_comment_like).await.unwrap();
|
let _inserted_child_comment_like = CommentLike::like(pool, &child_comment_like).await?;
|
||||||
|
|
||||||
let person_aggregates_before_delete = PersonAggregates::read(pool, inserted_person.id)
|
let person_aggregates_before_delete = PersonAggregates::read(pool, inserted_person.id)
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(1, person_aggregates_before_delete.post_count);
|
assert_eq!(1, person_aggregates_before_delete.post_count);
|
||||||
@ -125,12 +121,9 @@ mod tests {
|
|||||||
assert_eq!(2, person_aggregates_before_delete.comment_score);
|
assert_eq!(2, person_aggregates_before_delete.comment_score);
|
||||||
|
|
||||||
// Remove a post like
|
// Remove a post like
|
||||||
PostLike::remove(pool, inserted_person.id, inserted_post.id)
|
PostLike::remove(pool, inserted_person.id, inserted_post.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let after_post_like_remove = PersonAggregates::read(pool, inserted_person.id)
|
let after_post_like_remove = PersonAggregates::read(pool, inserted_person.id)
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(0, after_post_like_remove.post_score);
|
assert_eq!(0, after_post_like_remove.post_score);
|
||||||
|
|
||||||
@ -142,8 +135,7 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
Comment::update(
|
Comment::update(
|
||||||
pool,
|
pool,
|
||||||
inserted_child_comment.id,
|
inserted_child_comment.id,
|
||||||
@ -152,50 +144,41 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let after_parent_comment_removed = PersonAggregates::read(pool, inserted_person.id)
|
let after_parent_comment_removed = PersonAggregates::read(pool, inserted_person.id)
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(0, after_parent_comment_removed.comment_count);
|
assert_eq!(0, after_parent_comment_removed.comment_count);
|
||||||
// TODO: fix person aggregate comment score calculation
|
// TODO: fix person aggregate comment score calculation
|
||||||
// assert_eq!(0, after_parent_comment_removed.comment_score);
|
// assert_eq!(0, after_parent_comment_removed.comment_score);
|
||||||
|
|
||||||
// Remove a parent comment (the scores should also be removed)
|
// Remove a parent comment (the scores should also be removed)
|
||||||
Comment::delete(pool, inserted_comment.id).await.unwrap();
|
Comment::delete(pool, inserted_comment.id).await?;
|
||||||
Comment::delete(pool, inserted_child_comment.id)
|
Comment::delete(pool, inserted_child_comment.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let after_parent_comment_delete = PersonAggregates::read(pool, inserted_person.id)
|
let after_parent_comment_delete = PersonAggregates::read(pool, inserted_person.id)
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(0, after_parent_comment_delete.comment_count);
|
assert_eq!(0, after_parent_comment_delete.comment_count);
|
||||||
// TODO: fix person aggregate comment score calculation
|
// TODO: fix person aggregate comment score calculation
|
||||||
// assert_eq!(0, after_parent_comment_delete.comment_score);
|
// assert_eq!(0, after_parent_comment_delete.comment_score);
|
||||||
|
|
||||||
// Add in the two comments again, then delete the post.
|
// Add in the two comments again, then delete the post.
|
||||||
let new_parent_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
let new_parent_comment = Comment::create(pool, &comment_form, None).await?;
|
||||||
let _new_child_comment =
|
let _new_child_comment =
|
||||||
Comment::create(pool, &child_comment_form, Some(&new_parent_comment.path))
|
Comment::create(pool, &child_comment_form, Some(&new_parent_comment.path)).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
comment_like.comment_id = new_parent_comment.id;
|
comment_like.comment_id = new_parent_comment.id;
|
||||||
CommentLike::like(pool, &comment_like).await.unwrap();
|
CommentLike::like(pool, &comment_like).await?;
|
||||||
let after_comment_add = PersonAggregates::read(pool, inserted_person.id)
|
let after_comment_add = PersonAggregates::read(pool, inserted_person.id)
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(2, after_comment_add.comment_count);
|
assert_eq!(2, after_comment_add.comment_count);
|
||||||
// TODO: fix person aggregate comment score calculation
|
// TODO: fix person aggregate comment score calculation
|
||||||
// assert_eq!(1, after_comment_add.comment_score);
|
// assert_eq!(1, after_comment_add.comment_score);
|
||||||
|
|
||||||
Post::delete(pool, inserted_post.id).await.unwrap();
|
Post::delete(pool, inserted_post.id).await?;
|
||||||
let after_post_delete = PersonAggregates::read(pool, inserted_person.id)
|
let after_post_delete = PersonAggregates::read(pool, inserted_person.id)
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// TODO: fix person aggregate comment score calculation
|
// TODO: fix person aggregate comment score calculation
|
||||||
// assert_eq!(0, after_post_delete.comment_score);
|
// assert_eq!(0, after_post_delete.comment_score);
|
||||||
@ -204,24 +187,20 @@ mod tests {
|
|||||||
assert_eq!(0, after_post_delete.post_count);
|
assert_eq!(0, after_post_delete.post_count);
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
let person_num_deleted = Person::delete(pool, inserted_person.id).await.unwrap();
|
let person_num_deleted = Person::delete(pool, inserted_person.id).await?;
|
||||||
assert_eq!(1, person_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
Person::delete(pool, another_inserted_person.id)
|
Person::delete(pool, another_inserted_person.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Delete the community
|
// Delete the community
|
||||||
let community_num_deleted = Community::delete(pool, inserted_community.id)
|
let community_num_deleted = Community::delete(pool, inserted_community.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(1, community_num_deleted);
|
assert_eq!(1, community_num_deleted);
|
||||||
|
|
||||||
// Should be none found
|
// Should be none found
|
||||||
let after_delete = PersonAggregates::read(pool, inserted_person.id)
|
let after_delete = PersonAggregates::read(pool, inserted_person.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert!(after_delete.is_none());
|
assert!(after_delete.is_none());
|
||||||
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,6 @@ impl PostAggregates {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -65,26 +63,25 @@ mod tests {
|
|||||||
traits::{Crud, Likeable},
|
traits::{Crud, Likeable},
|
||||||
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;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 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 new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_community_agg");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_community_agg");
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
let inserted_person = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let another_person = PersonInsertForm::test_form(inserted_instance.id, "jerry_community_agg");
|
let another_person = PersonInsertForm::test_form(inserted_instance.id, "jerry_community_agg");
|
||||||
|
|
||||||
let another_inserted_person = Person::create(pool, &another_person).await.unwrap();
|
let another_inserted_person = Person::create(pool, &another_person).await?;
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -92,21 +89,21 @@ mod tests {
|
|||||||
"nada".to_owned(),
|
"nada".to_owned(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
let new_post = PostInsertForm::new(
|
||||||
"A test post".into(),
|
"A test post".into(),
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
let inserted_post = Post::create(pool, &new_post).await.unwrap();
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::new(
|
let comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"A test comment".into(),
|
"A test comment".into(),
|
||||||
);
|
);
|
||||||
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
let inserted_comment = Comment::create(pool, &comment_form, None).await?;
|
||||||
|
|
||||||
let child_comment_form = CommentInsertForm::new(
|
let child_comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
@ -114,9 +111,7 @@ mod tests {
|
|||||||
"A test comment".into(),
|
"A test comment".into(),
|
||||||
);
|
);
|
||||||
let inserted_child_comment =
|
let inserted_child_comment =
|
||||||
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path))
|
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let post_like = PostLikeForm {
|
let post_like = PostLikeForm {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
@ -124,9 +119,9 @@ mod tests {
|
|||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
PostLike::like(pool, &post_like).await.unwrap();
|
PostLike::like(pool, &post_like).await?;
|
||||||
|
|
||||||
let post_aggs_before_delete = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
let post_aggs_before_delete = PostAggregates::read(pool, inserted_post.id).await?;
|
||||||
|
|
||||||
assert_eq!(2, post_aggs_before_delete.comments);
|
assert_eq!(2, post_aggs_before_delete.comments);
|
||||||
assert_eq!(1, post_aggs_before_delete.score);
|
assert_eq!(1, post_aggs_before_delete.score);
|
||||||
@ -140,9 +135,9 @@ mod tests {
|
|||||||
score: -1,
|
score: -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
PostLike::like(pool, &post_dislike).await.unwrap();
|
PostLike::like(pool, &post_dislike).await?;
|
||||||
|
|
||||||
let post_aggs_after_dislike = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
let post_aggs_after_dislike = PostAggregates::read(pool, inserted_post.id).await?;
|
||||||
|
|
||||||
assert_eq!(2, post_aggs_after_dislike.comments);
|
assert_eq!(2, post_aggs_after_dislike.comments);
|
||||||
assert_eq!(0, post_aggs_after_dislike.score);
|
assert_eq!(0, post_aggs_after_dislike.score);
|
||||||
@ -150,59 +145,51 @@ mod tests {
|
|||||||
assert_eq!(1, post_aggs_after_dislike.downvotes);
|
assert_eq!(1, post_aggs_after_dislike.downvotes);
|
||||||
|
|
||||||
// Remove the comments
|
// Remove the comments
|
||||||
Comment::delete(pool, inserted_comment.id).await.unwrap();
|
Comment::delete(pool, inserted_comment.id).await?;
|
||||||
Comment::delete(pool, inserted_child_comment.id)
|
Comment::delete(pool, inserted_child_comment.id).await?;
|
||||||
.await
|
let after_comment_delete = PostAggregates::read(pool, inserted_post.id).await?;
|
||||||
.unwrap();
|
|
||||||
let after_comment_delete = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
|
||||||
assert_eq!(0, after_comment_delete.comments);
|
assert_eq!(0, after_comment_delete.comments);
|
||||||
assert_eq!(0, after_comment_delete.score);
|
assert_eq!(0, after_comment_delete.score);
|
||||||
assert_eq!(1, after_comment_delete.upvotes);
|
assert_eq!(1, after_comment_delete.upvotes);
|
||||||
assert_eq!(1, after_comment_delete.downvotes);
|
assert_eq!(1, after_comment_delete.downvotes);
|
||||||
|
|
||||||
// Remove the first post like
|
// Remove the first post like
|
||||||
PostLike::remove(pool, inserted_person.id, inserted_post.id)
|
PostLike::remove(pool, inserted_person.id, inserted_post.id).await?;
|
||||||
.await
|
let after_like_remove = PostAggregates::read(pool, inserted_post.id).await?;
|
||||||
.unwrap();
|
|
||||||
let after_like_remove = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
|
||||||
assert_eq!(0, after_like_remove.comments);
|
assert_eq!(0, after_like_remove.comments);
|
||||||
assert_eq!(-1, after_like_remove.score);
|
assert_eq!(-1, after_like_remove.score);
|
||||||
assert_eq!(0, after_like_remove.upvotes);
|
assert_eq!(0, after_like_remove.upvotes);
|
||||||
assert_eq!(1, after_like_remove.downvotes);
|
assert_eq!(1, after_like_remove.downvotes);
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
Person::delete(pool, another_inserted_person.id)
|
Person::delete(pool, another_inserted_person.id).await?;
|
||||||
.await
|
let person_num_deleted = Person::delete(pool, inserted_person.id).await?;
|
||||||
.unwrap();
|
|
||||||
let person_num_deleted = Person::delete(pool, inserted_person.id).await.unwrap();
|
|
||||||
assert_eq!(1, person_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
|
|
||||||
// Delete the community
|
// Delete the community
|
||||||
let community_num_deleted = Community::delete(pool, inserted_community.id)
|
let community_num_deleted = Community::delete(pool, inserted_community.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(1, community_num_deleted);
|
assert_eq!(1, community_num_deleted);
|
||||||
|
|
||||||
// Should be none found, since the creator was deleted
|
// Should be none found, since the creator was deleted
|
||||||
let after_delete = PostAggregates::read(pool, inserted_post.id).await;
|
let after_delete = PostAggregates::read(pool, inserted_post.id).await;
|
||||||
assert!(after_delete.is_err());
|
assert!(after_delete.is_err());
|
||||||
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_soft_delete() {
|
async fn test_soft_delete() -> 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 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 new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_community_agg");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_community_agg");
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
let inserted_person = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -210,14 +197,14 @@ mod tests {
|
|||||||
"nada".to_owned(),
|
"nada".to_owned(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
let new_post = PostInsertForm::new(
|
||||||
"A test post".into(),
|
"A test post".into(),
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
let inserted_post = Post::create(pool, &new_post).await.unwrap();
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::new(
|
let comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
@ -225,9 +212,9 @@ mod tests {
|
|||||||
"A test comment".into(),
|
"A test comment".into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
let inserted_comment = Comment::create(pool, &comment_form, None).await?;
|
||||||
|
|
||||||
let post_aggregates_before = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
let post_aggregates_before = PostAggregates::read(pool, inserted_post.id).await?;
|
||||||
assert_eq!(1, post_aggregates_before.comments);
|
assert_eq!(1, post_aggregates_before.comments);
|
||||||
|
|
||||||
Comment::update(
|
Comment::update(
|
||||||
@ -238,10 +225,9 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let post_aggregates_after_remove = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
let post_aggregates_after_remove = PostAggregates::read(pool, inserted_post.id).await?;
|
||||||
assert_eq!(0, post_aggregates_after_remove.comments);
|
assert_eq!(0, post_aggregates_after_remove.comments);
|
||||||
|
|
||||||
Comment::update(
|
Comment::update(
|
||||||
@ -252,8 +238,7 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Comment::update(
|
Comment::update(
|
||||||
pool,
|
pool,
|
||||||
@ -263,10 +248,9 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let post_aggregates_after_delete = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
let post_aggregates_after_delete = PostAggregates::read(pool, inserted_post.id).await?;
|
||||||
assert_eq!(0, post_aggregates_after_delete.comments);
|
assert_eq!(0, post_aggregates_after_delete.comments);
|
||||||
|
|
||||||
Comment::update(
|
Comment::update(
|
||||||
@ -277,19 +261,17 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let post_aggregates_after_delete_remove =
|
let post_aggregates_after_delete_remove = PostAggregates::read(pool, inserted_post.id).await?;
|
||||||
PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
|
||||||
assert_eq!(0, post_aggregates_after_delete_remove.comments);
|
assert_eq!(0, post_aggregates_after_delete_remove.comments);
|
||||||
|
|
||||||
Comment::delete(pool, inserted_comment.id).await.unwrap();
|
Comment::delete(pool, inserted_comment.id).await?;
|
||||||
Post::delete(pool, inserted_post.id).await.unwrap();
|
Post::delete(pool, inserted_post.id).await?;
|
||||||
Person::delete(pool, inserted_person.id).await.unwrap();
|
Person::delete(pool, inserted_person.id).await?;
|
||||||
Community::delete(pool, inserted_community.id)
|
Community::delete(pool, inserted_community.id).await?;
|
||||||
.await
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
.unwrap();
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,22 +32,21 @@ mod tests {
|
|||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{build_db_pool_for_tests, DbPool},
|
utils::{build_db_pool_for_tests, DbPool},
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
async fn prepare_site_with_community(
|
async fn prepare_site_with_community(
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
) -> (Instance, Person, Site, Community) {
|
) -> LemmyResult<(Instance, Person, Site, Community)> {
|
||||||
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 new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_site_agg");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_site_agg");
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
let inserted_person = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let site_form = SiteInsertForm::new("test_site".into(), inserted_instance.id);
|
let site_form = SiteInsertForm::new("test_site".into(), inserted_instance.id);
|
||||||
let inserted_site = Site::create(pool, &site_form).await.unwrap();
|
let inserted_site = Site::create(pool, &site_form).await?;
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -56,23 +55,24 @@ mod tests {
|
|||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
(
|
|
||||||
|
Ok((
|
||||||
inserted_instance,
|
inserted_instance,
|
||||||
inserted_person,
|
inserted_person,
|
||||||
inserted_site,
|
inserted_site,
|
||||||
inserted_community,
|
inserted_community,
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 (inserted_instance, inserted_person, inserted_site, inserted_community) =
|
let (inserted_instance, inserted_person, inserted_site, inserted_community) =
|
||||||
prepare_site_with_community(pool).await;
|
prepare_site_with_community(pool).await?;
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
let new_post = PostInsertForm::new(
|
||||||
"A test post".into(),
|
"A test post".into(),
|
||||||
@ -81,8 +81,8 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Insert two of those posts
|
// Insert two of those posts
|
||||||
let inserted_post = Post::create(pool, &new_post).await.unwrap();
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
let _inserted_post_again = Post::create(pool, &new_post).await.unwrap();
|
let _inserted_post_again = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::new(
|
let comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
@ -91,7 +91,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Insert two of those comments
|
// Insert two of those comments
|
||||||
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
let inserted_comment = Comment::create(pool, &comment_form, None).await?;
|
||||||
|
|
||||||
let child_comment_form = CommentInsertForm::new(
|
let child_comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
@ -99,11 +99,9 @@ mod tests {
|
|||||||
"A test comment".into(),
|
"A test comment".into(),
|
||||||
);
|
);
|
||||||
let _inserted_child_comment =
|
let _inserted_child_comment =
|
||||||
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path))
|
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let site_aggregates_before_delete = SiteAggregates::read(pool).await.unwrap().unwrap();
|
let site_aggregates_before_delete = SiteAggregates::read(pool).await?.unwrap();
|
||||||
|
|
||||||
// TODO: this is unstable, sometimes it returns 0 users, sometimes 1
|
// TODO: this is unstable, sometimes it returns 0 users, sometimes 1
|
||||||
//assert_eq!(0, site_aggregates_before_delete.users);
|
//assert_eq!(0, site_aggregates_before_delete.users);
|
||||||
@ -112,42 +110,42 @@ mod tests {
|
|||||||
assert_eq!(2, site_aggregates_before_delete.comments);
|
assert_eq!(2, site_aggregates_before_delete.comments);
|
||||||
|
|
||||||
// Try a post delete
|
// Try a post delete
|
||||||
Post::delete(pool, inserted_post.id).await.unwrap();
|
Post::delete(pool, inserted_post.id).await?;
|
||||||
let site_aggregates_after_post_delete = SiteAggregates::read(pool).await.unwrap().unwrap();
|
let site_aggregates_after_post_delete = SiteAggregates::read(pool).await?.unwrap();
|
||||||
assert_eq!(1, site_aggregates_after_post_delete.posts);
|
assert_eq!(1, site_aggregates_after_post_delete.posts);
|
||||||
assert_eq!(0, site_aggregates_after_post_delete.comments);
|
assert_eq!(0, site_aggregates_after_post_delete.comments);
|
||||||
|
|
||||||
// This shouuld delete all the associated rows, and fire triggers
|
// This shouuld delete all the associated rows, and fire triggers
|
||||||
let person_num_deleted = Person::delete(pool, inserted_person.id).await.unwrap();
|
let person_num_deleted = Person::delete(pool, inserted_person.id).await?;
|
||||||
assert_eq!(1, person_num_deleted);
|
assert_eq!(1, person_num_deleted);
|
||||||
|
|
||||||
// Delete the community
|
// Delete the community
|
||||||
let community_num_deleted = Community::delete(pool, inserted_community.id)
|
let community_num_deleted = Community::delete(pool, inserted_community.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(1, community_num_deleted);
|
assert_eq!(1, community_num_deleted);
|
||||||
|
|
||||||
// Site should still exist, it can without a site creator.
|
// Site should still exist, it can without a site creator.
|
||||||
let after_delete_creator = SiteAggregates::read(pool).await;
|
let after_delete_creator = SiteAggregates::read(pool).await;
|
||||||
assert!(after_delete_creator.is_ok());
|
assert!(after_delete_creator.is_ok());
|
||||||
|
|
||||||
Site::delete(pool, inserted_site.id).await.unwrap();
|
Site::delete(pool, inserted_site.id).await?;
|
||||||
let after_delete_site = SiteAggregates::read(pool).await.unwrap();
|
let after_delete_site = SiteAggregates::read(pool).await?;
|
||||||
assert!(after_delete_site.is_none());
|
assert!(after_delete_site.is_none());
|
||||||
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_soft_delete() {
|
async fn test_soft_delete() -> 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 (inserted_instance, inserted_person, inserted_site, inserted_community) =
|
let (inserted_instance, inserted_person, inserted_site, inserted_community) =
|
||||||
prepare_site_with_community(pool).await;
|
prepare_site_with_community(pool).await?;
|
||||||
|
|
||||||
let site_aggregates_before = SiteAggregates::read(pool).await.unwrap().unwrap();
|
let site_aggregates_before = SiteAggregates::read(pool).await?.unwrap();
|
||||||
assert_eq!(1, site_aggregates_before.communities);
|
assert_eq!(1, site_aggregates_before.communities);
|
||||||
|
|
||||||
Community::update(
|
Community::update(
|
||||||
@ -158,10 +156,9 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let site_aggregates_after_delete = SiteAggregates::read(pool).await.unwrap().unwrap();
|
let site_aggregates_after_delete = SiteAggregates::read(pool).await?.unwrap();
|
||||||
assert_eq!(0, site_aggregates_after_delete.communities);
|
assert_eq!(0, site_aggregates_after_delete.communities);
|
||||||
|
|
||||||
Community::update(
|
Community::update(
|
||||||
@ -172,8 +169,7 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Community::update(
|
Community::update(
|
||||||
pool,
|
pool,
|
||||||
@ -183,10 +179,9 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let site_aggregates_after_remove = SiteAggregates::read(pool).await.unwrap().unwrap();
|
let site_aggregates_after_remove = SiteAggregates::read(pool).await?.unwrap();
|
||||||
assert_eq!(0, site_aggregates_after_remove.communities);
|
assert_eq!(0, site_aggregates_after_remove.communities);
|
||||||
|
|
||||||
Community::update(
|
Community::update(
|
||||||
@ -197,17 +192,16 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let site_aggregates_after_remove_delete = SiteAggregates::read(pool).await.unwrap().unwrap();
|
let site_aggregates_after_remove_delete = SiteAggregates::read(pool).await?.unwrap();
|
||||||
assert_eq!(0, site_aggregates_after_remove_delete.communities);
|
assert_eq!(0, site_aggregates_after_remove_delete.communities);
|
||||||
|
|
||||||
Community::delete(pool, inserted_community.id)
|
Community::delete(pool, inserted_community.id).await?;
|
||||||
.await
|
Site::delete(pool, inserted_site.id).await?;
|
||||||
.unwrap();
|
Person::delete(pool, inserted_person.id).await?;
|
||||||
Site::delete(pool, inserted_site.id).await.unwrap();
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
Person::delete(pool, inserted_person.id).await.unwrap();
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,7 @@ mod tests {
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{source::activity::ActorType, utils::build_db_pool_for_tests};
|
use crate::{source::activity::ActorType, utils::build_db_pool_for_tests};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
@ -70,26 +71,24 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn receive_activity_duplicate() {
|
async fn receive_activity_duplicate() -> 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 ap_id: DbUrl = Url::parse("http://example.com/activity/531")
|
let ap_id: DbUrl = Url::parse("http://example.com/activity/531")?.into();
|
||||||
.unwrap()
|
|
||||||
.into();
|
|
||||||
|
|
||||||
// inserting activity should only work once
|
// inserting activity should only work once
|
||||||
ReceivedActivity::create(pool, &ap_id).await.unwrap();
|
ReceivedActivity::create(pool, &ap_id).await?;
|
||||||
ReceivedActivity::create(pool, &ap_id).await.unwrap_err();
|
ReceivedActivity::create(pool, &ap_id).await.unwrap_err();
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn sent_activity_write_read() {
|
async fn sent_activity_write_read() -> 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 ap_id: DbUrl = Url::parse("http://example.com/activity/412")
|
let ap_id: DbUrl = Url::parse("http://example.com/activity/412")?.into();
|
||||||
.unwrap()
|
|
||||||
.into();
|
|
||||||
let data = json!({
|
let data = json!({
|
||||||
"key1": "0xF9BA143B95FF6D82",
|
"key1": "0xF9BA143B95FF6D82",
|
||||||
"key2": "42",
|
"key2": "42",
|
||||||
@ -100,20 +99,20 @@ mod tests {
|
|||||||
ap_id: ap_id.clone(),
|
ap_id: ap_id.clone(),
|
||||||
data: data.clone(),
|
data: data.clone(),
|
||||||
sensitive,
|
sensitive,
|
||||||
actor_apub_id: Url::parse("http://example.com/u/exampleuser")
|
actor_apub_id: Url::parse("http://example.com/u/exampleuser")?.into(),
|
||||||
.unwrap()
|
|
||||||
.into(),
|
|
||||||
actor_type: ActorType::Person,
|
actor_type: ActorType::Person,
|
||||||
send_all_instances: false,
|
send_all_instances: false,
|
||||||
send_community_followers_of: None,
|
send_community_followers_of: None,
|
||||||
send_inboxes: vec![],
|
send_inboxes: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
SentActivity::create(pool, form).await.unwrap();
|
SentActivity::create(pool, form).await?;
|
||||||
|
|
||||||
let res = SentActivity::read_from_apub_id(pool, &ap_id).await.unwrap();
|
let res = SentActivity::read_from_apub_id(pool, &ap_id).await?;
|
||||||
assert_eq!(res.ap_id, ap_id);
|
assert_eq!(res.ap_id, ap_id);
|
||||||
assert_eq!(res.data, data);
|
assert_eq!(res.data, data);
|
||||||
assert_eq!(res.sensitive, sensitive);
|
assert_eq!(res.sensitive, sensitive);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -412,165 +412,154 @@ mod tests {
|
|||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
async fn test_langs1(pool: &mut DbPool<'_>) -> Vec<LanguageId> {
|
async fn test_langs1(pool: &mut DbPool<'_>) -> LemmyResult<Vec<LanguageId>> {
|
||||||
vec![
|
Ok(vec![
|
||||||
Language::read_id_from_code(pool, Some("en"))
|
Language::read_id_from_code(pool, Some("en"))
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Language::read_id_from_code(pool, Some("fr"))
|
Language::read_id_from_code(pool, Some("fr"))
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Language::read_id_from_code(pool, Some("ru"))
|
Language::read_id_from_code(pool, Some("ru"))
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
]
|
])
|
||||||
}
|
}
|
||||||
async fn test_langs2(pool: &mut DbPool<'_>) -> Vec<LanguageId> {
|
async fn test_langs2(pool: &mut DbPool<'_>) -> LemmyResult<Vec<LanguageId>> {
|
||||||
vec![
|
Ok(vec![
|
||||||
Language::read_id_from_code(pool, Some("fi"))
|
Language::read_id_from_code(pool, Some("fi"))
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Language::read_id_from_code(pool, Some("se"))
|
Language::read_id_from_code(pool, Some("se"))
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
]
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_test_site(pool: &mut DbPool<'_>) -> (Site, Instance) {
|
async fn create_test_site(pool: &mut DbPool<'_>) -> LemmyResult<(Site, Instance)> {
|
||||||
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 site_form = SiteInsertForm::new("test site".to_string(), inserted_instance.id);
|
let site_form = SiteInsertForm::new("test site".to_string(), inserted_instance.id);
|
||||||
let site = Site::create(pool, &site_form).await.unwrap();
|
let site = Site::create(pool, &site_form).await?;
|
||||||
|
|
||||||
// Create a local site, since this is necessary for local languages
|
// Create a local site, since this is necessary for local languages
|
||||||
let local_site_form = LocalSiteInsertForm::new(site.id);
|
let local_site_form = LocalSiteInsertForm::new(site.id);
|
||||||
LocalSite::create(pool, &local_site_form).await.unwrap();
|
LocalSite::create(pool, &local_site_form).await?;
|
||||||
|
|
||||||
(site, inserted_instance)
|
Ok((site, inserted_instance))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_convert_update_languages() {
|
async fn test_convert_update_languages() -> 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();
|
||||||
|
|
||||||
// call with empty vec, returns all languages
|
// call with empty vec, returns all languages
|
||||||
let conn = &mut get_conn(pool).await.unwrap();
|
let conn = &mut get_conn(pool).await?;
|
||||||
let converted1 = convert_update_languages(conn, vec![]).await.unwrap();
|
let converted1 = convert_update_languages(conn, vec![]).await?;
|
||||||
assert_eq!(184, converted1.len());
|
assert_eq!(184, converted1.len());
|
||||||
|
|
||||||
// call with nonempty vec, returns same vec
|
// call with nonempty vec, returns same vec
|
||||||
let test_langs = test_langs1(&mut conn.into()).await;
|
let test_langs = test_langs1(&mut conn.into()).await?;
|
||||||
let converted2 = convert_update_languages(conn, test_langs.clone())
|
let converted2 = convert_update_languages(conn, test_langs.clone()).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(test_langs, converted2);
|
assert_eq!(test_langs, converted2);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_convert_read_languages() {
|
async fn test_convert_read_languages() -> LemmyResult<()> {
|
||||||
use crate::schema::language::dsl::{id, language};
|
use crate::schema::language::dsl::{id, language};
|
||||||
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();
|
||||||
|
|
||||||
// call with all languages, returns empty vec
|
// call with all languages, returns empty vec
|
||||||
let conn = &mut get_conn(pool).await.unwrap();
|
let conn = &mut get_conn(pool).await?;
|
||||||
let all_langs = language.select(id).get_results(conn).await.unwrap();
|
let all_langs = language.select(id).get_results(conn).await?;
|
||||||
let converted1: Vec<LanguageId> = convert_read_languages(conn, all_langs).await.unwrap();
|
let converted1: Vec<LanguageId> = convert_read_languages(conn, all_langs).await?;
|
||||||
assert_eq!(0, converted1.len());
|
assert_eq!(0, converted1.len());
|
||||||
|
|
||||||
// call with nonempty vec, returns same vec
|
// call with nonempty vec, returns same vec
|
||||||
let test_langs = test_langs1(&mut conn.into()).await;
|
let test_langs = test_langs1(&mut conn.into()).await?;
|
||||||
let converted2 = convert_read_languages(conn, test_langs.clone())
|
let converted2 = convert_read_languages(conn, test_langs.clone()).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(test_langs, converted2);
|
assert_eq!(test_langs, converted2);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_site_languages() {
|
async fn test_site_languages() -> 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 (site, instance) = create_test_site(pool).await;
|
let (site, instance) = create_test_site(pool).await?;
|
||||||
let site_languages1 = SiteLanguage::read_local_raw(pool).await.unwrap();
|
let site_languages1 = SiteLanguage::read_local_raw(pool).await?;
|
||||||
// site is created with all languages
|
// site is created with all languages
|
||||||
assert_eq!(184, site_languages1.len());
|
assert_eq!(184, site_languages1.len());
|
||||||
|
|
||||||
let test_langs = test_langs1(pool).await;
|
let test_langs = test_langs1(pool).await?;
|
||||||
SiteLanguage::update(pool, test_langs.clone(), &site)
|
SiteLanguage::update(pool, test_langs.clone(), &site).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let site_languages2 = SiteLanguage::read_local_raw(pool).await.unwrap();
|
let site_languages2 = SiteLanguage::read_local_raw(pool).await?;
|
||||||
// after update, site only has new languages
|
// after update, site only has new languages
|
||||||
assert_eq!(test_langs, site_languages2);
|
assert_eq!(test_langs, site_languages2);
|
||||||
|
|
||||||
Site::delete(pool, site.id).await.unwrap();
|
Site::delete(pool, site.id).await?;
|
||||||
Instance::delete(pool, instance.id).await.unwrap();
|
Instance::delete(pool, instance.id).await?;
|
||||||
LocalSite::delete(pool).await.unwrap();
|
LocalSite::delete(pool).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_user_languages() {
|
async fn test_user_languages() -> 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 (site, instance) = create_test_site(pool).await;
|
let (site, instance) = create_test_site(pool).await?;
|
||||||
|
|
||||||
let person_form = PersonInsertForm::test_form(instance.id, "my test person");
|
let person_form = PersonInsertForm::test_form(instance.id, "my test person");
|
||||||
let person = Person::create(pool, &person_form).await.unwrap();
|
let person = Person::create(pool, &person_form).await?;
|
||||||
let local_user_form = LocalUserInsertForm::test_form(person.id);
|
let local_user_form = LocalUserInsertForm::test_form(person.id);
|
||||||
|
|
||||||
let local_user = LocalUser::create(pool, &local_user_form, vec![])
|
let local_user = LocalUser::create(pool, &local_user_form, vec![]).await?;
|
||||||
.await
|
let local_user_langs1 = LocalUserLanguage::read(pool, local_user.id).await?;
|
||||||
.unwrap();
|
|
||||||
let local_user_langs1 = LocalUserLanguage::read(pool, local_user.id).await.unwrap();
|
|
||||||
|
|
||||||
// new user should be initialized with all languages
|
// new user should be initialized with all languages
|
||||||
assert_eq!(0, local_user_langs1.len());
|
assert_eq!(0, local_user_langs1.len());
|
||||||
|
|
||||||
// update user languages
|
// update user languages
|
||||||
let test_langs2 = test_langs2(pool).await;
|
let test_langs2 = test_langs2(pool).await?;
|
||||||
LocalUserLanguage::update(pool, test_langs2, local_user.id)
|
LocalUserLanguage::update(pool, test_langs2, local_user.id).await?;
|
||||||
.await
|
let local_user_langs2 = LocalUserLanguage::read(pool, local_user.id).await?;
|
||||||
.unwrap();
|
|
||||||
let local_user_langs2 = LocalUserLanguage::read(pool, local_user.id).await.unwrap();
|
|
||||||
assert_eq!(3, local_user_langs2.len());
|
assert_eq!(3, local_user_langs2.len());
|
||||||
|
|
||||||
Person::delete(pool, person.id).await.unwrap();
|
Person::delete(pool, person.id).await?;
|
||||||
LocalUser::delete(pool, local_user.id).await.unwrap();
|
LocalUser::delete(pool, local_user.id).await?;
|
||||||
Site::delete(pool, site.id).await.unwrap();
|
Site::delete(pool, site.id).await?;
|
||||||
LocalSite::delete(pool).await.unwrap();
|
LocalSite::delete(pool).await?;
|
||||||
Instance::delete(pool, instance.id).await.unwrap();
|
Instance::delete(pool, instance.id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_community_languages() {
|
async fn test_community_languages() -> 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 (site, instance) = create_test_site(pool).await;
|
let (site, instance) = create_test_site(pool).await?;
|
||||||
let test_langs = test_langs1(pool).await;
|
let test_langs = test_langs1(pool).await?;
|
||||||
SiteLanguage::update(pool, test_langs.clone(), &site)
|
SiteLanguage::update(pool, test_langs.clone(), &site).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let read_site_langs = SiteLanguage::read(pool, site.id).await.unwrap();
|
let read_site_langs = SiteLanguage::read(pool, site.id).await?;
|
||||||
assert_eq!(test_langs, read_site_langs);
|
assert_eq!(test_langs, read_site_langs);
|
||||||
|
|
||||||
// Test the local ones are the same
|
// Test the local ones are the same
|
||||||
let read_local_site_langs = SiteLanguage::read_local_raw(pool).await.unwrap();
|
let read_local_site_langs = SiteLanguage::read_local_raw(pool).await?;
|
||||||
assert_eq!(test_langs, read_local_site_langs);
|
assert_eq!(test_langs, read_local_site_langs);
|
||||||
|
|
||||||
let community_form = CommunityInsertForm::new(
|
let community_form = CommunityInsertForm::new(
|
||||||
@ -579,8 +568,8 @@ mod tests {
|
|||||||
"test community".to_string(),
|
"test community".to_string(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let community = Community::create(pool, &community_form).await.unwrap();
|
let community = Community::create(pool, &community_form).await?;
|
||||||
let community_langs1 = CommunityLanguage::read(pool, community.id).await.unwrap();
|
let community_langs1 = CommunityLanguage::read(pool, community.id).await?;
|
||||||
|
|
||||||
// community is initialized with site languages
|
// community is initialized with site languages
|
||||||
assert_eq!(test_langs, community_langs1);
|
assert_eq!(test_langs, community_langs1);
|
||||||
@ -590,7 +579,7 @@ mod tests {
|
|||||||
.await;
|
.await;
|
||||||
assert!(allowed_lang1.is_ok());
|
assert!(allowed_lang1.is_ok());
|
||||||
|
|
||||||
let test_langs2 = test_langs2(pool).await;
|
let test_langs2 = test_langs2(pool).await?;
|
||||||
let allowed_lang2 =
|
let allowed_lang2 =
|
||||||
CommunityLanguage::is_allowed_community_language(pool, Some(test_langs2[0]), community.id)
|
CommunityLanguage::is_allowed_community_language(pool, Some(test_langs2[0]), community.id)
|
||||||
.await;
|
.await;
|
||||||
@ -598,33 +587,31 @@ mod tests {
|
|||||||
|
|
||||||
// limit site languages to en, fi. after this, community languages should be updated to
|
// limit site languages to en, fi. after this, community languages should be updated to
|
||||||
// intersection of old languages (en, fr, ru) and (en, fi), which is only fi.
|
// intersection of old languages (en, fr, ru) and (en, fi), which is only fi.
|
||||||
SiteLanguage::update(pool, vec![test_langs[0], test_langs2[0]], &site)
|
SiteLanguage::update(pool, vec![test_langs[0], test_langs2[0]], &site).await?;
|
||||||
.await
|
let community_langs2 = CommunityLanguage::read(pool, community.id).await?;
|
||||||
.unwrap();
|
|
||||||
let community_langs2 = CommunityLanguage::read(pool, community.id).await.unwrap();
|
|
||||||
assert_eq!(vec![test_langs[0]], community_langs2);
|
assert_eq!(vec![test_langs[0]], community_langs2);
|
||||||
|
|
||||||
// update community languages to different ones
|
// update community languages to different ones
|
||||||
CommunityLanguage::update(pool, test_langs2.clone(), community.id)
|
CommunityLanguage::update(pool, test_langs2.clone(), community.id).await?;
|
||||||
.await
|
let community_langs3 = CommunityLanguage::read(pool, community.id).await?;
|
||||||
.unwrap();
|
|
||||||
let community_langs3 = CommunityLanguage::read(pool, community.id).await.unwrap();
|
|
||||||
assert_eq!(test_langs2, community_langs3);
|
assert_eq!(test_langs2, community_langs3);
|
||||||
|
|
||||||
Community::delete(pool, community.id).await.unwrap();
|
Community::delete(pool, community.id).await?;
|
||||||
Site::delete(pool, site.id).await.unwrap();
|
Site::delete(pool, site.id).await?;
|
||||||
LocalSite::delete(pool).await.unwrap();
|
LocalSite::delete(pool).await?;
|
||||||
Instance::delete(pool, instance.id).await.unwrap();
|
Instance::delete(pool, instance.id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_default_post_language() {
|
async fn test_default_post_language() -> 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 (site, instance) = create_test_site(pool).await;
|
let (site, instance) = create_test_site(pool).await?;
|
||||||
let test_langs = test_langs1(pool).await;
|
let test_langs = test_langs1(pool).await?;
|
||||||
let test_langs2 = test_langs2(pool).await;
|
let test_langs2 = test_langs2(pool).await?;
|
||||||
|
|
||||||
let community_form = CommunityInsertForm::new(
|
let community_form = CommunityInsertForm::new(
|
||||||
instance.id,
|
instance.id,
|
||||||
@ -632,58 +619,45 @@ mod tests {
|
|||||||
"test community".to_string(),
|
"test community".to_string(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let community = Community::create(pool, &community_form).await.unwrap();
|
let community = Community::create(pool, &community_form).await?;
|
||||||
CommunityLanguage::update(pool, test_langs, community.id)
|
CommunityLanguage::update(pool, test_langs, community.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let person_form = PersonInsertForm::test_form(instance.id, "my test person");
|
let person_form = PersonInsertForm::test_form(instance.id, "my test person");
|
||||||
let person = Person::create(pool, &person_form).await.unwrap();
|
let person = Person::create(pool, &person_form).await?;
|
||||||
let local_user_form = LocalUserInsertForm::test_form(person.id);
|
let local_user_form = LocalUserInsertForm::test_form(person.id);
|
||||||
let local_user = LocalUser::create(pool, &local_user_form, vec![])
|
let local_user = LocalUser::create(pool, &local_user_form, vec![]).await?;
|
||||||
.await
|
LocalUserLanguage::update(pool, test_langs2, local_user.id).await?;
|
||||||
.unwrap();
|
|
||||||
LocalUserLanguage::update(pool, test_langs2, local_user.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// no overlap in user/community languages, so defaults to undetermined
|
// no overlap in user/community languages, so defaults to undetermined
|
||||||
let def1 = default_post_language(pool, community.id, local_user.id)
|
let def1 = default_post_language(pool, community.id, local_user.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(None, def1);
|
assert_eq!(None, def1);
|
||||||
|
|
||||||
let ru = Language::read_id_from_code(pool, Some("ru"))
|
let ru = Language::read_id_from_code(pool, Some("ru"))
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let test_langs3 = vec![
|
let test_langs3 = vec![
|
||||||
ru,
|
ru,
|
||||||
Language::read_id_from_code(pool, Some("fi"))
|
Language::read_id_from_code(pool, Some("fi"))
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
Language::read_id_from_code(pool, Some("se"))
|
Language::read_id_from_code(pool, Some("se"))
|
||||||
.await
|
.await?
|
||||||
.unwrap()
|
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
UNDETERMINED_ID,
|
UNDETERMINED_ID,
|
||||||
];
|
];
|
||||||
LocalUserLanguage::update(pool, test_langs3, local_user.id)
|
LocalUserLanguage::update(pool, test_langs3, local_user.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// this time, both have ru as common lang
|
// this time, both have ru as common lang
|
||||||
let def2 = default_post_language(pool, community.id, local_user.id)
|
let def2 = default_post_language(pool, community.id, local_user.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(Some(ru), def2);
|
assert_eq!(Some(ru), def2);
|
||||||
|
|
||||||
Person::delete(pool, person.id).await.unwrap();
|
Person::delete(pool, person.id).await?;
|
||||||
Community::delete(pool, community.id).await.unwrap();
|
Community::delete(pool, community.id).await?;
|
||||||
LocalUser::delete(pool, local_user.id).await.unwrap();
|
LocalUser::delete(pool, local_user.id).await?;
|
||||||
Site::delete(pool, site.id).await.unwrap();
|
Site::delete(pool, site.id).await?;
|
||||||
LocalSite::delete(pool).await.unwrap();
|
LocalSite::delete(pool).await?;
|
||||||
Instance::delete(pool, instance.id).await.unwrap();
|
Instance::delete(pool, instance.id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,6 @@ impl Saveable for CommentSaved {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -220,23 +219,22 @@ mod tests {
|
|||||||
utils::build_db_pool_for_tests,
|
utils::build_db_pool_for_tests,
|
||||||
};
|
};
|
||||||
use diesel_ltree::Ltree;
|
use diesel_ltree::Ltree;
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 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 new_person = PersonInsertForm::test_form(inserted_instance.id, "terry");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "terry");
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
let inserted_person = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -244,21 +242,21 @@ mod tests {
|
|||||||
"nada".to_owned(),
|
"nada".to_owned(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
let new_post = PostInsertForm::new(
|
||||||
"A test post".into(),
|
"A test post".into(),
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
let inserted_post = Post::create(pool, &new_post).await.unwrap();
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::new(
|
let comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"A test comment".into(),
|
"A test comment".into(),
|
||||||
);
|
);
|
||||||
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
let inserted_comment = Comment::create(pool, &comment_form, None).await?;
|
||||||
|
|
||||||
let expected_comment = Comment {
|
let expected_comment = Comment {
|
||||||
id: inserted_comment.id,
|
id: inserted_comment.id,
|
||||||
@ -273,8 +271,7 @@ mod tests {
|
|||||||
ap_id: Url::parse(&format!(
|
ap_id: Url::parse(&format!(
|
||||||
"https://lemmy-alpha/comment/{}",
|
"https://lemmy-alpha/comment/{}",
|
||||||
inserted_comment.id
|
inserted_comment.id
|
||||||
))
|
))?
|
||||||
.unwrap()
|
|
||||||
.into(),
|
.into(),
|
||||||
distinguished: false,
|
distinguished: false,
|
||||||
local: true,
|
local: true,
|
||||||
@ -287,9 +284,7 @@ mod tests {
|
|||||||
"A child comment".into(),
|
"A child comment".into(),
|
||||||
);
|
);
|
||||||
let inserted_child_comment =
|
let inserted_child_comment =
|
||||||
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path))
|
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Comment Like
|
// Comment Like
|
||||||
let comment_like_form = CommentLikeForm {
|
let comment_like_form = CommentLikeForm {
|
||||||
@ -299,7 +294,7 @@ mod tests {
|
|||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_comment_like = CommentLike::like(pool, &comment_like_form).await.unwrap();
|
let inserted_comment_like = CommentLike::like(pool, &comment_like_form).await?;
|
||||||
|
|
||||||
let expected_comment_like = CommentLike {
|
let expected_comment_like = CommentLike {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
@ -315,7 +310,7 @@ mod tests {
|
|||||||
person_id: inserted_person.id,
|
person_id: inserted_person.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_comment_saved = CommentSaved::save(pool, &comment_saved_form).await.unwrap();
|
let inserted_comment_saved = CommentSaved::save(pool, &comment_saved_form).await?;
|
||||||
|
|
||||||
let expected_comment_saved = CommentSaved {
|
let expected_comment_saved = CommentSaved {
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
@ -328,27 +323,17 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let updated_comment = Comment::update(pool, inserted_comment.id, &comment_update_form)
|
let updated_comment = Comment::update(pool, inserted_comment.id, &comment_update_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let read_comment = Comment::read(pool, inserted_comment.id).await.unwrap();
|
let read_comment = Comment::read(pool, inserted_comment.id).await?;
|
||||||
let like_removed = CommentLike::remove(pool, inserted_person.id, inserted_comment.id)
|
let like_removed = CommentLike::remove(pool, inserted_person.id, inserted_comment.id).await?;
|
||||||
.await
|
let saved_removed = CommentSaved::unsave(pool, &comment_saved_form).await?;
|
||||||
.unwrap();
|
let num_deleted = Comment::delete(pool, inserted_comment.id).await?;
|
||||||
let saved_removed = CommentSaved::unsave(pool, &comment_saved_form)
|
Comment::delete(pool, inserted_child_comment.id).await?;
|
||||||
.await
|
Post::delete(pool, inserted_post.id).await?;
|
||||||
.unwrap();
|
Community::delete(pool, inserted_community.id).await?;
|
||||||
let num_deleted = Comment::delete(pool, inserted_comment.id).await.unwrap();
|
Person::delete(pool, inserted_person.id).await?;
|
||||||
Comment::delete(pool, inserted_child_comment.id)
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
Post::delete(pool, inserted_post.id).await.unwrap();
|
|
||||||
Community::delete(pool, inserted_community.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
Person::delete(pool, inserted_person.id).await.unwrap();
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(expected_comment, read_comment);
|
assert_eq!(expected_comment, read_comment);
|
||||||
assert_eq!(expected_comment, inserted_comment);
|
assert_eq!(expected_comment, inserted_comment);
|
||||||
@ -362,5 +347,7 @@ mod tests {
|
|||||||
assert_eq!(1, like_removed);
|
assert_eq!(1, like_removed);
|
||||||
assert_eq!(1, saved_removed);
|
assert_eq!(1, saved_removed);
|
||||||
assert_eq!(1, num_deleted);
|
assert_eq!(1, num_deleted);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,19 +48,19 @@ impl FederationAllowList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
source::{federation_allowlist::FederationAllowList, instance::Instance},
|
source::{federation_allowlist::FederationAllowList, instance::Instance},
|
||||||
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;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_allowlist_insert_and_clear() {
|
async fn test_allowlist_insert_and_clear() -> 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 domains = vec![
|
let domains = vec![
|
||||||
@ -71,9 +71,9 @@ mod tests {
|
|||||||
|
|
||||||
let allowed = Some(domains.clone());
|
let allowed = Some(domains.clone());
|
||||||
|
|
||||||
FederationAllowList::replace(pool, allowed).await.unwrap();
|
FederationAllowList::replace(pool, allowed).await?;
|
||||||
|
|
||||||
let allows = Instance::allowlist(pool).await.unwrap();
|
let allows = Instance::allowlist(pool).await?;
|
||||||
let allows_domains = allows
|
let allows_domains = allows
|
||||||
.iter()
|
.iter()
|
||||||
.map(|i| i.domain.clone())
|
.map(|i| i.domain.clone())
|
||||||
@ -85,13 +85,13 @@ mod tests {
|
|||||||
// Now test clearing them via Some(empty vec)
|
// Now test clearing them via Some(empty vec)
|
||||||
let clear_allows = Some(Vec::new());
|
let clear_allows = Some(Vec::new());
|
||||||
|
|
||||||
FederationAllowList::replace(pool, clear_allows)
|
FederationAllowList::replace(pool, clear_allows).await?;
|
||||||
.await
|
let allows = Instance::allowlist(pool).await?;
|
||||||
.unwrap();
|
|
||||||
let allows = Instance::allowlist(pool).await.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(0, allows.len());
|
assert_eq!(0, allows.len());
|
||||||
|
|
||||||
Instance::delete_all(pool).await.unwrap();
|
Instance::delete_all(pool).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,25 +41,27 @@ impl Language {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
#[expect(clippy::indexing_slicing)]
|
#[expect(clippy::indexing_slicing)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::{source::language::Language, utils::build_db_pool_for_tests};
|
use crate::{source::language::Language, 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;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_languages() {
|
async fn test_languages() -> 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 all = Language::read_all(pool).await.unwrap();
|
let all = Language::read_all(pool).await?;
|
||||||
|
|
||||||
assert_eq!(184, all.len());
|
assert_eq!(184, all.len());
|
||||||
assert_eq!("ak", all[5].code);
|
assert_eq!("ak", all[5].code);
|
||||||
assert_eq!("lv", all[99].code);
|
assert_eq!("lv", all[99].code);
|
||||||
assert_eq!("yi", all[179].code);
|
assert_eq!("yi", all[179].code);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -465,7 +465,6 @@ impl Crud for AdminPurgeComment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -499,26 +498,25 @@ 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;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 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 new_mod = PersonInsertForm::test_form(inserted_instance.id, "the mod");
|
let new_mod = PersonInsertForm::test_form(inserted_instance.id, "the mod");
|
||||||
|
|
||||||
let inserted_mod = Person::create(pool, &new_mod).await.unwrap();
|
let inserted_mod = Person::create(pool, &new_mod).await?;
|
||||||
|
|
||||||
let new_person = PersonInsertForm::test_form(inserted_instance.id, "jim2");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "jim2");
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
let inserted_person = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -527,21 +525,21 @@ mod tests {
|
|||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
let new_post = PostInsertForm::new(
|
||||||
"A test post thweep".into(),
|
"A test post thweep".into(),
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
let inserted_post = Post::create(pool, &new_post).await.unwrap();
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::new(
|
let comment_form = CommentInsertForm::new(
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"A test comment".into(),
|
"A test comment".into(),
|
||||||
);
|
);
|
||||||
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
let inserted_comment = Comment::create(pool, &comment_form, None).await?;
|
||||||
|
|
||||||
// Now the actual tests
|
// Now the actual tests
|
||||||
|
|
||||||
@ -552,12 +550,8 @@ mod tests {
|
|||||||
reason: None,
|
reason: None,
|
||||||
removed: None,
|
removed: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_remove_post = ModRemovePost::create(pool, &mod_remove_post_form)
|
let inserted_mod_remove_post = ModRemovePost::create(pool, &mod_remove_post_form).await?;
|
||||||
.await
|
let read_mod_remove_post = ModRemovePost::read(pool, inserted_mod_remove_post.id).await?;
|
||||||
.unwrap();
|
|
||||||
let read_mod_remove_post = ModRemovePost::read(pool, inserted_mod_remove_post.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let expected_mod_remove_post = ModRemovePost {
|
let expected_mod_remove_post = ModRemovePost {
|
||||||
id: inserted_mod_remove_post.id,
|
id: inserted_mod_remove_post.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
@ -574,12 +568,8 @@ mod tests {
|
|||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
locked: None,
|
locked: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_lock_post = ModLockPost::create(pool, &mod_lock_post_form)
|
let inserted_mod_lock_post = ModLockPost::create(pool, &mod_lock_post_form).await?;
|
||||||
.await
|
let read_mod_lock_post = ModLockPost::read(pool, inserted_mod_lock_post.id).await?;
|
||||||
.unwrap();
|
|
||||||
let read_mod_lock_post = ModLockPost::read(pool, inserted_mod_lock_post.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let expected_mod_lock_post = ModLockPost {
|
let expected_mod_lock_post = ModLockPost {
|
||||||
id: inserted_mod_lock_post.id,
|
id: inserted_mod_lock_post.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
@ -596,12 +586,8 @@ mod tests {
|
|||||||
featured: false,
|
featured: false,
|
||||||
is_featured_community: true,
|
is_featured_community: true,
|
||||||
};
|
};
|
||||||
let inserted_mod_feature_post = ModFeaturePost::create(pool, &mod_feature_post_form)
|
let inserted_mod_feature_post = ModFeaturePost::create(pool, &mod_feature_post_form).await?;
|
||||||
.await
|
let read_mod_feature_post = ModFeaturePost::read(pool, inserted_mod_feature_post.id).await?;
|
||||||
.unwrap();
|
|
||||||
let read_mod_feature_post = ModFeaturePost::read(pool, inserted_mod_feature_post.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let expected_mod_feature_post = ModFeaturePost {
|
let expected_mod_feature_post = ModFeaturePost {
|
||||||
id: inserted_mod_feature_post.id,
|
id: inserted_mod_feature_post.id,
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
@ -619,12 +605,10 @@ mod tests {
|
|||||||
reason: None,
|
reason: None,
|
||||||
removed: None,
|
removed: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_remove_comment = ModRemoveComment::create(pool, &mod_remove_comment_form)
|
let inserted_mod_remove_comment =
|
||||||
.await
|
ModRemoveComment::create(pool, &mod_remove_comment_form).await?;
|
||||||
.unwrap();
|
let read_mod_remove_comment =
|
||||||
let read_mod_remove_comment = ModRemoveComment::read(pool, inserted_mod_remove_comment.id)
|
ModRemoveComment::read(pool, inserted_mod_remove_comment.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let expected_mod_remove_comment = ModRemoveComment {
|
let expected_mod_remove_comment = ModRemoveComment {
|
||||||
id: inserted_mod_remove_comment.id,
|
id: inserted_mod_remove_comment.id,
|
||||||
comment_id: inserted_comment.id,
|
comment_id: inserted_comment.id,
|
||||||
@ -643,13 +627,9 @@ mod tests {
|
|||||||
removed: None,
|
removed: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_remove_community =
|
let inserted_mod_remove_community =
|
||||||
ModRemoveCommunity::create(pool, &mod_remove_community_form)
|
ModRemoveCommunity::create(pool, &mod_remove_community_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let read_mod_remove_community =
|
let read_mod_remove_community =
|
||||||
ModRemoveCommunity::read(pool, inserted_mod_remove_community.id)
|
ModRemoveCommunity::read(pool, inserted_mod_remove_community.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let expected_mod_remove_community = ModRemoveCommunity {
|
let expected_mod_remove_community = ModRemoveCommunity {
|
||||||
id: inserted_mod_remove_community.id,
|
id: inserted_mod_remove_community.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
@ -670,13 +650,9 @@ mod tests {
|
|||||||
expires: None,
|
expires: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_ban_from_community =
|
let inserted_mod_ban_from_community =
|
||||||
ModBanFromCommunity::create(pool, &mod_ban_from_community_form)
|
ModBanFromCommunity::create(pool, &mod_ban_from_community_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let read_mod_ban_from_community =
|
let read_mod_ban_from_community =
|
||||||
ModBanFromCommunity::read(pool, inserted_mod_ban_from_community.id)
|
ModBanFromCommunity::read(pool, inserted_mod_ban_from_community.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let expected_mod_ban_from_community = ModBanFromCommunity {
|
let expected_mod_ban_from_community = ModBanFromCommunity {
|
||||||
id: inserted_mod_ban_from_community.id,
|
id: inserted_mod_ban_from_community.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
@ -697,8 +673,8 @@ mod tests {
|
|||||||
banned: None,
|
banned: None,
|
||||||
expires: None,
|
expires: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_ban = ModBan::create(pool, &mod_ban_form).await.unwrap();
|
let inserted_mod_ban = ModBan::create(pool, &mod_ban_form).await?;
|
||||||
let read_mod_ban = ModBan::read(pool, inserted_mod_ban.id).await.unwrap();
|
let read_mod_ban = ModBan::read(pool, inserted_mod_ban.id).await?;
|
||||||
let expected_mod_ban = ModBan {
|
let expected_mod_ban = ModBan {
|
||||||
id: inserted_mod_ban.id,
|
id: inserted_mod_ban.id,
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
@ -717,12 +693,8 @@ mod tests {
|
|||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_add_community = ModAddCommunity::create(pool, &mod_add_community_form)
|
let inserted_mod_add_community = ModAddCommunity::create(pool, &mod_add_community_form).await?;
|
||||||
.await
|
let read_mod_add_community = ModAddCommunity::read(pool, inserted_mod_add_community.id).await?;
|
||||||
.unwrap();
|
|
||||||
let read_mod_add_community = ModAddCommunity::read(pool, inserted_mod_add_community.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let expected_mod_add_community = ModAddCommunity {
|
let expected_mod_add_community = ModAddCommunity {
|
||||||
id: inserted_mod_add_community.id,
|
id: inserted_mod_add_community.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
@ -739,8 +711,8 @@ mod tests {
|
|||||||
other_person_id: inserted_person.id,
|
other_person_id: inserted_person.id,
|
||||||
removed: None,
|
removed: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_add = ModAdd::create(pool, &mod_add_form).await.unwrap();
|
let inserted_mod_add = ModAdd::create(pool, &mod_add_form).await?;
|
||||||
let read_mod_add = ModAdd::read(pool, inserted_mod_add.id).await.unwrap();
|
let read_mod_add = ModAdd::read(pool, inserted_mod_add.id).await?;
|
||||||
let expected_mod_add = ModAdd {
|
let expected_mod_add = ModAdd {
|
||||||
id: inserted_mod_add.id,
|
id: inserted_mod_add.id,
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
@ -749,14 +721,12 @@ mod tests {
|
|||||||
when_: inserted_mod_add.when_,
|
when_: inserted_mod_add.when_,
|
||||||
};
|
};
|
||||||
|
|
||||||
Comment::delete(pool, inserted_comment.id).await.unwrap();
|
Comment::delete(pool, inserted_comment.id).await?;
|
||||||
Post::delete(pool, inserted_post.id).await.unwrap();
|
Post::delete(pool, inserted_post.id).await?;
|
||||||
Community::delete(pool, inserted_community.id)
|
Community::delete(pool, inserted_community.id).await?;
|
||||||
.await
|
Person::delete(pool, inserted_person.id).await?;
|
||||||
.unwrap();
|
Person::delete(pool, inserted_mod.id).await?;
|
||||||
Person::delete(pool, inserted_person.id).await.unwrap();
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
Person::delete(pool, inserted_mod.id).await.unwrap();
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(expected_mod_remove_post, read_mod_remove_post);
|
assert_eq!(expected_mod_remove_post, read_mod_remove_post);
|
||||||
assert_eq!(expected_mod_lock_post, read_mod_lock_post);
|
assert_eq!(expected_mod_lock_post, read_mod_lock_post);
|
||||||
@ -767,5 +737,7 @@ mod tests {
|
|||||||
assert_eq!(expected_mod_ban, read_mod_ban);
|
assert_eq!(expected_mod_ban, read_mod_ban);
|
||||||
assert_eq!(expected_mod_add_community, read_mod_add_community);
|
assert_eq!(expected_mod_add_community, read_mod_add_community);
|
||||||
assert_eq!(expected_mod_add, read_mod_add);
|
assert_eq!(expected_mod_add, read_mod_add);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,7 +392,6 @@ impl PostHide {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -415,6 +414,7 @@ mod tests {
|
|||||||
utils::build_db_pool_for_tests,
|
utils::build_db_pool_for_tests,
|
||||||
};
|
};
|
||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
@ -422,17 +422,15 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 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 new_person = PersonInsertForm::test_form(inserted_instance.id, "jim");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "jim");
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
let inserted_person = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -441,27 +439,27 @@ mod tests {
|
|||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
let new_post = PostInsertForm::new(
|
||||||
"A test post".into(),
|
"A test post".into(),
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
let inserted_post = Post::create(pool, &new_post).await.unwrap();
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let new_post2 = PostInsertForm::new(
|
let new_post2 = PostInsertForm::new(
|
||||||
"A test post 2".into(),
|
"A test post 2".into(),
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
let inserted_post2 = Post::create(pool, &new_post2).await.unwrap();
|
let inserted_post2 = Post::create(pool, &new_post2).await?;
|
||||||
|
|
||||||
let new_scheduled_post = PostInsertForm {
|
let new_scheduled_post = PostInsertForm {
|
||||||
scheduled_publish_time: Some(DateTime::from_timestamp_nanos(i64::MAX)),
|
scheduled_publish_time: Some(DateTime::from_timestamp_nanos(i64::MAX)),
|
||||||
..PostInsertForm::new("beans".into(), inserted_person.id, inserted_community.id)
|
..PostInsertForm::new("beans".into(), inserted_person.id, inserted_community.id)
|
||||||
};
|
};
|
||||||
let inserted_scheduled_post = Post::create(pool, &new_scheduled_post).await.unwrap();
|
let inserted_scheduled_post = Post::create(pool, &new_scheduled_post).await?;
|
||||||
|
|
||||||
let expected_post = Post {
|
let expected_post = Post {
|
||||||
id: inserted_post.id,
|
id: inserted_post.id,
|
||||||
@ -481,9 +479,7 @@ mod tests {
|
|||||||
embed_description: None,
|
embed_description: None,
|
||||||
embed_video_url: None,
|
embed_video_url: None,
|
||||||
thumbnail_url: None,
|
thumbnail_url: None,
|
||||||
ap_id: Url::parse(&format!("https://lemmy-alpha/post/{}", inserted_post.id))
|
ap_id: Url::parse(&format!("https://lemmy-alpha/post/{}", inserted_post.id))?.into(),
|
||||||
.unwrap()
|
|
||||||
.into(),
|
|
||||||
local: true,
|
local: true,
|
||||||
language_id: Default::default(),
|
language_id: Default::default(),
|
||||||
featured_community: false,
|
featured_community: false,
|
||||||
@ -499,7 +495,7 @@ mod tests {
|
|||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_post_like = PostLike::like(pool, &post_like_form).await.unwrap();
|
let inserted_post_like = PostLike::like(pool, &post_like_form).await?;
|
||||||
|
|
||||||
let expected_post_like = PostLike {
|
let expected_post_like = PostLike {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
@ -514,7 +510,7 @@ mod tests {
|
|||||||
person_id: inserted_person.id,
|
person_id: inserted_person.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_post_saved = PostSaved::save(pool, &post_saved_form).await.unwrap();
|
let inserted_post_saved = PostSaved::save(pool, &post_saved_form).await?;
|
||||||
|
|
||||||
let expected_post_saved = PostSaved {
|
let expected_post_saved = PostSaved {
|
||||||
post_id: inserted_post.id,
|
post_id: inserted_post.id,
|
||||||
@ -528,57 +524,47 @@ mod tests {
|
|||||||
HashSet::from([inserted_post.id, inserted_post2.id]),
|
HashSet::from([inserted_post.id, inserted_post2.id]),
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(2, marked_as_read);
|
assert_eq!(2, marked_as_read);
|
||||||
|
|
||||||
let read_post = Post::read(pool, inserted_post.id).await.unwrap();
|
let read_post = Post::read(pool, inserted_post.id).await?;
|
||||||
|
|
||||||
let new_post_update = PostUpdateForm {
|
let new_post_update = PostUpdateForm {
|
||||||
name: Some("A test post".into()),
|
name: Some("A test post".into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let updated_post = Post::update(pool, inserted_post.id, &new_post_update)
|
let updated_post = Post::update(pool, inserted_post.id, &new_post_update).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Scheduled post count
|
// Scheduled post count
|
||||||
let scheduled_post_count = Post::user_scheduled_post_count(inserted_person.id, pool)
|
let scheduled_post_count = Post::user_scheduled_post_count(inserted_person.id, pool).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(1, scheduled_post_count);
|
assert_eq!(1, scheduled_post_count);
|
||||||
|
|
||||||
let like_removed = PostLike::remove(pool, inserted_person.id, inserted_post.id)
|
let like_removed = PostLike::remove(pool, inserted_person.id, inserted_post.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(1, like_removed);
|
assert_eq!(1, like_removed);
|
||||||
let saved_removed = PostSaved::unsave(pool, &post_saved_form).await.unwrap();
|
let saved_removed = PostSaved::unsave(pool, &post_saved_form).await?;
|
||||||
assert_eq!(1, saved_removed);
|
assert_eq!(1, saved_removed);
|
||||||
let read_removed = PostRead::mark_as_unread(
|
let read_removed = PostRead::mark_as_unread(
|
||||||
pool,
|
pool,
|
||||||
HashSet::from([inserted_post.id, inserted_post2.id]),
|
HashSet::from([inserted_post.id, inserted_post2.id]),
|
||||||
inserted_person.id,
|
inserted_person.id,
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(2, read_removed);
|
assert_eq!(2, read_removed);
|
||||||
|
|
||||||
let num_deleted = Post::delete(pool, inserted_post.id).await.unwrap()
|
let num_deleted = Post::delete(pool, inserted_post.id).await?
|
||||||
+ Post::delete(pool, inserted_post2.id).await.unwrap()
|
+ Post::delete(pool, inserted_post2.id).await?
|
||||||
+ Post::delete(pool, inserted_scheduled_post.id)
|
+ Post::delete(pool, inserted_scheduled_post.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(3, num_deleted);
|
assert_eq!(3, num_deleted);
|
||||||
Community::delete(pool, inserted_community.id)
|
Community::delete(pool, inserted_community.id).await?;
|
||||||
.await
|
Person::delete(pool, inserted_person.id).await?;
|
||||||
.unwrap();
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
Person::delete(pool, inserted_person.id).await.unwrap();
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(expected_post, read_post);
|
assert_eq!(expected_post, read_post);
|
||||||
assert_eq!(expected_post, inserted_post);
|
assert_eq!(expected_post, inserted_post);
|
||||||
assert_eq!(expected_post, updated_post);
|
assert_eq!(expected_post, updated_post);
|
||||||
assert_eq!(expected_post_like, inserted_post_like);
|
assert_eq!(expected_post_like, inserted_post_like);
|
||||||
assert_eq!(expected_post_saved, inserted_post_saved);
|
assert_eq!(expected_post_saved, inserted_post_saved);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,6 @@ impl Reportable for PostReport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -94,14 +93,13 @@ mod tests {
|
|||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::build_db_pool_for_tests,
|
utils::build_db_pool_for_tests,
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
async fn init(pool: &mut DbPool<'_>) -> (Person, PostReport) {
|
async fn init(pool: &mut DbPool<'_>) -> LemmyResult<(Person, PostReport)> {
|
||||||
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 person_form = PersonInsertForm::test_form(inserted_instance.id, "jim");
|
let person_form = PersonInsertForm::test_form(inserted_instance.id, "jim");
|
||||||
let person = Person::create(pool, &person_form).await.unwrap();
|
let person = Person::create(pool, &person_form).await?;
|
||||||
|
|
||||||
let community_form = CommunityInsertForm::new(
|
let community_form = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -109,10 +107,10 @@ mod tests {
|
|||||||
"nada".to_owned(),
|
"nada".to_owned(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let community = Community::create(pool, &community_form).await.unwrap();
|
let community = Community::create(pool, &community_form).await?;
|
||||||
|
|
||||||
let form = PostInsertForm::new("A test post".into(), person.id, community.id);
|
let form = PostInsertForm::new("A test post".into(), person.id, community.id);
|
||||||
let post = Post::create(pool, &form).await.unwrap();
|
let post = Post::create(pool, &form).await?;
|
||||||
|
|
||||||
let report_form = PostReportForm {
|
let report_form = PostReportForm {
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
@ -120,46 +118,46 @@ mod tests {
|
|||||||
reason: "my reason".to_string(),
|
reason: "my reason".to_string(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
let report = PostReport::report(pool, &report_form).await.unwrap();
|
let report = PostReport::report(pool, &report_form).await?;
|
||||||
(person, report)
|
|
||||||
|
Ok((person, report))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_resolve_post_report() {
|
async fn test_resolve_post_report() -> 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 (person, report) = init(pool).await;
|
let (person, report) = init(pool).await?;
|
||||||
|
|
||||||
let resolved_count = PostReport::resolve(pool, report.id, person.id)
|
let resolved_count = PostReport::resolve(pool, report.id, person.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(resolved_count, 1);
|
assert_eq!(resolved_count, 1);
|
||||||
|
|
||||||
let unresolved_count = PostReport::unresolve(pool, report.id, person.id)
|
let unresolved_count = PostReport::unresolve(pool, report.id, person.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(unresolved_count, 1);
|
assert_eq!(unresolved_count, 1);
|
||||||
|
|
||||||
Person::delete(pool, person.id).await.unwrap();
|
Person::delete(pool, person.id).await?;
|
||||||
Post::delete(pool, report.post_id).await.unwrap();
|
Post::delete(pool, report.post_id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_resolve_all_post_reports() {
|
async fn test_resolve_all_post_reports() -> 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 (person, report) = init(pool).await;
|
let (person, report) = init(pool).await?;
|
||||||
|
|
||||||
let resolved_count = PostReport::resolve_all_for_object(pool, report.post_id, person.id)
|
let resolved_count =
|
||||||
.await
|
PostReport::resolve_all_for_object(pool, report.post_id, person.id).await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(resolved_count, 1);
|
assert_eq!(resolved_count, 1);
|
||||||
|
|
||||||
Person::delete(pool, person.id).await.unwrap();
|
Person::delete(pool, person.id).await?;
|
||||||
Post::delete(pool, report.post_id).await.unwrap();
|
Post::delete(pool, report.post_id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,6 @@ impl PrivateMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -97,27 +96,26 @@ 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;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 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 creator_form = PersonInsertForm::test_form(inserted_instance.id, "creator_pm");
|
let creator_form = PersonInsertForm::test_form(inserted_instance.id, "creator_pm");
|
||||||
|
|
||||||
let inserted_creator = Person::create(pool, &creator_form).await.unwrap();
|
let inserted_creator = Person::create(pool, &creator_form).await?;
|
||||||
|
|
||||||
let recipient_form = PersonInsertForm::test_form(inserted_instance.id, "recipient_pm");
|
let recipient_form = PersonInsertForm::test_form(inserted_instance.id, "recipient_pm");
|
||||||
|
|
||||||
let inserted_recipient = Person::create(pool, &recipient_form).await.unwrap();
|
let inserted_recipient = Person::create(pool, &recipient_form).await?;
|
||||||
|
|
||||||
let private_message_form = PrivateMessageInsertForm::new(
|
let private_message_form = PrivateMessageInsertForm::new(
|
||||||
inserted_creator.id,
|
inserted_creator.id,
|
||||||
@ -125,9 +123,7 @@ mod tests {
|
|||||||
"A test private message".into(),
|
"A test private message".into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let inserted_private_message = PrivateMessage::create(pool, &private_message_form)
|
let inserted_private_message = PrivateMessage::create(pool, &private_message_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let expected_private_message = PrivateMessage {
|
let expected_private_message = PrivateMessage {
|
||||||
id: inserted_private_message.id,
|
id: inserted_private_message.id,
|
||||||
@ -141,15 +137,12 @@ mod tests {
|
|||||||
ap_id: Url::parse(&format!(
|
ap_id: Url::parse(&format!(
|
||||||
"https://lemmy-alpha/private_message/{}",
|
"https://lemmy-alpha/private_message/{}",
|
||||||
inserted_private_message.id
|
inserted_private_message.id
|
||||||
))
|
))?
|
||||||
.unwrap()
|
|
||||||
.into(),
|
.into(),
|
||||||
local: true,
|
local: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_private_message = PrivateMessage::read(pool, inserted_private_message.id)
|
let read_private_message = PrivateMessage::read(pool, inserted_private_message.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let private_message_update_form = PrivateMessageUpdateForm {
|
let private_message_update_form = PrivateMessageUpdateForm {
|
||||||
content: Some("A test private message".into()),
|
content: Some("A test private message".into()),
|
||||||
@ -160,8 +153,7 @@ mod tests {
|
|||||||
inserted_private_message.id,
|
inserted_private_message.id,
|
||||||
&private_message_update_form,
|
&private_message_update_form,
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let deleted_private_message = PrivateMessage::update(
|
let deleted_private_message = PrivateMessage::update(
|
||||||
pool,
|
pool,
|
||||||
@ -171,8 +163,7 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
let marked_read_private_message = PrivateMessage::update(
|
let marked_read_private_message = PrivateMessage::update(
|
||||||
pool,
|
pool,
|
||||||
inserted_private_message.id,
|
inserted_private_message.id,
|
||||||
@ -181,16 +172,17 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
Person::delete(pool, inserted_creator.id).await?;
|
||||||
Person::delete(pool, inserted_creator.id).await.unwrap();
|
Person::delete(pool, inserted_recipient.id).await?;
|
||||||
Person::delete(pool, inserted_recipient.id).await.unwrap();
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(expected_private_message, read_private_message);
|
assert_eq!(expected_private_message, read_private_message);
|
||||||
assert_eq!(expected_private_message, updated_private_message);
|
assert_eq!(expected_private_message, updated_private_message);
|
||||||
assert_eq!(expected_private_message, inserted_private_message);
|
assert_eq!(expected_private_message, inserted_private_message);
|
||||||
assert!(deleted_private_message.deleted);
|
assert!(deleted_private_message.deleted);
|
||||||
assert!(marked_read_private_message.read);
|
assert!(marked_read_private_message.read);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,6 @@ impl CommentReportQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
#[expect(clippy::indexing_slicing)]
|
#[expect(clippy::indexing_slicing)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
@ -284,27 +283,24 @@ mod tests {
|
|||||||
CommunityVisibility,
|
CommunityVisibility,
|
||||||
SubscribedType,
|
SubscribedType,
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 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 new_person = PersonInsertForm::test_form(inserted_instance.id, "timmy_crv");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "timmy_crv");
|
||||||
|
|
||||||
let inserted_timmy = Person::create(pool, &new_person).await.unwrap();
|
let inserted_timmy = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let new_local_user = LocalUserInsertForm::test_form(inserted_timmy.id);
|
let new_local_user = LocalUserInsertForm::test_form(inserted_timmy.id);
|
||||||
let timmy_local_user = LocalUser::create(pool, &new_local_user, vec![])
|
let timmy_local_user = LocalUser::create(pool, &new_local_user, vec![]).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let timmy_view = LocalUserView {
|
let timmy_view = LocalUserView {
|
||||||
local_user: timmy_local_user,
|
local_user: timmy_local_user,
|
||||||
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
|
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
|
||||||
@ -314,12 +310,12 @@ mod tests {
|
|||||||
|
|
||||||
let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "sara_crv");
|
let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "sara_crv");
|
||||||
|
|
||||||
let inserted_sara = Person::create(pool, &new_person_2).await.unwrap();
|
let inserted_sara = Person::create(pool, &new_person_2).await?;
|
||||||
|
|
||||||
// Add a third person, since new ppl can only report something once.
|
// Add a third person, since new ppl can only report something once.
|
||||||
let new_person_3 = PersonInsertForm::test_form(inserted_instance.id, "jessica_crv");
|
let new_person_3 = PersonInsertForm::test_form(inserted_instance.id, "jessica_crv");
|
||||||
|
|
||||||
let inserted_jessica = Person::create(pool, &new_person_3).await.unwrap();
|
let inserted_jessica = Person::create(pool, &new_person_3).await?;
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -327,7 +323,7 @@ mod tests {
|
|||||||
"nada".to_owned(),
|
"nada".to_owned(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
|
|
||||||
// Make timmy a mod
|
// Make timmy a mod
|
||||||
let timmy_moderator_form = CommunityModeratorForm {
|
let timmy_moderator_form = CommunityModeratorForm {
|
||||||
@ -335,9 +331,7 @@ mod tests {
|
|||||||
person_id: inserted_timmy.id,
|
person_id: inserted_timmy.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _inserted_moderator = CommunityModerator::join(pool, &timmy_moderator_form)
|
let _inserted_moderator = CommunityModerator::join(pool, &timmy_moderator_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
let new_post = PostInsertForm::new(
|
||||||
"A test post crv".into(),
|
"A test post crv".into(),
|
||||||
@ -345,14 +339,14 @@ mod tests {
|
|||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
let inserted_post = Post::create(pool, &new_post).await.unwrap();
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::new(
|
let comment_form = CommentInsertForm::new(
|
||||||
inserted_timmy.id,
|
inserted_timmy.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"A test comment 32".into(),
|
"A test comment 32".into(),
|
||||||
);
|
);
|
||||||
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
let inserted_comment = Comment::create(pool, &comment_form, None).await?;
|
||||||
|
|
||||||
// sara reports
|
// sara reports
|
||||||
let sara_report_form = CommentReportForm {
|
let sara_report_form = CommentReportForm {
|
||||||
@ -362,9 +356,7 @@ mod tests {
|
|||||||
reason: "from sara".into(),
|
reason: "from sara".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_sara_report = CommentReport::report(pool, &sara_report_form)
|
let inserted_sara_report = CommentReport::report(pool, &sara_report_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// jessica reports
|
// jessica reports
|
||||||
let jessica_report_form = CommentReportForm {
|
let jessica_report_form = CommentReportForm {
|
||||||
@ -374,18 +366,12 @@ mod tests {
|
|||||||
reason: "from jessica".into(),
|
reason: "from jessica".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_jessica_report = CommentReport::report(pool, &jessica_report_form)
|
let inserted_jessica_report = CommentReport::report(pool, &jessica_report_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let agg = CommentAggregates::read(pool, inserted_comment.id)
|
let agg = CommentAggregates::read(pool, inserted_comment.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let read_jessica_report_view =
|
let read_jessica_report_view =
|
||||||
CommentReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id)
|
CommentReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let expected_jessica_report_view = CommentReportView {
|
let expected_jessica_report_view = CommentReportView {
|
||||||
comment_report: inserted_jessica_report.clone(),
|
comment_report: inserted_jessica_report.clone(),
|
||||||
comment: inserted_comment.clone(),
|
comment: inserted_comment.clone(),
|
||||||
@ -514,8 +500,7 @@ mod tests {
|
|||||||
// Do a batch read of timmys reports
|
// Do a batch read of timmys reports
|
||||||
let reports = CommentReportQuery::default()
|
let reports = CommentReportQuery::default()
|
||||||
.list(pool, &timmy_view)
|
.list(pool, &timmy_view)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
reports,
|
reports,
|
||||||
@ -526,19 +511,14 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let report_count = CommentReportView::get_report_count(pool, inserted_timmy.id, false, None)
|
let report_count =
|
||||||
.await
|
CommentReportView::get_report_count(pool, inserted_timmy.id, false, None).await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(2, report_count);
|
assert_eq!(2, report_count);
|
||||||
|
|
||||||
// Try to resolve the report
|
// Try to resolve the report
|
||||||
CommentReport::resolve(pool, inserted_jessica_report.id, inserted_timmy.id)
|
CommentReport::resolve(pool, inserted_jessica_report.id, inserted_timmy.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let read_jessica_report_view_after_resolve =
|
let read_jessica_report_view_after_resolve =
|
||||||
CommentReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id)
|
CommentReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut expected_jessica_report_view_after_resolve = expected_jessica_report_view;
|
let mut expected_jessica_report_view_after_resolve = expected_jessica_report_view;
|
||||||
expected_jessica_report_view_after_resolve
|
expected_jessica_report_view_after_resolve
|
||||||
@ -588,24 +568,21 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(pool, &timmy_view)
|
.list(pool, &timmy_view)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(reports_after_resolve[0], expected_sara_report_view);
|
assert_eq!(reports_after_resolve[0], expected_sara_report_view);
|
||||||
assert_eq!(reports_after_resolve.len(), 1);
|
assert_eq!(reports_after_resolve.len(), 1);
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let report_count_after_resolved =
|
let report_count_after_resolved =
|
||||||
CommentReportView::get_report_count(pool, inserted_timmy.id, false, None)
|
CommentReportView::get_report_count(pool, inserted_timmy.id, false, None).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(1, report_count_after_resolved);
|
assert_eq!(1, report_count_after_resolved);
|
||||||
|
|
||||||
Person::delete(pool, inserted_timmy.id).await.unwrap();
|
Person::delete(pool, inserted_timmy.id).await?;
|
||||||
Person::delete(pool, inserted_sara.id).await.unwrap();
|
Person::delete(pool, inserted_sara.id).await?;
|
||||||
Person::delete(pool, inserted_jessica.id).await.unwrap();
|
Person::delete(pool, inserted_jessica.id).await?;
|
||||||
Community::delete(pool, inserted_community.id)
|
Community::delete(pool, inserted_community.id).await?;
|
||||||
.await
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
.unwrap();
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,27 +306,24 @@ mod tests {
|
|||||||
traits::{Crud, Joinable, Reportable},
|
traits::{Crud, Joinable, Reportable},
|
||||||
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;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 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 new_person = PersonInsertForm::test_form(inserted_instance.id, "timmy_prv");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "timmy_prv");
|
||||||
|
|
||||||
let inserted_timmy = Person::create(pool, &new_person).await.unwrap();
|
let inserted_timmy = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let new_local_user = LocalUserInsertForm::test_form(inserted_timmy.id);
|
let new_local_user = LocalUserInsertForm::test_form(inserted_timmy.id);
|
||||||
let timmy_local_user = LocalUser::create(pool, &new_local_user, vec![])
|
let timmy_local_user = LocalUser::create(pool, &new_local_user, vec![]).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let timmy_view = LocalUserView {
|
let timmy_view = LocalUserView {
|
||||||
local_user: timmy_local_user,
|
local_user: timmy_local_user,
|
||||||
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
|
local_user_vote_display_mode: LocalUserVoteDisplayMode::default(),
|
||||||
@ -336,12 +333,12 @@ mod tests {
|
|||||||
|
|
||||||
let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "sara_prv");
|
let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "sara_prv");
|
||||||
|
|
||||||
let inserted_sara = Person::create(pool, &new_person_2).await.unwrap();
|
let inserted_sara = Person::create(pool, &new_person_2).await?;
|
||||||
|
|
||||||
// Add a third person, since new ppl can only report something once.
|
// Add a third person, since new ppl can only report something once.
|
||||||
let new_person_3 = PersonInsertForm::test_form(inserted_instance.id, "jessica_prv");
|
let new_person_3 = PersonInsertForm::test_form(inserted_instance.id, "jessica_prv");
|
||||||
|
|
||||||
let inserted_jessica = Person::create(pool, &new_person_3).await.unwrap();
|
let inserted_jessica = Person::create(pool, &new_person_3).await?;
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -349,7 +346,7 @@ mod tests {
|
|||||||
"nada".to_owned(),
|
"nada".to_owned(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
|
|
||||||
// Make timmy a mod
|
// Make timmy a mod
|
||||||
let timmy_moderator_form = CommunityModeratorForm {
|
let timmy_moderator_form = CommunityModeratorForm {
|
||||||
@ -357,16 +354,14 @@ mod tests {
|
|||||||
person_id: inserted_timmy.id,
|
person_id: inserted_timmy.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let _inserted_moderator = CommunityModerator::join(pool, &timmy_moderator_form)
|
let _inserted_moderator = CommunityModerator::join(pool, &timmy_moderator_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
let new_post = PostInsertForm::new(
|
||||||
"A test post crv".into(),
|
"A test post crv".into(),
|
||||||
inserted_timmy.id,
|
inserted_timmy.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
let inserted_post = Post::create(pool, &new_post).await.unwrap();
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
// sara reports
|
// sara reports
|
||||||
let sara_report_form = PostReportForm {
|
let sara_report_form = PostReportForm {
|
||||||
@ -378,14 +373,14 @@ mod tests {
|
|||||||
reason: "from sara".into(),
|
reason: "from sara".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
PostReport::report(pool, &sara_report_form).await.unwrap();
|
PostReport::report(pool, &sara_report_form).await?;
|
||||||
|
|
||||||
let new_post_2 = PostInsertForm::new(
|
let new_post_2 = PostInsertForm::new(
|
||||||
"A test post crv 2".into(),
|
"A test post crv 2".into(),
|
||||||
inserted_timmy.id,
|
inserted_timmy.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
let inserted_post_2 = Post::create(pool, &new_post_2).await.unwrap();
|
let inserted_post_2 = Post::create(pool, &new_post_2).await?;
|
||||||
|
|
||||||
// jessica reports
|
// jessica reports
|
||||||
let jessica_report_form = PostReportForm {
|
let jessica_report_form = PostReportForm {
|
||||||
@ -397,14 +392,10 @@ mod tests {
|
|||||||
reason: "from jessica".into(),
|
reason: "from jessica".into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_jessica_report = PostReport::report(pool, &jessica_report_form)
|
let inserted_jessica_report = PostReport::report(pool, &jessica_report_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let read_jessica_report_view =
|
let read_jessica_report_view =
|
||||||
PostReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id)
|
PostReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
read_jessica_report_view.post_report,
|
read_jessica_report_view.post_report,
|
||||||
@ -418,30 +409,23 @@ mod tests {
|
|||||||
assert_eq!(read_jessica_report_view.resolver, None);
|
assert_eq!(read_jessica_report_view.resolver, None);
|
||||||
|
|
||||||
// Do a batch read of timmys reports
|
// Do a batch read of timmys reports
|
||||||
let reports = PostReportQuery::default()
|
let reports = PostReportQuery::default().list(pool, &timmy_view).await?;
|
||||||
.list(pool, &timmy_view)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(reports[1].creator.id, inserted_sara.id);
|
assert_eq!(reports[1].creator.id, inserted_sara.id);
|
||||||
assert_eq!(reports[0].creator.id, inserted_jessica.id);
|
assert_eq!(reports[0].creator.id, inserted_jessica.id);
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let report_count = PostReportView::get_report_count(pool, inserted_timmy.id, false, None)
|
let report_count =
|
||||||
.await
|
PostReportView::get_report_count(pool, inserted_timmy.id, false, None).await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(2, report_count);
|
assert_eq!(2, report_count);
|
||||||
|
|
||||||
// Pretend the post was removed, and resolve all reports for that object.
|
// Pretend the post was removed, and resolve all reports for that object.
|
||||||
// This is called manually in the API for post removals
|
// This is called manually in the API for post removals
|
||||||
PostReport::resolve_all_for_object(pool, inserted_jessica_report.post_id, inserted_timmy.id)
|
PostReport::resolve_all_for_object(pool, inserted_jessica_report.post_id, inserted_timmy.id)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let read_jessica_report_view_after_resolve =
|
let read_jessica_report_view_after_resolve =
|
||||||
PostReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id)
|
PostReportView::read(pool, inserted_jessica_report.id, inserted_timmy.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert!(read_jessica_report_view_after_resolve.post_report.resolved);
|
assert!(read_jessica_report_view_after_resolve.post_report.resolved);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
read_jessica_report_view_after_resolve
|
read_jessica_report_view_after_resolve
|
||||||
@ -461,24 +445,21 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(pool, &timmy_view)
|
.list(pool, &timmy_view)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
assert_length!(1, reports_after_resolve);
|
assert_length!(1, reports_after_resolve);
|
||||||
assert_eq!(reports_after_resolve[0].creator.id, inserted_sara.id);
|
assert_eq!(reports_after_resolve[0].creator.id, inserted_sara.id);
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let report_count_after_resolved =
|
let report_count_after_resolved =
|
||||||
PostReportView::get_report_count(pool, inserted_timmy.id, false, None)
|
PostReportView::get_report_count(pool, inserted_timmy.id, false, None).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(1, report_count_after_resolved);
|
assert_eq!(1, report_count_after_resolved);
|
||||||
|
|
||||||
Person::delete(pool, inserted_timmy.id).await.unwrap();
|
Person::delete(pool, inserted_timmy.id).await?;
|
||||||
Person::delete(pool, inserted_sara.id).await.unwrap();
|
Person::delete(pool, inserted_sara.id).await?;
|
||||||
Person::delete(pool, inserted_jessica.id).await.unwrap();
|
Person::delete(pool, inserted_jessica.id).await?;
|
||||||
Community::delete(pool, inserted_community.id)
|
Community::delete(pool, inserted_community.id).await?;
|
||||||
.await
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
.unwrap();
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,24 +127,23 @@ mod tests {
|
|||||||
traits::{Crud, Reportable},
|
traits::{Crud, Reportable},
|
||||||
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;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 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 new_person_1 = PersonInsertForm::test_form(inserted_instance.id, "timmy_mrv");
|
let new_person_1 = PersonInsertForm::test_form(inserted_instance.id, "timmy_mrv");
|
||||||
let inserted_timmy = Person::create(pool, &new_person_1).await.unwrap();
|
let inserted_timmy = Person::create(pool, &new_person_1).await?;
|
||||||
|
|
||||||
let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "jessica_mrv");
|
let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "jessica_mrv");
|
||||||
let inserted_jessica = Person::create(pool, &new_person_2).await.unwrap();
|
let inserted_jessica = Person::create(pool, &new_person_2).await?;
|
||||||
|
|
||||||
// timmy sends private message to jessica
|
// timmy sends private message to jessica
|
||||||
let pm_form = PrivateMessageInsertForm::new(
|
let pm_form = PrivateMessageInsertForm::new(
|
||||||
@ -152,7 +151,7 @@ mod tests {
|
|||||||
inserted_jessica.id,
|
inserted_jessica.id,
|
||||||
"something offensive".to_string(),
|
"something offensive".to_string(),
|
||||||
);
|
);
|
||||||
let pm = PrivateMessage::create(pool, &pm_form).await.unwrap();
|
let pm = PrivateMessage::create(pool, &pm_form).await?;
|
||||||
|
|
||||||
// jessica reports private message
|
// jessica reports private message
|
||||||
let pm_report_form = PrivateMessageReportForm {
|
let pm_report_form = PrivateMessageReportForm {
|
||||||
@ -161,14 +160,9 @@ mod tests {
|
|||||||
private_message_id: pm.id,
|
private_message_id: pm.id,
|
||||||
reason: "its offensive".to_string(),
|
reason: "its offensive".to_string(),
|
||||||
};
|
};
|
||||||
let pm_report = PrivateMessageReport::report(pool, &pm_report_form)
|
let pm_report = PrivateMessageReport::report(pool, &pm_report_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let reports = PrivateMessageReportQuery::default()
|
let reports = PrivateMessageReportQuery::default().list(pool).await?;
|
||||||
.list(pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_length!(1, reports);
|
assert_length!(1, reports);
|
||||||
assert!(!reports[0].private_message_report.resolved);
|
assert!(!reports[0].private_message_report.resolved);
|
||||||
assert_eq!(inserted_timmy.name, reports[0].private_message_creator.name);
|
assert_eq!(inserted_timmy.name, reports[0].private_message_creator.name);
|
||||||
@ -177,20 +171,17 @@ mod tests {
|
|||||||
assert_eq!(pm.content, reports[0].private_message.content);
|
assert_eq!(pm.content, reports[0].private_message.content);
|
||||||
|
|
||||||
let new_person_3 = PersonInsertForm::test_form(inserted_instance.id, "admin_mrv");
|
let new_person_3 = PersonInsertForm::test_form(inserted_instance.id, "admin_mrv");
|
||||||
let inserted_admin = Person::create(pool, &new_person_3).await.unwrap();
|
let inserted_admin = Person::create(pool, &new_person_3).await?;
|
||||||
|
|
||||||
// admin resolves the report (after taking appropriate action)
|
// admin resolves the report (after taking appropriate action)
|
||||||
PrivateMessageReport::resolve(pool, pm_report.id, inserted_admin.id)
|
PrivateMessageReport::resolve(pool, pm_report.id, inserted_admin.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let reports = PrivateMessageReportQuery {
|
let reports = PrivateMessageReportQuery {
|
||||||
unresolved_only: (false),
|
unresolved_only: (false),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(pool)
|
.list(pool)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
assert_length!(1, reports);
|
assert_length!(1, reports);
|
||||||
assert!(reports[0].private_message_report.resolved);
|
assert!(reports[0].private_message_report.resolved);
|
||||||
assert!(reports[0].resolver.is_some());
|
assert!(reports[0].resolver.is_some());
|
||||||
@ -199,6 +190,8 @@ mod tests {
|
|||||||
reports[0].resolver.as_ref().unwrap().name
|
reports[0].resolver.as_ref().unwrap().name
|
||||||
);
|
);
|
||||||
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,6 @@ impl PrivateMessageQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
#[expect(clippy::indexing_slicing)]
|
#[expect(clippy::indexing_slicing)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
@ -205,45 +204,35 @@ mod tests {
|
|||||||
async fn init_data(pool: &mut DbPool<'_>) -> LemmyResult<Data> {
|
async fn init_data(pool: &mut DbPool<'_>) -> LemmyResult<Data> {
|
||||||
let message_content = String::new();
|
let message_content = String::new();
|
||||||
|
|
||||||
let instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
|
let instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let timmy_form = PersonInsertForm::test_form(instance.id, "timmy_rav");
|
let timmy_form = PersonInsertForm::test_form(instance.id, "timmy_rav");
|
||||||
|
|
||||||
let timmy = Person::create(pool, &timmy_form).await.unwrap();
|
let timmy = Person::create(pool, &timmy_form).await?;
|
||||||
|
|
||||||
let sara_form = PersonInsertForm::test_form(instance.id, "sara_rav");
|
let sara_form = PersonInsertForm::test_form(instance.id, "sara_rav");
|
||||||
|
|
||||||
let sara = Person::create(pool, &sara_form).await.unwrap();
|
let sara = Person::create(pool, &sara_form).await?;
|
||||||
|
|
||||||
let jess_form = PersonInsertForm::test_form(instance.id, "jess_rav");
|
let jess_form = PersonInsertForm::test_form(instance.id, "jess_rav");
|
||||||
|
|
||||||
let jess = Person::create(pool, &jess_form).await.unwrap();
|
let jess = Person::create(pool, &jess_form).await?;
|
||||||
|
|
||||||
let sara_timmy_message_form =
|
let sara_timmy_message_form =
|
||||||
PrivateMessageInsertForm::new(sara.id, timmy.id, message_content.clone());
|
PrivateMessageInsertForm::new(sara.id, timmy.id, message_content.clone());
|
||||||
PrivateMessage::create(pool, &sara_timmy_message_form)
|
PrivateMessage::create(pool, &sara_timmy_message_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let sara_jess_message_form =
|
let sara_jess_message_form =
|
||||||
PrivateMessageInsertForm::new(sara.id, jess.id, message_content.clone());
|
PrivateMessageInsertForm::new(sara.id, jess.id, message_content.clone());
|
||||||
PrivateMessage::create(pool, &sara_jess_message_form)
|
PrivateMessage::create(pool, &sara_jess_message_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let timmy_sara_message_form =
|
let timmy_sara_message_form =
|
||||||
PrivateMessageInsertForm::new(timmy.id, sara.id, message_content.clone());
|
PrivateMessageInsertForm::new(timmy.id, sara.id, message_content.clone());
|
||||||
PrivateMessage::create(pool, &timmy_sara_message_form)
|
PrivateMessage::create(pool, &timmy_sara_message_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let jess_timmy_message_form =
|
let jess_timmy_message_form =
|
||||||
PrivateMessageInsertForm::new(jess.id, timmy.id, message_content.clone());
|
PrivateMessageInsertForm::new(jess.id, timmy.id, message_content.clone());
|
||||||
PrivateMessage::create(pool, &jess_timmy_message_form)
|
PrivateMessage::create(pool, &jess_timmy_message_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
Ok(Data {
|
Ok(Data {
|
||||||
instance,
|
instance,
|
||||||
@ -255,7 +244,7 @@ mod tests {
|
|||||||
|
|
||||||
async fn cleanup(instance_id: InstanceId, pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
async fn cleanup(instance_id: InstanceId, pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||||
// This also deletes all persons and private messages thanks to sql `on delete cascade`
|
// This also deletes all persons and private messages thanks to sql `on delete cascade`
|
||||||
Instance::delete(pool, instance_id).await.unwrap();
|
Instance::delete(pool, instance_id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,8 +266,7 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(pool, timmy.id)
|
.list(pool, timmy.id)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_length!(3, &timmy_messages);
|
assert_length!(3, &timmy_messages);
|
||||||
assert_eq!(timmy_messages[0].creator.id, jess.id);
|
assert_eq!(timmy_messages[0].creator.id, jess.id);
|
||||||
@ -294,8 +282,7 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(pool, timmy.id)
|
.list(pool, timmy.id)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_length!(2, &timmy_unread_messages);
|
assert_length!(2, &timmy_unread_messages);
|
||||||
assert_eq!(timmy_unread_messages[0].creator.id, jess.id);
|
assert_eq!(timmy_unread_messages[0].creator.id, jess.id);
|
||||||
@ -309,8 +296,7 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(pool, timmy.id)
|
.list(pool, timmy.id)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_length!(2, &timmy_sara_messages);
|
assert_length!(2, &timmy_sara_messages);
|
||||||
assert_eq!(timmy_sara_messages[0].creator.id, timmy.id);
|
assert_eq!(timmy_sara_messages[0].creator.id, timmy.id);
|
||||||
@ -324,8 +310,7 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(pool, timmy.id)
|
.list(pool, timmy.id)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_length!(1, &timmy_sara_unread_messages);
|
assert_length!(1, &timmy_sara_unread_messages);
|
||||||
assert_eq!(timmy_sara_unread_messages[0].creator.id, sara.id);
|
assert_eq!(timmy_sara_unread_messages[0].creator.id, sara.id);
|
||||||
@ -352,9 +337,7 @@ mod tests {
|
|||||||
target_id: sara.id,
|
target_id: sara.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_block = PersonBlock::block(pool, &timmy_blocks_sara_form)
|
let inserted_block = PersonBlock::block(pool, &timmy_blocks_sara_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let expected_block = PersonBlock {
|
let expected_block = PersonBlock {
|
||||||
person_id: timmy.id,
|
person_id: timmy.id,
|
||||||
@ -369,14 +352,11 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(pool, timmy.id)
|
.list(pool, timmy.id)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_length!(1, &timmy_messages);
|
assert_length!(1, &timmy_messages);
|
||||||
|
|
||||||
let timmy_unread_messages = PrivateMessageView::get_unread_messages(pool, timmy.id)
|
let timmy_unread_messages = PrivateMessageView::get_unread_messages(pool, timmy.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(timmy_unread_messages, 1);
|
assert_eq!(timmy_unread_messages, 1);
|
||||||
|
|
||||||
cleanup(instance.id, pool).await
|
cleanup(instance.id, pool).await
|
||||||
@ -399,9 +379,7 @@ mod tests {
|
|||||||
instance_id: sara.instance_id,
|
instance_id: sara.instance_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let inserted_instance_block = InstanceBlock::block(pool, &timmy_blocks_instance_form)
|
let inserted_instance_block = InstanceBlock::block(pool, &timmy_blocks_instance_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let expected_instance_block = InstanceBlock {
|
let expected_instance_block = InstanceBlock {
|
||||||
person_id: timmy.id,
|
person_id: timmy.id,
|
||||||
@ -416,14 +394,11 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(pool, timmy.id)
|
.list(pool, timmy.id)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_length!(0, &timmy_messages);
|
assert_length!(0, &timmy_messages);
|
||||||
|
|
||||||
let timmy_unread_messages = PrivateMessageView::get_unread_messages(pool, timmy.id)
|
let timmy_unread_messages = PrivateMessageView::get_unread_messages(pool, timmy.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(timmy_unread_messages, 0);
|
assert_eq!(timmy_unread_messages, 0);
|
||||||
cleanup(instance.id, pool).await
|
cleanup(instance.id, pool).await
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,6 @@ impl RegistrationApplicationQuery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::registration_application_view::{
|
use crate::registration_application_view::{
|
||||||
@ -156,38 +155,34 @@ 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;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_crud() {
|
async fn test_crud() -> 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 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 timmy_person_form = PersonInsertForm::test_form(inserted_instance.id, "timmy_rav");
|
let timmy_person_form = PersonInsertForm::test_form(inserted_instance.id, "timmy_rav");
|
||||||
|
|
||||||
let inserted_timmy_person = Person::create(pool, &timmy_person_form).await.unwrap();
|
let inserted_timmy_person = Person::create(pool, &timmy_person_form).await?;
|
||||||
|
|
||||||
let timmy_local_user_form = LocalUserInsertForm::test_form_admin(inserted_timmy_person.id);
|
let timmy_local_user_form = LocalUserInsertForm::test_form_admin(inserted_timmy_person.id);
|
||||||
|
|
||||||
let _inserted_timmy_local_user = LocalUser::create(pool, &timmy_local_user_form, vec![])
|
let _inserted_timmy_local_user =
|
||||||
.await
|
LocalUser::create(pool, &timmy_local_user_form, vec![]).await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let sara_person_form = PersonInsertForm::test_form(inserted_instance.id, "sara_rav");
|
let sara_person_form = PersonInsertForm::test_form(inserted_instance.id, "sara_rav");
|
||||||
|
|
||||||
let inserted_sara_person = Person::create(pool, &sara_person_form).await.unwrap();
|
let inserted_sara_person = Person::create(pool, &sara_person_form).await?;
|
||||||
|
|
||||||
let sara_local_user_form = LocalUserInsertForm::test_form(inserted_sara_person.id);
|
let sara_local_user_form = LocalUserInsertForm::test_form(inserted_sara_person.id);
|
||||||
|
|
||||||
let inserted_sara_local_user = LocalUser::create(pool, &sara_local_user_form, vec![])
|
let inserted_sara_local_user = LocalUser::create(pool, &sara_local_user_form, vec![]).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Sara creates an application
|
// Sara creates an application
|
||||||
let sara_app_form = RegistrationApplicationInsertForm {
|
let sara_app_form = RegistrationApplicationInsertForm {
|
||||||
@ -195,23 +190,17 @@ mod tests {
|
|||||||
answer: "LET ME IIIIINN".to_string(),
|
answer: "LET ME IIIIINN".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let sara_app = RegistrationApplication::create(pool, &sara_app_form)
|
let sara_app = RegistrationApplication::create(pool, &sara_app_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let read_sara_app_view = RegistrationApplicationView::read(pool, sara_app.id)
|
let read_sara_app_view = RegistrationApplicationView::read(pool, sara_app.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let jess_person_form = PersonInsertForm::test_form(inserted_instance.id, "jess_rav");
|
let jess_person_form = PersonInsertForm::test_form(inserted_instance.id, "jess_rav");
|
||||||
|
|
||||||
let inserted_jess_person = Person::create(pool, &jess_person_form).await.unwrap();
|
let inserted_jess_person = Person::create(pool, &jess_person_form).await?;
|
||||||
|
|
||||||
let jess_local_user_form = LocalUserInsertForm::test_form(inserted_jess_person.id);
|
let jess_local_user_form = LocalUserInsertForm::test_form(inserted_jess_person.id);
|
||||||
|
|
||||||
let inserted_jess_local_user = LocalUser::create(pool, &jess_local_user_form, vec![])
|
let inserted_jess_local_user = LocalUser::create(pool, &jess_local_user_form, vec![]).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Sara creates an application
|
// Sara creates an application
|
||||||
let jess_app_form = RegistrationApplicationInsertForm {
|
let jess_app_form = RegistrationApplicationInsertForm {
|
||||||
@ -219,13 +208,9 @@ mod tests {
|
|||||||
answer: "LET ME IIIIINN".to_string(),
|
answer: "LET ME IIIIINN".to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let jess_app = RegistrationApplication::create(pool, &jess_app_form)
|
let jess_app = RegistrationApplication::create(pool, &jess_app_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let read_jess_app_view = RegistrationApplicationView::read(pool, jess_app.id)
|
let read_jess_app_view = RegistrationApplicationView::read(pool, jess_app.id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut expected_sara_app_view = RegistrationApplicationView {
|
let mut expected_sara_app_view = RegistrationApplicationView {
|
||||||
registration_application: sara_app.clone(),
|
registration_application: sara_app.clone(),
|
||||||
@ -291,8 +276,7 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(pool)
|
.list(pool)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
apps,
|
apps,
|
||||||
@ -300,9 +284,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let unread_count = RegistrationApplicationView::get_unread_count(pool, false)
|
let unread_count = RegistrationApplicationView::get_unread_count(pool, false).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(unread_count, 2);
|
assert_eq!(unread_count, 2);
|
||||||
|
|
||||||
// Approve the application
|
// Approve the application
|
||||||
@ -311,9 +293,7 @@ mod tests {
|
|||||||
deny_reason: None,
|
deny_reason: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
RegistrationApplication::update(pool, sara_app.id, &approve_form)
|
RegistrationApplication::update(pool, sara_app.id, &approve_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Update the local_user row
|
// Update the local_user row
|
||||||
let approve_local_user_form = LocalUserUpdateForm {
|
let approve_local_user_form = LocalUserUpdateForm {
|
||||||
@ -321,13 +301,10 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
LocalUser::update(pool, inserted_sara_local_user.id, &approve_local_user_form)
|
LocalUser::update(pool, inserted_sara_local_user.id, &approve_local_user_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let read_sara_app_view_after_approve = RegistrationApplicationView::read(pool, sara_app.id)
|
let read_sara_app_view_after_approve =
|
||||||
.await
|
RegistrationApplicationView::read(pool, sara_app.id).await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Make sure the columns changed
|
// Make sure the columns changed
|
||||||
expected_sara_app_view
|
expected_sara_app_view
|
||||||
@ -367,28 +344,23 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(pool)
|
.list(pool)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(apps_after_resolve, vec![read_jess_app_view]);
|
assert_eq!(apps_after_resolve, vec![read_jess_app_view]);
|
||||||
|
|
||||||
// Make sure the counts are correct
|
// Make sure the counts are correct
|
||||||
let unread_count_after_approve = RegistrationApplicationView::get_unread_count(pool, false)
|
let unread_count_after_approve =
|
||||||
.await
|
RegistrationApplicationView::get_unread_count(pool, false).await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(unread_count_after_approve, 1);
|
assert_eq!(unread_count_after_approve, 1);
|
||||||
|
|
||||||
// Make sure the not undenied_only has all the apps
|
// Make sure the not undenied_only has all the apps
|
||||||
let all_apps = RegistrationApplicationQuery::default()
|
let all_apps = RegistrationApplicationQuery::default().list(pool).await?;
|
||||||
.list(pool)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(all_apps.len(), 2);
|
assert_eq!(all_apps.len(), 2);
|
||||||
|
|
||||||
Person::delete(pool, inserted_timmy_person.id)
|
Person::delete(pool, inserted_timmy_person.id).await?;
|
||||||
.await
|
Person::delete(pool, inserted_sara_person.id).await?;
|
||||||
.unwrap();
|
Person::delete(pool, inserted_jess_person.id).await?;
|
||||||
Person::delete(pool, inserted_sara_person.id).await.unwrap();
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
Person::delete(pool, inserted_jess_person.id).await.unwrap();
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,26 +98,25 @@ mod tests {
|
|||||||
traits::{Bannable, Crud, Likeable},
|
traits::{Bannable, Crud, Likeable},
|
||||||
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;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn post_and_comment_vote_views() {
|
async fn post_and_comment_vote_views() -> 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 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 new_person = PersonInsertForm::test_form(inserted_instance.id, "timmy_vv");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "timmy_vv");
|
||||||
|
|
||||||
let inserted_timmy = Person::create(pool, &new_person).await.unwrap();
|
let inserted_timmy = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "sara_vv");
|
let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "sara_vv");
|
||||||
|
|
||||||
let inserted_sara = Person::create(pool, &new_person_2).await.unwrap();
|
let inserted_sara = Person::create(pool, &new_person_2).await?;
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -125,21 +124,21 @@ mod tests {
|
|||||||
"nada".to_owned(),
|
"nada".to_owned(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
|
|
||||||
let new_post = PostInsertForm::new(
|
let new_post = PostInsertForm::new(
|
||||||
"A test post vv".into(),
|
"A test post vv".into(),
|
||||||
inserted_timmy.id,
|
inserted_timmy.id,
|
||||||
inserted_community.id,
|
inserted_community.id,
|
||||||
);
|
);
|
||||||
let inserted_post = Post::create(pool, &new_post).await.unwrap();
|
let inserted_post = Post::create(pool, &new_post).await?;
|
||||||
|
|
||||||
let comment_form = CommentInsertForm::new(
|
let comment_form = CommentInsertForm::new(
|
||||||
inserted_timmy.id,
|
inserted_timmy.id,
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
"A test comment vv".into(),
|
"A test comment vv".into(),
|
||||||
);
|
);
|
||||||
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
let inserted_comment = Comment::create(pool, &comment_form, None).await?;
|
||||||
|
|
||||||
// Timmy upvotes his own post
|
// Timmy upvotes his own post
|
||||||
let timmy_post_vote_form = PostLikeForm {
|
let timmy_post_vote_form = PostLikeForm {
|
||||||
@ -147,7 +146,7 @@ mod tests {
|
|||||||
person_id: inserted_timmy.id,
|
person_id: inserted_timmy.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
PostLike::like(pool, &timmy_post_vote_form).await.unwrap();
|
PostLike::like(pool, &timmy_post_vote_form).await?;
|
||||||
|
|
||||||
// Sara downvotes timmy's post
|
// Sara downvotes timmy's post
|
||||||
let sara_post_vote_form = PostLikeForm {
|
let sara_post_vote_form = PostLikeForm {
|
||||||
@ -155,7 +154,7 @@ mod tests {
|
|||||||
person_id: inserted_sara.id,
|
person_id: inserted_sara.id,
|
||||||
score: -1,
|
score: -1,
|
||||||
};
|
};
|
||||||
PostLike::like(pool, &sara_post_vote_form).await.unwrap();
|
PostLike::like(pool, &sara_post_vote_form).await?;
|
||||||
|
|
||||||
let expected_post_vote_views = [
|
let expected_post_vote_views = [
|
||||||
VoteView {
|
VoteView {
|
||||||
@ -170,9 +169,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let read_post_vote_views = VoteView::list_for_post(pool, inserted_post.id, None, None)
|
let read_post_vote_views = VoteView::list_for_post(pool, inserted_post.id, None, None).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(read_post_vote_views, expected_post_vote_views);
|
assert_eq!(read_post_vote_views, expected_post_vote_views);
|
||||||
|
|
||||||
// Timothy votes down his own comment
|
// Timothy votes down his own comment
|
||||||
@ -182,9 +179,7 @@ mod tests {
|
|||||||
person_id: inserted_timmy.id,
|
person_id: inserted_timmy.id,
|
||||||
score: -1,
|
score: -1,
|
||||||
};
|
};
|
||||||
CommentLike::like(pool, &timmy_comment_vote_form)
|
CommentLike::like(pool, &timmy_comment_vote_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Sara upvotes timmy's comment
|
// Sara upvotes timmy's comment
|
||||||
let sara_comment_vote_form = CommentLikeForm {
|
let sara_comment_vote_form = CommentLikeForm {
|
||||||
@ -193,9 +188,7 @@ mod tests {
|
|||||||
person_id: inserted_sara.id,
|
person_id: inserted_sara.id,
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
CommentLike::like(pool, &sara_comment_vote_form)
|
CommentLike::like(pool, &sara_comment_vote_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let expected_comment_vote_views = [
|
let expected_comment_vote_views = [
|
||||||
VoteView {
|
VoteView {
|
||||||
@ -210,9 +203,8 @@ mod tests {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let read_comment_vote_views = VoteView::list_for_comment(pool, inserted_comment.id, None, None)
|
let read_comment_vote_views =
|
||||||
.await
|
VoteView::list_for_comment(pool, inserted_comment.id, None, None).await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(read_comment_vote_views, expected_comment_vote_views);
|
assert_eq!(read_comment_vote_views, expected_comment_vote_views);
|
||||||
|
|
||||||
// Ban timmy from that community
|
// Ban timmy from that community
|
||||||
@ -221,15 +213,11 @@ mod tests {
|
|||||||
person_id: inserted_timmy.id,
|
person_id: inserted_timmy.id,
|
||||||
expires: None,
|
expires: None,
|
||||||
};
|
};
|
||||||
CommunityPersonBan::ban(pool, &ban_timmy_form)
|
CommunityPersonBan::ban(pool, &ban_timmy_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Make sure creator_banned_from_community is true
|
// Make sure creator_banned_from_community is true
|
||||||
let read_comment_vote_views_after_ban =
|
let read_comment_vote_views_after_ban =
|
||||||
VoteView::list_for_comment(pool, inserted_comment.id, None, None)
|
VoteView::list_for_comment(pool, inserted_comment.id, None, None).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
read_comment_vote_views_after_ban
|
read_comment_vote_views_after_ban
|
||||||
@ -239,9 +227,7 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let read_post_vote_views_after_ban =
|
let read_post_vote_views_after_ban =
|
||||||
VoteView::list_for_post(pool, inserted_post.id, None, None)
|
VoteView::list_for_post(pool, inserted_post.id, None, None).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
read_post_vote_views_after_ban
|
read_post_vote_views_after_ban
|
||||||
@ -251,6 +237,8 @@ mod tests {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Instance::delete(pool, inserted_instance.id).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,6 @@ impl<'a> CommunityQuery<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::{community_view::CommunityQuery, structs::CommunityView};
|
use crate::{community_view::CommunityQuery, structs::CommunityView};
|
||||||
@ -264,6 +263,7 @@ mod tests {
|
|||||||
utils::{build_db_pool_for_tests, DbPool},
|
utils::{build_db_pool_for_tests, DbPool},
|
||||||
CommunityVisibility,
|
CommunityVisibility,
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
@ -274,21 +274,17 @@ mod tests {
|
|||||||
site: Site,
|
site: Site,
|
||||||
}
|
}
|
||||||
|
|
||||||
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 person_name = "tegan".to_string();
|
let person_name = "tegan".to_string();
|
||||||
|
|
||||||
let new_person = PersonInsertForm::test_form(inserted_instance.id, &person_name);
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, &person_name);
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
let inserted_person = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let local_user_form = LocalUserInsertForm::test_form(inserted_person.id);
|
let local_user_form = LocalUserInsertForm::test_form(inserted_person.id);
|
||||||
let local_user = LocalUser::create(pool, &local_user_form, vec![])
|
let local_user = LocalUser::create(pool, &local_user_form, vec![]).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let new_community = CommunityInsertForm::new(
|
let new_community = CommunityInsertForm::new(
|
||||||
inserted_instance.id,
|
inserted_instance.id,
|
||||||
@ -296,9 +292,9 @@ mod tests {
|
|||||||
"nada".to_owned(),
|
"nada".to_owned(),
|
||||||
"pubkey".to_string(),
|
"pubkey".to_string(),
|
||||||
);
|
);
|
||||||
let inserted_community = Community::create(pool, &new_community).await.unwrap();
|
let inserted_community = Community::create(pool, &new_community).await?;
|
||||||
|
|
||||||
let url = Url::parse("http://example.com").unwrap();
|
let url = Url::parse("http://example.com")?;
|
||||||
let site = Site {
|
let site = Site {
|
||||||
id: Default::default(),
|
id: Default::default(),
|
||||||
name: String::new(),
|
name: String::new(),
|
||||||
@ -317,32 +313,28 @@ mod tests {
|
|||||||
content_warning: None,
|
content_warning: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Data {
|
Ok(Data {
|
||||||
inserted_instance,
|
inserted_instance,
|
||||||
local_user,
|
local_user,
|
||||||
inserted_community,
|
inserted_community,
|
||||||
site,
|
site,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(data: Data, pool: &mut DbPool<'_>) {
|
async fn cleanup(data: Data, pool: &mut DbPool<'_>) -> LemmyResult<()> {
|
||||||
Community::delete(pool, data.inserted_community.id)
|
Community::delete(pool, data.inserted_community.id).await?;
|
||||||
.await
|
Person::delete(pool, data.local_user.person_id).await?;
|
||||||
.unwrap();
|
Instance::delete(pool, data.inserted_instance.id).await?;
|
||||||
Person::delete(pool, data.local_user.person_id)
|
|
||||||
.await
|
Ok(())
|
||||||
.unwrap();
|
|
||||||
Instance::delete(pool, data.inserted_instance.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn local_only_community() {
|
async fn local_only_community() -> 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?;
|
||||||
|
|
||||||
Community::update(
|
Community::update(
|
||||||
pool,
|
pool,
|
||||||
@ -352,15 +344,13 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let unauthenticated_query = CommunityQuery {
|
let unauthenticated_query = CommunityQuery {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(&data.site, pool)
|
.list(&data.site, pool)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(0, unauthenticated_query.len());
|
assert_eq!(0, unauthenticated_query.len());
|
||||||
|
|
||||||
let authenticated_query = CommunityQuery {
|
let authenticated_query = CommunityQuery {
|
||||||
@ -368,8 +358,7 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
.list(&data.site, pool)
|
.list(&data.site, pool)
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(1, authenticated_query.len());
|
assert_eq!(1, authenticated_query.len());
|
||||||
|
|
||||||
let unauthenticated_community =
|
let unauthenticated_community =
|
||||||
@ -385,6 +374,6 @@ mod tests {
|
|||||||
.await;
|
.await;
|
||||||
assert!(authenticated_community.is_ok());
|
assert!(authenticated_community.is_ok());
|
||||||
|
|
||||||
cleanup(data, pool).await;
|
cleanup(data, pool).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,6 +230,7 @@ mod tests {
|
|||||||
newtypes::{ActivityId, CommunityId, InstanceId, SiteId},
|
newtypes::{ActivityId, CommunityId, InstanceId, SiteId},
|
||||||
source::activity::{ActorType, SentActivity},
|
source::activity::{ActorType, SentActivity},
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use mockall::{mock, predicate::*};
|
use mockall::{mock, predicate::*};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
mock! {
|
mock! {
|
||||||
@ -253,13 +254,11 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_inbox_urls_empty() {
|
async fn test_get_inbox_urls_empty() -> LemmyResult<()> {
|
||||||
let mut collector = setup_collector();
|
let mut collector = setup_collector();
|
||||||
let activity = SentActivity {
|
let activity = SentActivity {
|
||||||
id: ActivityId(1),
|
id: ActivityId(1),
|
||||||
ap_id: Url::parse("https://example.com/activities/1")
|
ap_id: Url::parse("https://example.com/activities/1")?.into(),
|
||||||
.unwrap()
|
|
||||||
.into(),
|
|
||||||
data: json!({}),
|
data: json!({}),
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
published: Utc::now(),
|
published: Utc::now(),
|
||||||
@ -270,14 +269,16 @@ mod tests {
|
|||||||
actor_apub_id: None,
|
actor_apub_id: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = collector.get_inbox_urls(&activity).await.unwrap();
|
let result = collector.get_inbox_urls(&activity).await?;
|
||||||
assert!(result.is_empty());
|
assert!(result.is_empty());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_inbox_urls_send_all_instances() {
|
async fn test_get_inbox_urls_send_all_instances() -> LemmyResult<()> {
|
||||||
let mut collector = setup_collector();
|
let mut collector = setup_collector();
|
||||||
let site_inbox = Url::parse("https://example.com/inbox").unwrap();
|
let site_inbox = Url::parse("https://example.com/inbox")?;
|
||||||
let site = Site {
|
let site = Site {
|
||||||
id: SiteId(1),
|
id: SiteId(1),
|
||||||
name: "Test Site".to_string(),
|
name: "Test Site".to_string(),
|
||||||
@ -287,7 +288,7 @@ mod tests {
|
|||||||
icon: None,
|
icon: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
description: None,
|
description: None,
|
||||||
actor_id: Url::parse("https://example.com/site").unwrap().into(),
|
actor_id: Url::parse("https://example.com/site")?.into(),
|
||||||
last_refreshed_at: Utc::now(),
|
last_refreshed_at: Utc::now(),
|
||||||
inbox_url: site_inbox.clone().into(),
|
inbox_url: site_inbox.clone().into(),
|
||||||
private_key: None,
|
private_key: None,
|
||||||
@ -303,9 +304,7 @@ mod tests {
|
|||||||
|
|
||||||
let activity = SentActivity {
|
let activity = SentActivity {
|
||||||
id: ActivityId(1),
|
id: ActivityId(1),
|
||||||
ap_id: Url::parse("https://example.com/activities/1")
|
ap_id: Url::parse("https://example.com/activities/1")?.into(),
|
||||||
.unwrap()
|
|
||||||
.into(),
|
|
||||||
data: json!({}),
|
data: json!({}),
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
published: Utc::now(),
|
published: Utc::now(),
|
||||||
@ -316,13 +315,15 @@ mod tests {
|
|||||||
actor_apub_id: None,
|
actor_apub_id: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = collector.get_inbox_urls(&activity).await.unwrap();
|
let result = collector.get_inbox_urls(&activity).await?;
|
||||||
assert_eq!(result.len(), 1);
|
assert_eq!(result.len(), 1);
|
||||||
assert_eq!(result[0], site_inbox);
|
assert_eq!(result[0], site_inbox);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_inbox_urls_community_followers() {
|
async fn test_get_inbox_urls_community_followers() -> LemmyResult<()> {
|
||||||
let mut collector = setup_collector();
|
let mut collector = setup_collector();
|
||||||
let community_id = CommunityId(1);
|
let community_id = CommunityId(1);
|
||||||
let url1 = "https://follower1.example.com/inbox";
|
let url1 = "https://follower1.example.com/inbox";
|
||||||
@ -338,13 +339,11 @@ mod tests {
|
|||||||
])
|
])
|
||||||
});
|
});
|
||||||
|
|
||||||
collector.update_communities().await.unwrap();
|
collector.update_communities().await?;
|
||||||
|
|
||||||
let activity = SentActivity {
|
let activity = SentActivity {
|
||||||
id: ActivityId(1),
|
id: ActivityId(1),
|
||||||
ap_id: Url::parse("https://example.com/activities/1")
|
ap_id: Url::parse("https://example.com/activities/1")?.into(),
|
||||||
.unwrap()
|
|
||||||
.into(),
|
|
||||||
data: json!({}),
|
data: json!({}),
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
published: Utc::now(),
|
published: Utc::now(),
|
||||||
@ -355,24 +354,24 @@ mod tests {
|
|||||||
actor_apub_id: None,
|
actor_apub_id: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = collector.get_inbox_urls(&activity).await.unwrap();
|
let result = collector.get_inbox_urls(&activity).await?;
|
||||||
assert_eq!(result.len(), 2);
|
assert_eq!(result.len(), 2);
|
||||||
assert!(result.contains(&Url::parse(url1).unwrap()));
|
assert!(result.contains(&Url::parse(url1)?));
|
||||||
assert!(result.contains(&Url::parse(url2).unwrap()));
|
assert!(result.contains(&Url::parse(url2)?));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_inbox_urls_send_inboxes() {
|
async fn test_get_inbox_urls_send_inboxes() -> LemmyResult<()> {
|
||||||
let mut collector = setup_collector();
|
let mut collector = setup_collector();
|
||||||
collector.domain = "example.com".to_string();
|
collector.domain = "example.com".to_string();
|
||||||
let inbox_user_1 = Url::parse("https://example.com/user1/inbox").unwrap();
|
let inbox_user_1 = Url::parse("https://example.com/user1/inbox")?;
|
||||||
let inbox_user_2 = Url::parse("https://example.com/user2/inbox").unwrap();
|
let inbox_user_2 = Url::parse("https://example.com/user2/inbox")?;
|
||||||
let other_domain_inbox = Url::parse("https://other-domain.com/user3/inbox").unwrap();
|
let other_domain_inbox = Url::parse("https://other-domain.com/user3/inbox")?;
|
||||||
let activity = SentActivity {
|
let activity = SentActivity {
|
||||||
id: ActivityId(1),
|
id: ActivityId(1),
|
||||||
ap_id: Url::parse("https://example.com/activities/1")
|
ap_id: Url::parse("https://example.com/activities/1")?.into(),
|
||||||
.unwrap()
|
|
||||||
.into(),
|
|
||||||
data: json!({}),
|
data: json!({}),
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
published: Utc::now(),
|
published: Utc::now(),
|
||||||
@ -387,20 +386,22 @@ mod tests {
|
|||||||
actor_apub_id: None,
|
actor_apub_id: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = collector.get_inbox_urls(&activity).await.unwrap();
|
let result = collector.get_inbox_urls(&activity).await?;
|
||||||
assert_eq!(result.len(), 2);
|
assert_eq!(result.len(), 2);
|
||||||
assert!(result.contains(&inbox_user_1));
|
assert!(result.contains(&inbox_user_1));
|
||||||
assert!(result.contains(&inbox_user_2));
|
assert!(result.contains(&inbox_user_2));
|
||||||
assert!(!result.contains(&other_domain_inbox));
|
assert!(!result.contains(&other_domain_inbox));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_inbox_urls_combined() {
|
async fn test_get_inbox_urls_combined() -> LemmyResult<()> {
|
||||||
let mut collector = setup_collector();
|
let mut collector = setup_collector();
|
||||||
collector.domain = "example.com".to_string();
|
collector.domain = "example.com".to_string();
|
||||||
let community_id = CommunityId(1);
|
let community_id = CommunityId(1);
|
||||||
|
|
||||||
let site_inbox = Url::parse("https://example.com/site_inbox").unwrap();
|
let site_inbox = Url::parse("https://example.com/site_inbox")?;
|
||||||
let site = Site {
|
let site = Site {
|
||||||
id: SiteId(1),
|
id: SiteId(1),
|
||||||
name: "Test Site".to_string(),
|
name: "Test Site".to_string(),
|
||||||
@ -410,7 +411,7 @@ mod tests {
|
|||||||
icon: None,
|
icon: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
description: None,
|
description: None,
|
||||||
actor_id: Url::parse("https://example.com/site").unwrap().into(),
|
actor_id: Url::parse("https://example.com/site")?.into(),
|
||||||
last_refreshed_at: Utc::now(),
|
last_refreshed_at: Utc::now(),
|
||||||
inbox_url: site_inbox.clone().into(),
|
inbox_url: site_inbox.clone().into(),
|
||||||
private_key: None,
|
private_key: None,
|
||||||
@ -435,14 +436,12 @@ mod tests {
|
|||||||
)])
|
)])
|
||||||
});
|
});
|
||||||
|
|
||||||
collector.update_communities().await.unwrap();
|
collector.update_communities().await?;
|
||||||
let user1_inbox = Url::parse("https://example.com/user1/inbox").unwrap();
|
let user1_inbox = Url::parse("https://example.com/user1/inbox")?;
|
||||||
let user2_inbox = Url::parse("https://other-domain.com/user2/inbox").unwrap();
|
let user2_inbox = Url::parse("https://other-domain.com/user2/inbox")?;
|
||||||
let activity = SentActivity {
|
let activity = SentActivity {
|
||||||
id: ActivityId(1),
|
id: ActivityId(1),
|
||||||
ap_id: Url::parse("https://example.com/activities/1")
|
ap_id: Url::parse("https://example.com/activities/1")?.into(),
|
||||||
.unwrap()
|
|
||||||
.into(),
|
|
||||||
data: json!({}),
|
data: json!({}),
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
published: Utc::now(),
|
published: Utc::now(),
|
||||||
@ -456,27 +455,29 @@ mod tests {
|
|||||||
actor_apub_id: None,
|
actor_apub_id: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = collector.get_inbox_urls(&activity).await.unwrap();
|
let result = collector.get_inbox_urls(&activity).await?;
|
||||||
assert_eq!(result.len(), 3);
|
assert_eq!(result.len(), 3);
|
||||||
assert!(result.contains(&site_inbox));
|
assert!(result.contains(&site_inbox));
|
||||||
assert!(result.contains(&Url::parse(subdomain_inbox).unwrap()));
|
assert!(result.contains(&Url::parse(subdomain_inbox)?));
|
||||||
assert!(result.contains(&user1_inbox));
|
assert!(result.contains(&user1_inbox));
|
||||||
assert!(!result.contains(&user2_inbox));
|
assert!(!result.contains(&user2_inbox));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_update_communities() {
|
async fn test_update_communities() -> LemmyResult<()> {
|
||||||
let mut collector = setup_collector();
|
let mut collector = setup_collector();
|
||||||
let community_id1 = CommunityId(1);
|
let community_id1 = CommunityId(1);
|
||||||
let community_id2 = CommunityId(2);
|
let community_id2 = CommunityId(2);
|
||||||
let community_id3 = CommunityId(3);
|
let community_id3 = CommunityId(3);
|
||||||
|
|
||||||
let user1_inbox_str = "https://follower1.example.com/inbox";
|
let user1_inbox_str = "https://follower1.example.com/inbox";
|
||||||
let user1_inbox = Url::parse(user1_inbox_str).unwrap();
|
let user1_inbox = Url::parse(user1_inbox_str)?;
|
||||||
let user2_inbox_str = "https://follower2.example.com/inbox";
|
let user2_inbox_str = "https://follower2.example.com/inbox";
|
||||||
let user2_inbox = Url::parse(user2_inbox_str).unwrap();
|
let user2_inbox = Url::parse(user2_inbox_str)?;
|
||||||
let user3_inbox_str = "https://follower3.example.com/inbox";
|
let user3_inbox_str = "https://follower3.example.com/inbox";
|
||||||
let user3_inbox = Url::parse(user3_inbox_str).unwrap();
|
let user3_inbox = Url::parse(user3_inbox_str)?;
|
||||||
|
|
||||||
collector
|
collector
|
||||||
.data_source
|
.data_source
|
||||||
@ -497,30 +498,33 @@ mod tests {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// First update
|
// First update
|
||||||
collector.update_communities().await.unwrap();
|
collector.update_communities().await?;
|
||||||
assert_eq!(collector.followed_communities.len(), 2);
|
assert_eq!(collector.followed_communities.len(), 2);
|
||||||
assert!(collector.followed_communities[&community_id1].contains(&user1_inbox));
|
assert!(collector.followed_communities[&community_id1].contains(&user1_inbox));
|
||||||
assert!(collector.followed_communities[&community_id2].contains(&user2_inbox));
|
assert!(collector.followed_communities[&community_id2].contains(&user2_inbox));
|
||||||
|
|
||||||
// Simulate time passing
|
// Simulate time passing
|
||||||
collector.last_full_communities_fetch = Utc::now() - chrono::TimeDelta::try_minutes(3).unwrap();
|
collector.last_full_communities_fetch =
|
||||||
|
Utc::now() - chrono::TimeDelta::try_minutes(3).expect("TimeDelta out of bounds");
|
||||||
collector.last_incremental_communities_fetch =
|
collector.last_incremental_communities_fetch =
|
||||||
Utc::now() - chrono::TimeDelta::try_minutes(3).unwrap();
|
Utc::now() - chrono::TimeDelta::try_minutes(3).expect("TimeDelta out of bounds");
|
||||||
|
|
||||||
// Second update (incremental)
|
// Second update (incremental)
|
||||||
collector.update_communities().await.unwrap();
|
collector.update_communities().await?;
|
||||||
assert_eq!(collector.followed_communities.len(), 3);
|
assert_eq!(collector.followed_communities.len(), 3);
|
||||||
assert!(collector.followed_communities[&community_id1].contains(&user1_inbox));
|
assert!(collector.followed_communities[&community_id1].contains(&user1_inbox));
|
||||||
assert!(collector.followed_communities[&community_id3].contains(&user3_inbox));
|
assert!(collector.followed_communities[&community_id3].contains(&user3_inbox));
|
||||||
assert!(collector.followed_communities[&community_id2].contains(&user2_inbox));
|
assert!(collector.followed_communities[&community_id2].contains(&user2_inbox));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_inbox_urls_no_duplicates() {
|
async fn test_get_inbox_urls_no_duplicates() -> LemmyResult<()> {
|
||||||
let mut collector = setup_collector();
|
let mut collector = setup_collector();
|
||||||
collector.domain = "example.com".to_string();
|
collector.domain = "example.com".to_string();
|
||||||
let community_id = CommunityId(1);
|
let community_id = CommunityId(1);
|
||||||
let site_inbox = Url::parse("https://example.com/site_inbox").unwrap();
|
let site_inbox = Url::parse("https://example.com/site_inbox")?;
|
||||||
let site_inbox_clone = site_inbox.clone();
|
let site_inbox_clone = site_inbox.clone();
|
||||||
let site = Site {
|
let site = Site {
|
||||||
id: SiteId(1),
|
id: SiteId(1),
|
||||||
@ -531,7 +535,7 @@ mod tests {
|
|||||||
icon: None,
|
icon: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
description: None,
|
description: None,
|
||||||
actor_id: Url::parse("https://example.com/site").unwrap().into(),
|
actor_id: Url::parse("https://example.com/site")?.into(),
|
||||||
last_refreshed_at: Utc::now(),
|
last_refreshed_at: Utc::now(),
|
||||||
inbox_url: site_inbox.clone().into(),
|
inbox_url: site_inbox.clone().into(),
|
||||||
private_key: None,
|
private_key: None,
|
||||||
@ -550,13 +554,11 @@ mod tests {
|
|||||||
.expect_get_instance_followed_community_inboxes()
|
.expect_get_instance_followed_community_inboxes()
|
||||||
.return_once(move |_, _| Ok(vec![(community_id, site_inbox_clone.into())]));
|
.return_once(move |_, _| Ok(vec![(community_id, site_inbox_clone.into())]));
|
||||||
|
|
||||||
collector.update_communities().await.unwrap();
|
collector.update_communities().await?;
|
||||||
|
|
||||||
let activity = SentActivity {
|
let activity = SentActivity {
|
||||||
id: ActivityId(1),
|
id: ActivityId(1),
|
||||||
ap_id: Url::parse("https://example.com/activities/1")
|
ap_id: Url::parse("https://example.com/activities/1")?.into(),
|
||||||
.unwrap()
|
|
||||||
.into(),
|
|
||||||
data: json!({}),
|
data: json!({}),
|
||||||
sensitive: false,
|
sensitive: false,
|
||||||
published: Utc::now(),
|
published: Utc::now(),
|
||||||
@ -567,8 +569,10 @@ mod tests {
|
|||||||
actor_apub_id: None,
|
actor_apub_id: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = collector.get_inbox_urls(&activity).await.unwrap();
|
let result = collector.get_inbox_urls(&activity).await?;
|
||||||
assert_eq!(result.len(), 1);
|
assert_eq!(result.len(), 1);
|
||||||
assert!(result.contains(&Url::parse("https://example.com/site_inbox").unwrap()));
|
assert!(result.contains(&Url::parse("https://example.com/site_inbox")?));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,21 +297,25 @@ cfg_if! {
|
|||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserializes_no_message() {
|
fn deserializes_no_message() -> LemmyResult<()> {
|
||||||
let err = LemmyError::from(LemmyErrorType::Banned).error_response();
|
let err = LemmyError::from(LemmyErrorType::Banned).error_response();
|
||||||
let json = String::from_utf8(err.into_body().try_into_bytes().unwrap().to_vec()).unwrap();
|
let json = String::from_utf8(err.into_body().try_into_bytes().unwrap().to_vec())?;
|
||||||
assert_eq!(&json, "{\"error\":\"banned\"}")
|
assert_eq!(&json, "{\"error\":\"banned\"}");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserializes_with_message() {
|
fn deserializes_with_message() -> LemmyResult<()> {
|
||||||
let reg_banned = LemmyErrorType::PersonIsBannedFromSite(String::from("reason"));
|
let reg_banned = LemmyErrorType::PersonIsBannedFromSite(String::from("reason"));
|
||||||
let err = LemmyError::from(reg_banned).error_response();
|
let err = LemmyError::from(reg_banned).error_response();
|
||||||
let json = String::from_utf8(err.into_body().try_into_bytes().unwrap().to_vec()).unwrap();
|
let json = String::from_utf8(err.into_body().try_into_bytes().unwrap().to_vec())?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&json,
|
&json,
|
||||||
"{\"error\":\"person_is_banned_from_site\",\"message\":\"reason\"}"
|
"{\"error\":\"person_is_banned_from_site\",\"message\":\"reason\"}"
|
||||||
)
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -328,19 +332,21 @@ cfg_if! {
|
|||||||
/// Check if errors match translations. Disabled because many are not translated at all.
|
/// Check if errors match translations. Disabled because many are not translated at all.
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
#[ignore]
|
||||||
fn test_translations_match() {
|
fn test_translations_match() -> LemmyResult<()> {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct Err {
|
struct Err {
|
||||||
error: String,
|
error: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
let translations = read_to_string("translations/translations/en.json").unwrap();
|
let translations = read_to_string("translations/translations/en.json")?;
|
||||||
LemmyErrorType::iter().for_each(|e| {
|
LemmyErrorType::iter().for_each(|e| {
|
||||||
let msg = serde_json::to_string(&e).unwrap();
|
let msg = serde_json::to_string(&e).unwrap();
|
||||||
let msg: Err = serde_json::from_str(&msg).unwrap();
|
let msg: Err = serde_json::from_str(&msg).unwrap();
|
||||||
let msg = msg.error;
|
let msg = msg.error;
|
||||||
assert!(translations.contains(&format!("\"{msg}\"")), "{msg}");
|
assert!(translations.contains(&format!("\"{msg}\"")), "{msg}");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,10 +308,10 @@ fn split_ipv6(ip: Ipv6Addr) -> ([u8; 6], u8, u8) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::{ActionType, BucketConfig, InstantSecs, RateLimitState, RateLimitedGroup};
|
use super::{ActionType, BucketConfig, InstantSecs, RateLimitState, RateLimitedGroup};
|
||||||
|
use crate::error::LemmyResult;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -326,7 +326,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rate_limiter() {
|
fn test_rate_limiter() -> LemmyResult<()> {
|
||||||
let bucket_configs = enum_map::enum_map! {
|
let bucket_configs = enum_map::enum_map! {
|
||||||
ActionType::Message => BucketConfig {
|
ActionType::Message => BucketConfig {
|
||||||
capacity: 2,
|
capacity: 2,
|
||||||
@ -350,7 +350,7 @@ mod tests {
|
|||||||
"1:2:3:0405:6::",
|
"1:2:3:0405:6::",
|
||||||
];
|
];
|
||||||
for ip in ips {
|
for ip in ips {
|
||||||
let ip = ip.parse().unwrap();
|
let ip = ip.parse()?;
|
||||||
let message_passed = rate_limiter.check(ActionType::Message, ip, now);
|
let message_passed = rate_limiter.check(ActionType::Message, ip, now);
|
||||||
let post_passed = rate_limiter.check(ActionType::Post, ip, now);
|
let post_passed = rate_limiter.check(ActionType::Post, ip, now);
|
||||||
assert!(message_passed);
|
assert!(message_passed);
|
||||||
@ -407,7 +407,7 @@ mod tests {
|
|||||||
|
|
||||||
// Do 2 `Message` actions for 1 IP address and expect only the 2nd one to fail
|
// Do 2 `Message` actions for 1 IP address and expect only the 2nd one to fail
|
||||||
for expected_to_pass in [true, false] {
|
for expected_to_pass in [true, false] {
|
||||||
let ip = "1:2:3:0400::".parse().unwrap();
|
let ip = "1:2:3:0400::".parse()?;
|
||||||
let passed = rate_limiter.check(ActionType::Message, ip, now);
|
let passed = rate_limiter.check(ActionType::Message, ip, now);
|
||||||
assert_eq!(passed, expected_to_pass);
|
assert_eq!(passed, expected_to_pass);
|
||||||
}
|
}
|
||||||
@ -419,7 +419,7 @@ mod tests {
|
|||||||
assert!(rate_limiter.ipv6_buckets.is_empty());
|
assert!(rate_limiter.ipv6_buckets.is_empty());
|
||||||
|
|
||||||
// `remove full buckets` should not remove empty buckets
|
// `remove full buckets` should not remove empty buckets
|
||||||
let ip = "1.1.1.1".parse().unwrap();
|
let ip = "1.1.1.1".parse()?;
|
||||||
// empty the bucket with 2 requests
|
// empty the bucket with 2 requests
|
||||||
assert!(rate_limiter.check(ActionType::Post, ip, now));
|
assert!(rate_limiter.check(ActionType::Post, ip, now));
|
||||||
assert!(rate_limiter.check(ActionType::Post, ip, now));
|
assert!(rate_limiter.check(ActionType::Post, ip, now));
|
||||||
@ -429,11 +429,13 @@ mod tests {
|
|||||||
|
|
||||||
// `remove full buckets` should not remove partial buckets
|
// `remove full buckets` should not remove partial buckets
|
||||||
now.secs += 2;
|
now.secs += 2;
|
||||||
let ip = "1.1.1.1".parse().unwrap();
|
let ip = "1.1.1.1".parse()?;
|
||||||
// Only make one request, so bucket still has 1 token
|
// Only make one request, so bucket still has 1 token
|
||||||
assert!(rate_limiter.check(ActionType::Post, ip, now));
|
assert!(rate_limiter.check(ActionType::Post, ip, now));
|
||||||
|
|
||||||
rate_limiter.remove_full_buckets(now);
|
rate_limiter.remove_full_buckets(now);
|
||||||
assert!(!rate_limiter.ipv4_buckets.is_empty());
|
assert!(!rate_limiter.ipv4_buckets.is_empty());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,6 @@ pub fn markdown_check_for_blocked_urls(text: &str, blocklist: &RegexSet) -> Lemm
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -245,8 +244,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_url_blocking() {
|
fn test_url_blocking() -> LemmyResult<()> {
|
||||||
let set = RegexSet::new(vec![r"(https://)?example\.com/?"]).unwrap();
|
let set = RegexSet::new(vec![r"(https://)?example\.com/?"])?;
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
markdown_check_for_blocked_urls(&String::from("[](https://example.com)"), &set).is_err()
|
markdown_check_for_blocked_urls(&String::from("[](https://example.com)"), &set).is_err()
|
||||||
@ -274,7 +273,7 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.is_err());
|
.is_err());
|
||||||
|
|
||||||
let set = RegexSet::new(vec![r"(https://)?example\.com/spam\.jpg"]).unwrap();
|
let set = RegexSet::new(vec![r"(https://)?example\.com/spam\.jpg"])?;
|
||||||
assert!(markdown_check_for_blocked_urls(
|
assert!(markdown_check_for_blocked_urls(
|
||||||
&String::from("![](https://example.com/spam.jpg)"),
|
&String::from("![](https://example.com/spam.jpg)"),
|
||||||
&set
|
&set
|
||||||
@ -285,8 +284,7 @@ mod tests {
|
|||||||
r"(https://)?quo\.example\.com/?",
|
r"(https://)?quo\.example\.com/?",
|
||||||
r"(https://)?foo\.example\.com/?",
|
r"(https://)?foo\.example\.com/?",
|
||||||
r"(https://)?bar\.example\.com/?",
|
r"(https://)?bar\.example\.com/?",
|
||||||
])
|
])?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
markdown_check_for_blocked_urls(&String::from("https://baz.example.com"), &set).is_ok()
|
markdown_check_for_blocked_urls(&String::from("https://baz.example.com"), &set).is_ok()
|
||||||
@ -296,15 +294,17 @@ mod tests {
|
|||||||
markdown_check_for_blocked_urls(&String::from("https://bar.example.com"), &set).is_err()
|
markdown_check_for_blocked_urls(&String::from("https://bar.example.com"), &set).is_err()
|
||||||
);
|
);
|
||||||
|
|
||||||
let set = RegexSet::new(vec![r"(https://)?example\.com/banned_page"]).unwrap();
|
let set = RegexSet::new(vec![r"(https://)?example\.com/banned_page"])?;
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
markdown_check_for_blocked_urls(&String::from("https://example.com/page"), &set).is_ok()
|
markdown_check_for_blocked_urls(&String::from("https://example.com/page"), &set).is_ok()
|
||||||
);
|
);
|
||||||
|
|
||||||
let set = RegexSet::new(vec![r"(https://)?ex\.mple\.com/?"]).unwrap();
|
let set = RegexSet::new(vec![r"(https://)?ex\.mple\.com/?"])?;
|
||||||
|
|
||||||
assert!(markdown_check_for_blocked_urls("example.com", &set).is_ok());
|
assert!(markdown_check_for_blocked_urls("example.com", &set).is_ok());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -61,16 +61,18 @@ pub(crate) fn slurs_vec_to_str(slurs: &[&str]) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[expect(clippy::unwrap_used)]
|
|
||||||
mod test {
|
mod test {
|
||||||
|
|
||||||
use crate::utils::slurs::{remove_slurs, slur_check, slurs_vec_to_str};
|
use crate::{
|
||||||
|
error::LemmyResult,
|
||||||
|
utils::slurs::{remove_slurs, slur_check, slurs_vec_to_str},
|
||||||
|
};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use regex::RegexBuilder;
|
use regex::RegexBuilder;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_slur_filter() {
|
fn test_slur_filter() -> LemmyResult<()> {
|
||||||
let slur_regex = Some(RegexBuilder::new(r"(fag(g|got|tard)?\b|cock\s?sucker(s|ing)?|ni((g{2,}|q)+|[gq]{2,})[e3r]+(s|z)?|mudslime?s?|kikes?|\bspi(c|k)s?\b|\bchinks?|gooks?|bitch(es|ing|y)?|whor(es?|ing)|\btr(a|@)nn?(y|ies?)|\b(b|re|r)tard(ed)?s?)").case_insensitive(true).build().unwrap());
|
let slur_regex = Some(RegexBuilder::new(r"(fag(g|got|tard)?\b|cock\s?sucker(s|ing)?|ni((g{2,}|q)+|[gq]{2,})[e3r]+(s|z)?|mudslime?s?|kikes?|\bspi(c|k)s?\b|\bchinks?|gooks?|bitch(es|ing|y)?|whor(es?|ing)|\btr(a|@)nn?(y|ies?)|\b(b|re|r)tard(ed)?s?)").case_insensitive(true).build()?);
|
||||||
let test =
|
let test =
|
||||||
"faggot test kike tranny cocksucker retardeds. Capitalized Niggerz. This is a bunch of other safe text.";
|
"faggot test kike tranny cocksucker retardeds. Capitalized Niggerz. This is a bunch of other safe text.";
|
||||||
let slur_free = "No slurs here";
|
let slur_free = "No slurs here";
|
||||||
@ -95,6 +97,8 @@ mod test {
|
|||||||
if let Err(slur_vec) = slur_check(test, &slur_regex) {
|
if let Err(slur_vec) = slur_check(test, &slur_regex) {
|
||||||
assert_eq!(&slurs_vec_to_str(&slur_vec), has_slurs_err_str);
|
assert_eq!(&slurs_vec_to_str(&slur_vec), has_slurs_err_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// These helped with testing
|
// These helped with testing
|
||||||
|
@ -113,7 +113,7 @@ mod tests {
|
|||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::build_db_pool_for_tests,
|
utils::build_db_pool_for_tests,
|
||||||
};
|
};
|
||||||
use lemmy_utils::rate_limit::RateLimitCell;
|
use lemmy_utils::{error::LemmyResult, rate_limit::RateLimitCell};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use reqwest_middleware::ClientBuilder;
|
use reqwest_middleware::ClientBuilder;
|
||||||
@ -122,13 +122,15 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_session_auth() {
|
async fn test_session_auth() -> LemmyResult<()> {
|
||||||
// hack, necessary so that config file can be loaded from hardcoded, relative path
|
// hack, necessary so that config file can be loaded from hardcoded, relative path
|
||||||
set_current_dir("crates/utils").unwrap();
|
set_current_dir("crates/utils")?;
|
||||||
|
|
||||||
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 secret = Secret::init(pool).await.unwrap().unwrap();
|
|
||||||
|
let secret = Secret::init(pool).await?.unwrap();
|
||||||
|
|
||||||
let context = LemmyContext::create(
|
let context = LemmyContext::create(
|
||||||
pool_.clone(),
|
pool_.clone(),
|
||||||
ClientBuilder::new(Client::default()).build(),
|
ClientBuilder::new(Client::default()).build(),
|
||||||
@ -136,29 +138,25 @@ mod tests {
|
|||||||
RateLimitCell::with_test_config(),
|
RateLimitCell::with_test_config(),
|
||||||
);
|
);
|
||||||
|
|
||||||
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 new_person = PersonInsertForm::test_form(inserted_instance.id, "Gerry9812");
|
let new_person = PersonInsertForm::test_form(inserted_instance.id, "Gerry9812");
|
||||||
|
|
||||||
let inserted_person = Person::create(pool, &new_person).await.unwrap();
|
let inserted_person = Person::create(pool, &new_person).await?;
|
||||||
|
|
||||||
let local_user_form = LocalUserInsertForm::test_form(inserted_person.id);
|
let local_user_form = LocalUserInsertForm::test_form(inserted_person.id);
|
||||||
|
|
||||||
let inserted_local_user = LocalUser::create(pool, &local_user_form, vec![])
|
let inserted_local_user = LocalUser::create(pool, &local_user_form, vec![]).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let req = TestRequest::default().to_http_request();
|
let req = TestRequest::default().to_http_request();
|
||||||
let jwt = Claims::generate(inserted_local_user.id, req, &context)
|
let jwt = Claims::generate(inserted_local_user.id, req, &context).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let valid = Claims::validate(&jwt, &context).await;
|
let valid = Claims::validate(&jwt, &context).await;
|
||||||
assert!(valid.is_ok());
|
assert!(valid.is_ok());
|
||||||
|
|
||||||
let num_deleted = Person::delete(pool, inserted_person.id).await.unwrap();
|
let num_deleted = Person::delete(pool, inserted_person.id).await?;
|
||||||
assert_eq!(1, num_deleted);
|
assert_eq!(1, num_deleted);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user