mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 11:21:32 +00:00
Use result instead of unwrap in apub tests (#4168)
This commit is contained in:
parent
e573010202
commit
fc56d0aa05
23 changed files with 3562 additions and 516 deletions
BIN
api_tests/pict-rs
Executable file
BIN
api_tests/pict-rs
Executable file
Binary file not shown.
3147
api_tests/yarn-error.log
Normal file
3147
api_tests/yarn-error.log
Normal file
File diff suppressed because it is too large
Load diff
|
@ -124,44 +124,43 @@ impl InCommunity for AnnouncableActivities {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
#![allow(clippy::indexing_slicing)]
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
activity_lists::{GroupInboxActivities, PersonInboxActivities, SharedInboxActivities},
|
activity_lists::{GroupInboxActivities, PersonInboxActivities, SharedInboxActivities},
|
||||||
protocol::tests::{test_json, test_parse_lemmy_item},
|
protocol::tests::{test_json, test_parse_lemmy_item},
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_group_inbox() {
|
fn test_group_inbox() -> LemmyResult<()> {
|
||||||
test_parse_lemmy_item::<GroupInboxActivities>("assets/lemmy/activities/following/follow.json")
|
test_parse_lemmy_item::<GroupInboxActivities>("assets/lemmy/activities/following/follow.json")?;
|
||||||
.unwrap();
|
|
||||||
test_parse_lemmy_item::<GroupInboxActivities>(
|
test_parse_lemmy_item::<GroupInboxActivities>(
|
||||||
"assets/lemmy/activities/create_or_update/create_note.json",
|
"assets/lemmy/activities/create_or_update/create_note.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_person_inbox() {
|
fn test_person_inbox() -> LemmyResult<()> {
|
||||||
test_parse_lemmy_item::<PersonInboxActivities>("assets/lemmy/activities/following/accept.json")
|
test_parse_lemmy_item::<PersonInboxActivities>(
|
||||||
.unwrap();
|
"assets/lemmy/activities/following/accept.json",
|
||||||
|
)?;
|
||||||
test_parse_lemmy_item::<PersonInboxActivities>(
|
test_parse_lemmy_item::<PersonInboxActivities>(
|
||||||
"assets/lemmy/activities/create_or_update/create_note.json",
|
"assets/lemmy/activities/create_or_update/create_note.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
|
||||||
test_parse_lemmy_item::<PersonInboxActivities>(
|
test_parse_lemmy_item::<PersonInboxActivities>(
|
||||||
"assets/lemmy/activities/create_or_update/create_private_message.json",
|
"assets/lemmy/activities/create_or_update/create_private_message.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
test_json::<PersonInboxActivities>("assets/mastodon/activities/follow.json")?;
|
||||||
test_json::<PersonInboxActivities>("assets/mastodon/activities/follow.json").unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_shared_inbox() {
|
fn test_shared_inbox() -> LemmyResult<()> {
|
||||||
test_parse_lemmy_item::<SharedInboxActivities>(
|
test_parse_lemmy_item::<SharedInboxActivities>(
|
||||||
"assets/lemmy/activities/deletion/delete_user.json",
|
"assets/lemmy/activities/deletion/delete_user.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,7 +277,6 @@ pub async fn import_settings(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
#![allow(clippy::indexing_slicing)]
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -297,7 +296,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_db_views_actor::structs::CommunityFollowerView;
|
use lemmy_db_views_actor::structs::CommunityFollowerView;
|
||||||
use lemmy_utils::error::LemmyErrorType;
|
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
|
@ -306,10 +305,8 @@ mod tests {
|
||||||
name: String,
|
name: String,
|
||||||
bio: Option<String>,
|
bio: Option<String>,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> LocalUserView {
|
) -> LemmyResult<LocalUserView> {
|
||||||
let instance = Instance::read_or_create(&mut context.pool(), "example.com".to_string())
|
let instance = Instance::read_or_create(&mut context.pool(), "example.com".to_string()).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let person_form = PersonInsertForm::builder()
|
let person_form = PersonInsertForm::builder()
|
||||||
.name(name.clone())
|
.name(name.clone())
|
||||||
.display_name(Some(name.clone()))
|
.display_name(Some(name.clone()))
|
||||||
|
@ -317,63 +314,49 @@ mod tests {
|
||||||
.public_key("asd".to_string())
|
.public_key("asd".to_string())
|
||||||
.instance_id(instance.id)
|
.instance_id(instance.id)
|
||||||
.build();
|
.build();
|
||||||
let person = Person::create(&mut context.pool(), &person_form)
|
let person = Person::create(&mut context.pool(), &person_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let user_form = LocalUserInsertForm::builder()
|
let user_form = LocalUserInsertForm::builder()
|
||||||
.person_id(person.id)
|
.person_id(person.id)
|
||||||
.password_encrypted("pass".to_string())
|
.password_encrypted("pass".to_string())
|
||||||
.build();
|
.build();
|
||||||
let local_user = LocalUser::create(&mut context.pool(), &user_form)
|
let local_user = LocalUser::create(&mut context.pool(), &user_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
LocalUserView::read(&mut context.pool(), local_user.id)
|
Ok(LocalUserView::read(&mut context.pool(), local_user.id).await?)
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_settings_export_import() {
|
async fn test_settings_export_import() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
|
|
||||||
let export_user = create_user("hanna".to_string(), Some("my bio".to_string()), &context).await;
|
let export_user =
|
||||||
|
create_user("hanna".to_string(), Some("my bio".to_string()), &context).await?;
|
||||||
|
|
||||||
let community_form = CommunityInsertForm::builder()
|
let community_form = CommunityInsertForm::builder()
|
||||||
.name("testcom".to_string())
|
.name("testcom".to_string())
|
||||||
.title("testcom".to_string())
|
.title("testcom".to_string())
|
||||||
.instance_id(export_user.person.instance_id)
|
.instance_id(export_user.person.instance_id)
|
||||||
.build();
|
.build();
|
||||||
let community = Community::create(&mut context.pool(), &community_form)
|
let community = Community::create(&mut context.pool(), &community_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let follower_form = CommunityFollowerForm {
|
let follower_form = CommunityFollowerForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
person_id: export_user.person.id,
|
person_id: export_user.person.id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
CommunityFollower::follow(&mut context.pool(), &follower_form)
|
CommunityFollower::follow(&mut context.pool(), &follower_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let backup = export_settings(export_user.clone(), context.reset_request_count())
|
let backup = export_settings(export_user.clone(), context.reset_request_count()).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let import_user = create_user("charles".to_string(), None, &context).await;
|
let import_user = create_user("charles".to_string(), None, &context).await?;
|
||||||
|
|
||||||
import_settings(backup, import_user.clone(), context.reset_request_count())
|
import_settings(backup, import_user.clone(), context.reset_request_count()).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// wait for background task to finish
|
// wait for background task to finish
|
||||||
sleep(Duration::from_millis(1000)).await;
|
sleep(Duration::from_millis(1000)).await;
|
||||||
|
|
||||||
let import_user_updated = LocalUserView::read(&mut context.pool(), import_user.local_user.id)
|
let import_user_updated =
|
||||||
.await
|
LocalUserView::read(&mut context.pool(), import_user.local_user.id).await?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
export_user.person.display_name,
|
export_user.person.display_name,
|
||||||
|
@ -381,61 +364,49 @@ mod tests {
|
||||||
);
|
);
|
||||||
assert_eq!(export_user.person.bio, import_user_updated.person.bio);
|
assert_eq!(export_user.person.bio, import_user_updated.person.bio);
|
||||||
|
|
||||||
let follows = CommunityFollowerView::for_person(&mut context.pool(), import_user.person.id)
|
let follows =
|
||||||
.await
|
CommunityFollowerView::for_person(&mut context.pool(), import_user.person.id).await?;
|
||||||
.unwrap();
|
|
||||||
assert_eq!(follows.len(), 1);
|
assert_eq!(follows.len(), 1);
|
||||||
assert_eq!(follows[0].community.actor_id, community.actor_id);
|
assert_eq!(follows[0].community.actor_id, community.actor_id);
|
||||||
|
|
||||||
LocalUser::delete(&mut context.pool(), export_user.local_user.id)
|
LocalUser::delete(&mut context.pool(), export_user.local_user.id).await?;
|
||||||
.await
|
LocalUser::delete(&mut context.pool(), import_user.local_user.id).await?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
LocalUser::delete(&mut context.pool(), import_user.local_user.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn disallow_large_backup() {
|
async fn disallow_large_backup() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
|
|
||||||
let export_user = create_user("hanna".to_string(), Some("my bio".to_string()), &context).await;
|
let export_user =
|
||||||
|
create_user("hanna".to_string(), Some("my bio".to_string()), &context).await?;
|
||||||
|
|
||||||
let mut backup = export_settings(export_user.clone(), context.reset_request_count())
|
let mut backup = export_settings(export_user.clone(), context.reset_request_count()).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
for _ in 0..251 {
|
for _ in 0..251 {
|
||||||
backup
|
backup
|
||||||
.followed_communities
|
.followed_communities
|
||||||
.push("http://example.com".parse().unwrap());
|
.push("http://example.com".parse()?);
|
||||||
backup
|
backup
|
||||||
.blocked_communities
|
.blocked_communities
|
||||||
.push("http://example2.com".parse().unwrap());
|
.push("http://example2.com".parse()?);
|
||||||
backup
|
backup.saved_posts.push("http://example3.com".parse()?);
|
||||||
.saved_posts
|
backup.saved_comments.push("http://example4.com".parse()?);
|
||||||
.push("http://example3.com".parse().unwrap());
|
|
||||||
backup
|
|
||||||
.saved_comments
|
|
||||||
.push("http://example4.com".parse().unwrap());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let import_user = create_user("charles".to_string(), None, &context).await;
|
let import_user = create_user("charles".to_string(), None, &context).await?;
|
||||||
|
|
||||||
let imported =
|
let imported =
|
||||||
import_settings(backup, import_user.clone(), context.reset_request_count()).await;
|
import_settings(backup, import_user.clone(), context.reset_request_count()).await;
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
imported.err().unwrap().error_type,
|
imported.err().map(|e| e.error_type),
|
||||||
LemmyErrorType::TooManyItems
|
Some(LemmyErrorType::TooManyItems)
|
||||||
);
|
);
|
||||||
|
|
||||||
LocalUser::delete(&mut context.pool(), export_user.local_user.id)
|
LocalUser::delete(&mut context.pool(), export_user.local_user.id).await?;
|
||||||
.await
|
LocalUser::delete(&mut context.pool(), import_user.local_user.id).await?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
LocalUser::delete(&mut context.pool(), import_user.local_user.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,6 @@ impl Collection for ApubCommunityModerators {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
#![allow(clippy::indexing_slicing)]
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -123,20 +122,19 @@ mod tests {
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_parse_lemmy_community_moderators() {
|
async fn test_parse_lemmy_community_moderators() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
let (new_mod, site) = parse_lemmy_person(&context).await;
|
let (new_mod, site) = parse_lemmy_person(&context).await?;
|
||||||
let community = parse_lemmy_community(&context).await;
|
let community = parse_lemmy_community(&context).await?;
|
||||||
let community_id = community.id;
|
let community_id = community.id;
|
||||||
|
|
||||||
let inserted_instance =
|
let inserted_instance =
|
||||||
Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string())
|
Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let old_mod = PersonInsertForm::builder()
|
let old_mod = PersonInsertForm::builder()
|
||||||
.name("holly".into())
|
.name("holly".into())
|
||||||
|
@ -144,49 +142,34 @@ mod tests {
|
||||||
.instance_id(inserted_instance.id)
|
.instance_id(inserted_instance.id)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let old_mod = Person::create(&mut context.pool(), &old_mod).await.unwrap();
|
let old_mod = Person::create(&mut context.pool(), &old_mod).await?;
|
||||||
let community_moderator_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
person_id: old_mod.id,
|
person_id: old_mod.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
CommunityModerator::join(&mut context.pool(), &community_moderator_form)
|
CommunityModerator::join(&mut context.pool(), &community_moderator_form).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(site.actor_id.to_string(), "https://enterprise.lemmy.ml/");
|
assert_eq!(site.actor_id.to_string(), "https://enterprise.lemmy.ml/");
|
||||||
|
|
||||||
let json: GroupModerators =
|
let json: GroupModerators =
|
||||||
file_to_json_object("assets/lemmy/collections/group_moderators.json").unwrap();
|
file_to_json_object("assets/lemmy/collections/group_moderators.json")?;
|
||||||
let url = Url::parse("https://enterprise.lemmy.ml/c/tenforward").unwrap();
|
let url = Url::parse("https://enterprise.lemmy.ml/c/tenforward")?;
|
||||||
ApubCommunityModerators::verify(&json, &url, &context)
|
ApubCommunityModerators::verify(&json, &url, &context).await?;
|
||||||
.await
|
ApubCommunityModerators::from_json(json, &community, &context).await?;
|
||||||
.unwrap();
|
|
||||||
ApubCommunityModerators::from_json(json, &community, &context)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(context.request_count(), 0);
|
assert_eq!(context.request_count(), 0);
|
||||||
|
|
||||||
let current_moderators =
|
let current_moderators =
|
||||||
CommunityModeratorView::for_community(&mut context.pool(), community_id)
|
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(current_moderators.len(), 1);
|
assert_eq!(current_moderators.len(), 1);
|
||||||
assert_eq!(current_moderators[0].moderator.id, new_mod.id);
|
assert_eq!(current_moderators[0].moderator.id, new_mod.id);
|
||||||
|
|
||||||
Person::delete(&mut context.pool(), old_mod.id)
|
Person::delete(&mut context.pool(), old_mod.id).await?;
|
||||||
.await
|
Person::delete(&mut context.pool(), new_mod.id).await?;
|
||||||
.unwrap();
|
Community::delete(&mut context.pool(), community.id).await?;
|
||||||
Person::delete(&mut context.pool(), new_mod.id)
|
Site::delete(&mut context.pool(), site.id).await?;
|
||||||
.await
|
Instance::delete(&mut context.pool(), inserted_instance.id).await?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
Community::delete(&mut context.pool(), community.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
Site::delete(&mut context.pool(), site.id).await.unwrap();
|
|
||||||
Instance::delete(&mut context.pool(), inserted_instance.id)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,9 +183,6 @@ impl Object for ApubComment {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
objects::{
|
objects::{
|
||||||
|
@ -200,46 +197,45 @@ pub(crate) mod tests {
|
||||||
use assert_json_diff::assert_json_include;
|
use assert_json_diff::assert_json_include;
|
||||||
use html2md::parse_html;
|
use html2md::parse_html;
|
||||||
use lemmy_db_schema::source::site::Site;
|
use lemmy_db_schema::source::site::Site;
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
async fn prepare_comment_test(
|
async fn prepare_comment_test(
|
||||||
url: &Url,
|
url: &Url,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> (ApubPerson, ApubCommunity, ApubPost, ApubSite) {
|
) -> LemmyResult<(ApubPerson, ApubCommunity, ApubPost, ApubSite)> {
|
||||||
// use separate counter so this doesnt affect tests
|
// use separate counter so this doesnt affect tests
|
||||||
let context2 = context.reset_request_count();
|
let context2 = context.reset_request_count();
|
||||||
let (person, site) = parse_lemmy_person(&context2).await;
|
let (person, site) = parse_lemmy_person(&context2).await?;
|
||||||
let community = parse_lemmy_community(&context2).await;
|
let community = parse_lemmy_community(&context2).await?;
|
||||||
let post_json = file_to_json_object("assets/lemmy/objects/page.json").unwrap();
|
let post_json = file_to_json_object("assets/lemmy/objects/page.json")?;
|
||||||
ApubPost::verify(&post_json, url, &context2).await.unwrap();
|
ApubPost::verify(&post_json, url, &context2).await?;
|
||||||
let post = ApubPost::from_json(post_json, &context2).await.unwrap();
|
let post = ApubPost::from_json(post_json, &context2).await?;
|
||||||
(person, community, post, site)
|
Ok((person, community, post, site))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(data: (ApubPerson, ApubCommunity, ApubPost, ApubSite), context: &LemmyContext) {
|
async fn cleanup(
|
||||||
Post::delete(&mut context.pool(), data.2.id).await.unwrap();
|
data: (ApubPerson, ApubCommunity, ApubPost, ApubSite),
|
||||||
Community::delete(&mut context.pool(), data.1.id)
|
context: &LemmyContext,
|
||||||
.await
|
) -> LemmyResult<()> {
|
||||||
.unwrap();
|
Post::delete(&mut context.pool(), data.2.id).await?;
|
||||||
Person::delete(&mut context.pool(), data.0.id)
|
Community::delete(&mut context.pool(), data.1.id).await?;
|
||||||
.await
|
Person::delete(&mut context.pool(), data.0.id).await?;
|
||||||
.unwrap();
|
Site::delete(&mut context.pool(), data.3.id).await?;
|
||||||
Site::delete(&mut context.pool(), data.3.id).await.unwrap();
|
LocalSite::delete(&mut context.pool()).await?;
|
||||||
LocalSite::delete(&mut context.pool()).await.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
pub(crate) async fn test_parse_lemmy_comment() {
|
pub(crate) async fn test_parse_lemmy_comment() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741").unwrap();
|
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741")?;
|
||||||
let data = prepare_comment_test(&url, &context).await;
|
let data = prepare_comment_test(&url, &context).await?;
|
||||||
|
|
||||||
let json: Note = file_to_json_object("assets/lemmy/objects/note.json").unwrap();
|
let json: Note = file_to_json_object("assets/lemmy/objects/note.json")?;
|
||||||
ApubComment::verify(&json, &url, &context).await.unwrap();
|
ApubComment::verify(&json, &url, &context).await?;
|
||||||
let comment = ApubComment::from_json(json.clone(), &context)
|
let comment = ApubComment::from_json(json.clone(), &context).await?;
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(comment.ap_id, url.into());
|
assert_eq!(comment.ap_id, url.into());
|
||||||
assert_eq!(comment.content.len(), 14);
|
assert_eq!(comment.content.len(), 14);
|
||||||
|
@ -247,45 +243,38 @@ pub(crate) mod tests {
|
||||||
assert_eq!(context.request_count(), 0);
|
assert_eq!(context.request_count(), 0);
|
||||||
|
|
||||||
let comment_id = comment.id;
|
let comment_id = comment.id;
|
||||||
let to_apub = comment.into_json(&context).await.unwrap();
|
let to_apub = comment.into_json(&context).await?;
|
||||||
assert_json_include!(actual: json, expected: to_apub);
|
assert_json_include!(actual: json, expected: to_apub);
|
||||||
|
|
||||||
Comment::delete(&mut context.pool(), comment_id)
|
Comment::delete(&mut context.pool(), comment_id).await?;
|
||||||
.await
|
cleanup(data, &context).await?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
cleanup(data, &context).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_parse_pleroma_comment() {
|
async fn test_parse_pleroma_comment() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741").unwrap();
|
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741")?;
|
||||||
let data = prepare_comment_test(&url, &context).await;
|
let data = prepare_comment_test(&url, &context).await?;
|
||||||
|
|
||||||
let pleroma_url =
|
let pleroma_url =
|
||||||
Url::parse("https://queer.hacktivis.me/objects/8d4973f4-53de-49cd-8c27-df160e16a9c2")
|
Url::parse("https://queer.hacktivis.me/objects/8d4973f4-53de-49cd-8c27-df160e16a9c2")?;
|
||||||
.unwrap();
|
let person_json = file_to_json_object("assets/pleroma/objects/person.json")?;
|
||||||
let person_json = file_to_json_object("assets/pleroma/objects/person.json").unwrap();
|
ApubPerson::verify(&person_json, &pleroma_url, &context).await?;
|
||||||
ApubPerson::verify(&person_json, &pleroma_url, &context)
|
ApubPerson::from_json(person_json, &context).await?;
|
||||||
.await
|
let json = file_to_json_object("assets/pleroma/objects/note.json")?;
|
||||||
.unwrap();
|
ApubComment::verify(&json, &pleroma_url, &context).await?;
|
||||||
ApubPerson::from_json(person_json, &context).await.unwrap();
|
let comment = ApubComment::from_json(json, &context).await?;
|
||||||
let json = file_to_json_object("assets/pleroma/objects/note.json").unwrap();
|
|
||||||
ApubComment::verify(&json, &pleroma_url, &context)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let comment = ApubComment::from_json(json, &context).await.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(comment.ap_id, pleroma_url.into());
|
assert_eq!(comment.ap_id, pleroma_url.into());
|
||||||
assert_eq!(comment.content.len(), 64);
|
assert_eq!(comment.content.len(), 64);
|
||||||
assert!(!comment.local);
|
assert!(!comment.local);
|
||||||
assert_eq!(context.request_count(), 1);
|
assert_eq!(context.request_count(), 1);
|
||||||
|
|
||||||
Comment::delete(&mut context.pool(), comment.id)
|
Comment::delete(&mut context.pool(), comment.id).await?;
|
||||||
.await
|
cleanup(data, &context).await?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
cleanup(data, &context).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
@ -216,9 +216,6 @@ impl ApubCommunity {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
objects::{instance::tests::parse_lemmy_instance, tests::init_context},
|
objects::{instance::tests::parse_lemmy_instance, tests::init_context},
|
||||||
|
@ -226,41 +223,44 @@ pub(crate) mod tests {
|
||||||
};
|
};
|
||||||
use activitypub_federation::fetch::collection_id::CollectionId;
|
use activitypub_federation::fetch::collection_id::CollectionId;
|
||||||
use lemmy_db_schema::{source::site::Site, traits::Crud};
|
use lemmy_db_schema::{source::site::Site, traits::Crud};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
pub(crate) async fn parse_lemmy_community(context: &Data<LemmyContext>) -> ApubCommunity {
|
pub(crate) async fn parse_lemmy_community(
|
||||||
|
context: &Data<LemmyContext>,
|
||||||
|
) -> LemmyResult<ApubCommunity> {
|
||||||
// use separate counter so this doesnt affect tests
|
// use separate counter so this doesnt affect tests
|
||||||
let context2 = context.reset_request_count();
|
let context2 = context.reset_request_count();
|
||||||
let mut json: Group = file_to_json_object("assets/lemmy/objects/group.json").unwrap();
|
let mut json: Group = file_to_json_object("assets/lemmy/objects/group.json")?;
|
||||||
// change these links so they dont fetch over the network
|
// change these links so they dont fetch over the network
|
||||||
json.attributed_to = None;
|
json.attributed_to = None;
|
||||||
json.outbox =
|
json.outbox = CollectionId::parse("https://enterprise.lemmy.ml/c/tenforward/not_outbox")?;
|
||||||
CollectionId::parse("https://enterprise.lemmy.ml/c/tenforward/not_outbox").unwrap();
|
json.followers = CollectionId::parse("https://enterprise.lemmy.ml/c/tenforward/not_followers")?;
|
||||||
json.followers =
|
|
||||||
CollectionId::parse("https://enterprise.lemmy.ml/c/tenforward/not_followers").unwrap();
|
|
||||||
|
|
||||||
let url = Url::parse("https://enterprise.lemmy.ml/c/tenforward").unwrap();
|
let url = Url::parse("https://enterprise.lemmy.ml/c/tenforward")?;
|
||||||
ApubCommunity::verify(&json, &url, &context2).await.unwrap();
|
ApubCommunity::verify(&json, &url, &context2).await?;
|
||||||
let community = ApubCommunity::from_json(json, &context2).await.unwrap();
|
let community = ApubCommunity::from_json(json, &context2).await?;
|
||||||
// this makes requests to the (intentionally broken) outbox and followers collections
|
// this makes requests to the (intentionally broken) outbox and followers collections
|
||||||
assert_eq!(context2.request_count(), 2);
|
assert_eq!(context2.request_count(), 2);
|
||||||
community
|
Ok(community)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_parse_lemmy_community() {
|
async fn test_parse_lemmy_community() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
let site = parse_lemmy_instance(&context).await;
|
let site = parse_lemmy_instance(&context).await?;
|
||||||
let community = parse_lemmy_community(&context).await;
|
let community = parse_lemmy_community(&context).await?;
|
||||||
|
|
||||||
assert_eq!(community.title, "Ten Forward");
|
assert_eq!(community.title, "Ten Forward");
|
||||||
assert!(!community.local);
|
assert!(!community.local);
|
||||||
assert_eq!(community.description.as_ref().unwrap().len(), 132);
|
assert_eq!(
|
||||||
|
community.description.as_ref().map(std::string::String::len),
|
||||||
|
Some(132)
|
||||||
|
);
|
||||||
|
|
||||||
Community::delete(&mut context.pool(), community.id)
|
Community::delete(&mut context.pool(), community.id).await?;
|
||||||
.await
|
Site::delete(&mut context.pool(), site.id).await?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
Site::delete(&mut context.pool(), site.id).await.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,32 +204,34 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object<T: Into<Url> + C
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{objects::tests::init_context, protocol::tests::file_to_json_object};
|
use crate::{objects::tests::init_context, protocol::tests::file_to_json_object};
|
||||||
use lemmy_db_schema::traits::Crud;
|
use lemmy_db_schema::traits::Crud;
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
pub(crate) async fn parse_lemmy_instance(context: &Data<LemmyContext>) -> ApubSite {
|
pub(crate) async fn parse_lemmy_instance(context: &Data<LemmyContext>) -> LemmyResult<ApubSite> {
|
||||||
let json: Instance = file_to_json_object("assets/lemmy/objects/instance.json").unwrap();
|
let json: Instance = file_to_json_object("assets/lemmy/objects/instance.json")?;
|
||||||
let id = Url::parse("https://enterprise.lemmy.ml/").unwrap();
|
let id = Url::parse("https://enterprise.lemmy.ml/")?;
|
||||||
ApubSite::verify(&json, &id, context).await.unwrap();
|
ApubSite::verify(&json, &id, context).await?;
|
||||||
let site = ApubSite::from_json(json, context).await.unwrap();
|
let site = ApubSite::from_json(json, context).await?;
|
||||||
assert_eq!(context.request_count(), 0);
|
assert_eq!(context.request_count(), 0);
|
||||||
site
|
Ok(site)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_parse_lemmy_instance() {
|
async fn test_parse_lemmy_instance() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
let site = parse_lemmy_instance(&context).await;
|
let site = parse_lemmy_instance(&context).await?;
|
||||||
|
|
||||||
assert_eq!(site.name, "Enterprise");
|
assert_eq!(site.name, "Enterprise");
|
||||||
assert_eq!(site.description.as_ref().unwrap().len(), 15);
|
assert_eq!(
|
||||||
|
site.description.as_ref().map(std::string::String::len),
|
||||||
|
Some(15)
|
||||||
|
);
|
||||||
|
|
||||||
Site::delete(&mut context.pool(), site.id).await.unwrap();
|
Site::delete(&mut context.pool(), site.id).await?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,14 +54,11 @@ pub(crate) fn verify_is_remote_object(id: &Url, settings: &Settings) -> Result<(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use activitypub_federation::config::{Data, FederationConfig};
|
use activitypub_federation::config::{Data, FederationConfig};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use lemmy_api_common::{context::LemmyContext, request::client_builder};
|
use lemmy_api_common::{context::LemmyContext, request::client_builder};
|
||||||
use lemmy_db_schema::{source::secret::Secret, utils::build_db_pool_for_tests};
|
use lemmy_db_schema::{source::secret::Secret, utils::build_db_pool_for_tests};
|
||||||
use lemmy_utils::{rate_limit::RateLimitCell, settings::SETTINGS};
|
use lemmy_utils::{error::LemmyResult, rate_limit::RateLimitCell, settings::SETTINGS};
|
||||||
use reqwest::{Request, Response};
|
use reqwest::{Request, Response};
|
||||||
use reqwest_middleware::{ClientBuilder, Middleware, Next};
|
use reqwest_middleware::{ClientBuilder, Middleware, Next};
|
||||||
use task_local_extensions::Extensions;
|
use task_local_extensions::Extensions;
|
||||||
|
@ -82,11 +79,11 @@ pub(crate) mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: would be nice if we didnt have to use a full context for tests.
|
// TODO: would be nice if we didnt have to use a full context for tests.
|
||||||
pub(crate) async fn init_context() -> Data<LemmyContext> {
|
pub(crate) async fn init_context() -> LemmyResult<Data<LemmyContext>> {
|
||||||
// call this to run migrations
|
// call this to run migrations
|
||||||
let pool = build_db_pool_for_tests().await;
|
let pool = build_db_pool_for_tests().await;
|
||||||
|
|
||||||
let client = client_builder(&SETTINGS).build().unwrap();
|
let client = client_builder(&SETTINGS).build()?;
|
||||||
|
|
||||||
let client = ClientBuilder::new(client).with(BlockedMiddleware).build();
|
let client = ClientBuilder::new(client).with(BlockedMiddleware).build();
|
||||||
let secret = Secret {
|
let secret = Secret {
|
||||||
|
@ -101,8 +98,7 @@ pub(crate) mod tests {
|
||||||
.domain("example.com")
|
.domain("example.com")
|
||||||
.app_data(context)
|
.app_data(context)
|
||||||
.build()
|
.build()
|
||||||
.await
|
.await?;
|
||||||
.unwrap();
|
Ok(config.to_request_data())
|
||||||
config.to_request_data()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,9 +208,6 @@ impl GetActorType for ApubPerson {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
objects::{
|
objects::{
|
||||||
|
@ -221,60 +218,64 @@ pub(crate) mod tests {
|
||||||
};
|
};
|
||||||
use activitypub_federation::fetch::object_id::ObjectId;
|
use activitypub_federation::fetch::object_id::ObjectId;
|
||||||
use lemmy_db_schema::{source::site::Site, traits::Crud};
|
use lemmy_db_schema::{source::site::Site, traits::Crud};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
pub(crate) async fn parse_lemmy_person(context: &Data<LemmyContext>) -> (ApubPerson, ApubSite) {
|
pub(crate) async fn parse_lemmy_person(
|
||||||
let site = parse_lemmy_instance(context).await;
|
context: &Data<LemmyContext>,
|
||||||
let json = file_to_json_object("assets/lemmy/objects/person.json").unwrap();
|
) -> LemmyResult<(ApubPerson, ApubSite)> {
|
||||||
let url = Url::parse("https://enterprise.lemmy.ml/u/picard").unwrap();
|
let site = parse_lemmy_instance(context).await?;
|
||||||
ApubPerson::verify(&json, &url, context).await.unwrap();
|
let json = file_to_json_object("assets/lemmy/objects/person.json")?;
|
||||||
let person = ApubPerson::from_json(json, context).await.unwrap();
|
let url = Url::parse("https://enterprise.lemmy.ml/u/picard")?;
|
||||||
|
ApubPerson::verify(&json, &url, context).await?;
|
||||||
|
let person = ApubPerson::from_json(json, context).await?;
|
||||||
assert_eq!(context.request_count(), 0);
|
assert_eq!(context.request_count(), 0);
|
||||||
(person, site)
|
Ok((person, site))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_parse_lemmy_person() {
|
async fn test_parse_lemmy_person() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
let (person, site) = parse_lemmy_person(&context).await;
|
let (person, site) = parse_lemmy_person(&context).await?;
|
||||||
|
|
||||||
assert_eq!(person.display_name, Some("Jean-Luc Picard".to_string()));
|
assert_eq!(person.display_name, Some("Jean-Luc Picard".to_string()));
|
||||||
assert!(!person.local);
|
assert!(!person.local);
|
||||||
assert_eq!(person.bio.as_ref().unwrap().len(), 39);
|
assert_eq!(person.bio.as_ref().map(std::string::String::len), Some(39));
|
||||||
|
|
||||||
cleanup((person, site), &context).await;
|
cleanup((person, site), &context).await?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_parse_pleroma_person() {
|
async fn test_parse_pleroma_person() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
|
|
||||||
// create and parse a fake pleroma instance actor, to avoid network request during test
|
// create and parse a fake pleroma instance actor, to avoid network request during test
|
||||||
let mut json: Instance = file_to_json_object("assets/lemmy/objects/instance.json").unwrap();
|
let mut json: Instance = file_to_json_object("assets/lemmy/objects/instance.json")?;
|
||||||
json.id = ObjectId::parse("https://queer.hacktivis.me/").unwrap();
|
json.id = ObjectId::parse("https://queer.hacktivis.me/")?;
|
||||||
let url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
|
let url = Url::parse("https://queer.hacktivis.me/users/lanodan")?;
|
||||||
ApubSite::verify(&json, &url, &context).await.unwrap();
|
ApubSite::verify(&json, &url, &context).await?;
|
||||||
let site = ApubSite::from_json(json, &context).await.unwrap();
|
let site = ApubSite::from_json(json, &context).await?;
|
||||||
|
|
||||||
let json = file_to_json_object("assets/pleroma/objects/person.json").unwrap();
|
let json = file_to_json_object("assets/pleroma/objects/person.json")?;
|
||||||
ApubPerson::verify(&json, &url, &context).await.unwrap();
|
ApubPerson::verify(&json, &url, &context).await?;
|
||||||
let person = ApubPerson::from_json(json, &context).await.unwrap();
|
let person = ApubPerson::from_json(json, &context).await?;
|
||||||
|
|
||||||
assert_eq!(person.actor_id, url.into());
|
assert_eq!(person.actor_id, url.into());
|
||||||
assert_eq!(person.name, "lanodan");
|
assert_eq!(person.name, "lanodan");
|
||||||
assert!(!person.local);
|
assert!(!person.local);
|
||||||
assert_eq!(context.request_count(), 0);
|
assert_eq!(context.request_count(), 0);
|
||||||
assert_eq!(person.bio.as_ref().unwrap().len(), 873);
|
assert_eq!(person.bio.as_ref().map(std::string::String::len), Some(873));
|
||||||
|
|
||||||
cleanup((person, site), &context).await;
|
cleanup((person, site), &context).await?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(data: (ApubPerson, ApubSite), context: &LemmyContext) {
|
async fn cleanup(data: (ApubPerson, ApubSite), context: &LemmyContext) -> LemmyResult<()> {
|
||||||
DbPerson::delete(&mut context.pool(), data.0.id)
|
DbPerson::delete(&mut context.pool(), data.0.id).await?;
|
||||||
.await
|
Site::delete(&mut context.pool(), data.1.id).await?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
Site::delete(&mut context.pool(), data.1.id).await.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,9 +292,6 @@ impl Object for ApubPost {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
objects::{
|
objects::{
|
||||||
|
@ -307,44 +304,47 @@ mod tests {
|
||||||
protocol::tests::file_to_json_object,
|
protocol::tests::file_to_json_object,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::site::Site;
|
use lemmy_db_schema::source::site::Site;
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_parse_lemmy_post() {
|
async fn test_parse_lemmy_post() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
let (person, site) = parse_lemmy_person(&context).await;
|
let (person, site) = parse_lemmy_person(&context).await?;
|
||||||
let community = parse_lemmy_community(&context).await;
|
let community = parse_lemmy_community(&context).await?;
|
||||||
|
|
||||||
let json = file_to_json_object("assets/lemmy/objects/page.json").unwrap();
|
let json = file_to_json_object("assets/lemmy/objects/page.json")?;
|
||||||
let url = Url::parse("https://enterprise.lemmy.ml/post/55143").unwrap();
|
let url = Url::parse("https://enterprise.lemmy.ml/post/55143")?;
|
||||||
ApubPost::verify(&json, &url, &context).await.unwrap();
|
ApubPost::verify(&json, &url, &context).await?;
|
||||||
let post = ApubPost::from_json(json, &context).await.unwrap();
|
let post = ApubPost::from_json(json, &context).await?;
|
||||||
|
|
||||||
assert_eq!(post.ap_id, url.into());
|
assert_eq!(post.ap_id, url.into());
|
||||||
assert_eq!(post.name, "Post title");
|
assert_eq!(post.name, "Post title");
|
||||||
assert!(post.body.is_some());
|
assert!(post.body.is_some());
|
||||||
assert_eq!(post.body.as_ref().unwrap().len(), 45);
|
assert_eq!(post.body.as_ref().map(std::string::String::len), Some(45));
|
||||||
assert!(!post.locked);
|
assert!(!post.locked);
|
||||||
assert!(!post.featured_community);
|
assert!(!post.featured_community);
|
||||||
assert_eq!(context.request_count(), 0);
|
assert_eq!(context.request_count(), 0);
|
||||||
|
|
||||||
cleanup(&context, person, site, community, post).await;
|
cleanup(&context, person, site, community, post).await?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_convert_mastodon_post_title() {
|
async fn test_convert_mastodon_post_title() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
let (person, site) = parse_lemmy_person(&context).await;
|
let (person, site) = parse_lemmy_person(&context).await?;
|
||||||
let community = parse_lemmy_community(&context).await;
|
let community = parse_lemmy_community(&context).await?;
|
||||||
|
|
||||||
let json = file_to_json_object("assets/mastodon/objects/page.json").unwrap();
|
let json = file_to_json_object("assets/mastodon/objects/page.json")?;
|
||||||
let post = ApubPost::from_json(json, &context).await.unwrap();
|
let post = ApubPost::from_json(json, &context).await?;
|
||||||
|
|
||||||
assert_eq!(post.name, "Variable never resetting at refresh");
|
assert_eq!(post.name, "Variable never resetting at refresh");
|
||||||
|
|
||||||
cleanup(&context, person, site, community, post).await;
|
cleanup(&context, person, site, community, post).await?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(
|
async fn cleanup(
|
||||||
|
@ -353,14 +353,11 @@ mod tests {
|
||||||
site: ApubSite,
|
site: ApubSite,
|
||||||
community: ApubCommunity,
|
community: ApubCommunity,
|
||||||
post: ApubPost,
|
post: ApubPost,
|
||||||
) {
|
) -> LemmyResult<()> {
|
||||||
Post::delete(&mut context.pool(), post.id).await.unwrap();
|
Post::delete(&mut context.pool(), post.id).await?;
|
||||||
Person::delete(&mut context.pool(), person.id)
|
Person::delete(&mut context.pool(), person.id).await?;
|
||||||
.await
|
Community::delete(&mut context.pool(), community.id).await?;
|
||||||
.unwrap();
|
Site::delete(&mut context.pool(), site.id).await?;
|
||||||
Community::delete(&mut context.pool(), community.id)
|
Ok(())
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
Site::delete(&mut context.pool(), site.id).await.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,9 +141,6 @@ impl Object for ApubPrivateMessage {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
objects::{
|
objects::{
|
||||||
|
@ -155,90 +152,75 @@ mod tests {
|
||||||
};
|
};
|
||||||
use assert_json_diff::assert_json_include;
|
use assert_json_diff::assert_json_include;
|
||||||
use lemmy_db_schema::source::site::Site;
|
use lemmy_db_schema::source::site::Site;
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
async fn prepare_comment_test(
|
async fn prepare_comment_test(
|
||||||
url: &Url,
|
url: &Url,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
) -> (ApubPerson, ApubPerson, ApubSite) {
|
) -> LemmyResult<(ApubPerson, ApubPerson, ApubSite)> {
|
||||||
let context2 = context.reset_request_count();
|
let context2 = context.reset_request_count();
|
||||||
let lemmy_person = file_to_json_object("assets/lemmy/objects/person.json").unwrap();
|
let lemmy_person = file_to_json_object("assets/lemmy/objects/person.json")?;
|
||||||
let site = parse_lemmy_instance(&context2).await;
|
let site = parse_lemmy_instance(&context2).await?;
|
||||||
ApubPerson::verify(&lemmy_person, url, &context2)
|
ApubPerson::verify(&lemmy_person, url, &context2).await?;
|
||||||
.await
|
let person1 = ApubPerson::from_json(lemmy_person, &context2).await?;
|
||||||
.unwrap();
|
let pleroma_person = file_to_json_object("assets/pleroma/objects/person.json")?;
|
||||||
let person1 = ApubPerson::from_json(lemmy_person, &context2)
|
let pleroma_url = Url::parse("https://queer.hacktivis.me/users/lanodan")?;
|
||||||
.await
|
ApubPerson::verify(&pleroma_person, &pleroma_url, &context2).await?;
|
||||||
.unwrap();
|
let person2 = ApubPerson::from_json(pleroma_person, &context2).await?;
|
||||||
let pleroma_person = file_to_json_object("assets/pleroma/objects/person.json").unwrap();
|
Ok((person1, person2, site))
|
||||||
let pleroma_url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
|
|
||||||
ApubPerson::verify(&pleroma_person, &pleroma_url, &context2)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
let person2 = ApubPerson::from_json(pleroma_person, &context2)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
(person1, person2, site)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(data: (ApubPerson, ApubPerson, ApubSite), context: &Data<LemmyContext>) {
|
async fn cleanup(
|
||||||
Person::delete(&mut context.pool(), data.0.id)
|
data: (ApubPerson, ApubPerson, ApubSite),
|
||||||
.await
|
context: &Data<LemmyContext>,
|
||||||
.unwrap();
|
) -> LemmyResult<()> {
|
||||||
Person::delete(&mut context.pool(), data.1.id)
|
Person::delete(&mut context.pool(), data.0.id).await?;
|
||||||
.await
|
Person::delete(&mut context.pool(), data.1.id).await?;
|
||||||
.unwrap();
|
Site::delete(&mut context.pool(), data.2.id).await?;
|
||||||
Site::delete(&mut context.pool(), data.2.id).await.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_parse_lemmy_pm() {
|
async fn test_parse_lemmy_pm() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap();
|
let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621")?;
|
||||||
let data = prepare_comment_test(&url, &context).await;
|
let data = prepare_comment_test(&url, &context).await?;
|
||||||
let json: ChatMessage = file_to_json_object("assets/lemmy/objects/chat_message.json").unwrap();
|
let json: ChatMessage = file_to_json_object("assets/lemmy/objects/chat_message.json")?;
|
||||||
ApubPrivateMessage::verify(&json, &url, &context)
|
ApubPrivateMessage::verify(&json, &url, &context).await?;
|
||||||
.await
|
let pm = ApubPrivateMessage::from_json(json.clone(), &context).await?;
|
||||||
.unwrap();
|
|
||||||
let pm = ApubPrivateMessage::from_json(json.clone(), &context)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(pm.ap_id.clone(), url.into());
|
assert_eq!(pm.ap_id.clone(), url.into());
|
||||||
assert_eq!(pm.content.len(), 20);
|
assert_eq!(pm.content.len(), 20);
|
||||||
assert_eq!(context.request_count(), 0);
|
assert_eq!(context.request_count(), 0);
|
||||||
|
|
||||||
let pm_id = pm.id;
|
let pm_id = pm.id;
|
||||||
let to_apub = pm.into_json(&context).await.unwrap();
|
let to_apub = pm.into_json(&context).await?;
|
||||||
assert_json_include!(actual: json, expected: to_apub);
|
assert_json_include!(actual: json, expected: to_apub);
|
||||||
|
|
||||||
PrivateMessage::delete(&mut context.pool(), pm_id)
|
PrivateMessage::delete(&mut context.pool(), pm_id).await?;
|
||||||
.await
|
cleanup(data, &context).await?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
cleanup(data, &context).await;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn test_parse_pleroma_pm() {
|
async fn test_parse_pleroma_pm() -> LemmyResult<()> {
|
||||||
let context = init_context().await;
|
let context = init_context().await?;
|
||||||
let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap();
|
let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621")?;
|
||||||
let data = prepare_comment_test(&url, &context).await;
|
let data = prepare_comment_test(&url, &context).await?;
|
||||||
let pleroma_url = Url::parse("https://queer.hacktivis.me/objects/2").unwrap();
|
let pleroma_url = Url::parse("https://queer.hacktivis.me/objects/2")?;
|
||||||
let json = file_to_json_object("assets/pleroma/objects/chat_message.json").unwrap();
|
let json = file_to_json_object("assets/pleroma/objects/chat_message.json")?;
|
||||||
ApubPrivateMessage::verify(&json, &pleroma_url, &context)
|
ApubPrivateMessage::verify(&json, &pleroma_url, &context).await?;
|
||||||
.await
|
let pm = ApubPrivateMessage::from_json(json, &context).await?;
|
||||||
.unwrap();
|
|
||||||
let pm = ApubPrivateMessage::from_json(json, &context).await.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(pm.ap_id, pleroma_url.into());
|
assert_eq!(pm.ap_id, pleroma_url.into());
|
||||||
assert_eq!(pm.content.len(), 3);
|
assert_eq!(pm.content.len(), 3);
|
||||||
assert_eq!(context.request_count(), 0);
|
assert_eq!(context.request_count(), 0);
|
||||||
|
|
||||||
PrivateMessage::delete(&mut context.pool(), pm.id)
|
PrivateMessage::delete(&mut context.pool(), pm.id).await?;
|
||||||
.await
|
cleanup(data, &context).await?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
cleanup(data, &context).await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,18 +3,16 @@ pub mod undo_block_user;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use crate::protocol::{
|
use crate::protocol::{
|
||||||
activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
|
activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
|
||||||
tests::test_parse_lemmy_item,
|
tests::test_parse_lemmy_item,
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_lemmy_block() {
|
fn test_parse_lemmy_block() -> LemmyResult<()> {
|
||||||
test_parse_lemmy_item::<BlockUser>("assets/lemmy/activities/block/block_user.json").unwrap();
|
test_parse_lemmy_item::<BlockUser>("assets/lemmy/activities/block/block_user.json")?;
|
||||||
test_parse_lemmy_item::<UndoBlockUser>("assets/lemmy/activities/block/undo_block_user.json")
|
test_parse_lemmy_item::<UndoBlockUser>("assets/lemmy/activities/block/undo_block_user.json")?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,6 @@ pub mod update;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use crate::protocol::{
|
use crate::protocol::{
|
||||||
activities::community::{
|
activities::community::{
|
||||||
announce::AnnounceActivity,
|
announce::AnnounceActivity,
|
||||||
|
@ -21,37 +18,32 @@ mod tests {
|
||||||
},
|
},
|
||||||
tests::test_parse_lemmy_item,
|
tests::test_parse_lemmy_item,
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_lemmy_community_activities() {
|
fn test_parse_lemmy_community_activities() -> LemmyResult<()> {
|
||||||
test_parse_lemmy_item::<AnnounceActivity>(
|
test_parse_lemmy_item::<AnnounceActivity>(
|
||||||
"assets/lemmy/activities/community/announce_create_page.json",
|
"assets/lemmy/activities/community/announce_create_page.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
test_parse_lemmy_item::<CollectionAdd>("assets/lemmy/activities/community/add_mod.json")
|
test_parse_lemmy_item::<CollectionAdd>("assets/lemmy/activities/community/add_mod.json")?;
|
||||||
.unwrap();
|
test_parse_lemmy_item::<CollectionRemove>("assets/lemmy/activities/community/remove_mod.json")?;
|
||||||
test_parse_lemmy_item::<CollectionRemove>("assets/lemmy/activities/community/remove_mod.json")
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
test_parse_lemmy_item::<CollectionAdd>(
|
test_parse_lemmy_item::<CollectionAdd>(
|
||||||
"assets/lemmy/activities/community/add_featured_post.json",
|
"assets/lemmy/activities/community/add_featured_post.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
|
||||||
test_parse_lemmy_item::<CollectionRemove>(
|
test_parse_lemmy_item::<CollectionRemove>(
|
||||||
"assets/lemmy/activities/community/remove_featured_post.json",
|
"assets/lemmy/activities/community/remove_featured_post.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
test_parse_lemmy_item::<LockPage>("assets/lemmy/activities/community/lock_page.json").unwrap();
|
test_parse_lemmy_item::<LockPage>("assets/lemmy/activities/community/lock_page.json")?;
|
||||||
test_parse_lemmy_item::<UndoLockPage>("assets/lemmy/activities/community/undo_lock_page.json")
|
test_parse_lemmy_item::<UndoLockPage>("assets/lemmy/activities/community/undo_lock_page.json")?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
test_parse_lemmy_item::<UpdateCommunity>(
|
test_parse_lemmy_item::<UpdateCommunity>(
|
||||||
"assets/lemmy/activities/community/update_community.json",
|
"assets/lemmy/activities/community/update_community.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
test_parse_lemmy_item::<Report>("assets/lemmy/activities/community/report_page.json").unwrap();
|
test_parse_lemmy_item::<Report>("assets/lemmy/activities/community/report_page.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,6 @@ pub mod page;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use crate::protocol::{
|
use crate::protocol::{
|
||||||
activities::create_or_update::{
|
activities::create_or_update::{
|
||||||
chat_message::CreateOrUpdateChatMessage,
|
chat_message::CreateOrUpdateChatMessage,
|
||||||
|
@ -15,24 +12,22 @@ mod tests {
|
||||||
},
|
},
|
||||||
tests::test_parse_lemmy_item,
|
tests::test_parse_lemmy_item,
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_lemmy_create_or_update() {
|
fn test_parse_lemmy_create_or_update() -> LemmyResult<()> {
|
||||||
test_parse_lemmy_item::<CreateOrUpdatePage>(
|
test_parse_lemmy_item::<CreateOrUpdatePage>(
|
||||||
"assets/lemmy/activities/create_or_update/create_page.json",
|
"assets/lemmy/activities/create_or_update/create_page.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
|
||||||
test_parse_lemmy_item::<CreateOrUpdatePage>(
|
test_parse_lemmy_item::<CreateOrUpdatePage>(
|
||||||
"assets/lemmy/activities/create_or_update/update_page.json",
|
"assets/lemmy/activities/create_or_update/update_page.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
|
||||||
test_parse_lemmy_item::<CreateOrUpdateNote>(
|
test_parse_lemmy_item::<CreateOrUpdateNote>(
|
||||||
"assets/lemmy/activities/create_or_update/create_note.json",
|
"assets/lemmy/activities/create_or_update/create_note.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
|
||||||
test_parse_lemmy_item::<CreateOrUpdateChatMessage>(
|
test_parse_lemmy_item::<CreateOrUpdateChatMessage>(
|
||||||
"assets/lemmy/activities/create_or_update/create_private_message.json",
|
"assets/lemmy/activities/create_or_update/create_private_message.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,31 +4,27 @@ pub mod undo_delete;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use crate::protocol::{
|
use crate::protocol::{
|
||||||
activities::deletion::{delete::Delete, delete_user::DeleteUser, undo_delete::UndoDelete},
|
activities::deletion::{delete::Delete, delete_user::DeleteUser, undo_delete::UndoDelete},
|
||||||
tests::test_parse_lemmy_item,
|
tests::test_parse_lemmy_item,
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_lemmy_deletion() {
|
fn test_parse_lemmy_deletion() -> LemmyResult<()> {
|
||||||
test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/remove_note.json").unwrap();
|
test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/remove_note.json")?;
|
||||||
test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/delete_page.json").unwrap();
|
test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/delete_page.json")?;
|
||||||
|
|
||||||
test_parse_lemmy_item::<UndoDelete>("assets/lemmy/activities/deletion/undo_remove_note.json")
|
test_parse_lemmy_item::<UndoDelete>("assets/lemmy/activities/deletion/undo_remove_note.json")?;
|
||||||
.unwrap();
|
test_parse_lemmy_item::<UndoDelete>("assets/lemmy/activities/deletion/undo_delete_page.json")?;
|
||||||
test_parse_lemmy_item::<UndoDelete>("assets/lemmy/activities/deletion/undo_delete_page.json")
|
test_parse_lemmy_item::<Delete>(
|
||||||
.unwrap();
|
"assets/lemmy/activities/deletion/delete_private_message.json",
|
||||||
test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/delete_private_message.json")
|
)?;
|
||||||
.unwrap();
|
|
||||||
test_parse_lemmy_item::<UndoDelete>(
|
test_parse_lemmy_item::<UndoDelete>(
|
||||||
"assets/lemmy/activities/deletion/undo_delete_private_message.json",
|
"assets/lemmy/activities/deletion/undo_delete_private_message.json",
|
||||||
)
|
)?;
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
test_parse_lemmy_item::<DeleteUser>("assets/lemmy/activities/deletion/delete_user.json")
|
test_parse_lemmy_item::<DeleteUser>("assets/lemmy/activities/deletion/delete_user.json")?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,19 +4,17 @@ pub mod undo_follow;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use crate::protocol::{
|
use crate::protocol::{
|
||||||
activities::following::{accept::AcceptFollow, follow::Follow, undo_follow::UndoFollow},
|
activities::following::{accept::AcceptFollow, follow::Follow, undo_follow::UndoFollow},
|
||||||
tests::test_parse_lemmy_item,
|
tests::test_parse_lemmy_item,
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_lemmy_accept_follow() {
|
fn test_parse_lemmy_accept_follow() -> LemmyResult<()> {
|
||||||
test_parse_lemmy_item::<Follow>("assets/lemmy/activities/following/follow.json").unwrap();
|
test_parse_lemmy_item::<Follow>("assets/lemmy/activities/following/follow.json")?;
|
||||||
test_parse_lemmy_item::<AcceptFollow>("assets/lemmy/activities/following/accept.json").unwrap();
|
test_parse_lemmy_item::<AcceptFollow>("assets/lemmy/activities/following/accept.json")?;
|
||||||
test_parse_lemmy_item::<UndoFollow>("assets/lemmy/activities/following/undo_follow.json")
|
test_parse_lemmy_item::<UndoFollow>("assets/lemmy/activities/following/undo_follow.json")?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,6 @@ pub enum CreateOrUpdateType {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use crate::protocol::{
|
use crate::protocol::{
|
||||||
activities::{
|
activities::{
|
||||||
community::announce::AnnounceActivity,
|
community::announce::AnnounceActivity,
|
||||||
|
@ -29,58 +26,66 @@ mod tests {
|
||||||
},
|
},
|
||||||
tests::test_json,
|
tests::test_json,
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_smithereen_activities() {
|
fn test_parse_smithereen_activities() -> LemmyResult<()> {
|
||||||
test_json::<CreateOrUpdateNote>("assets/smithereen/activities/create_note.json").unwrap();
|
test_json::<CreateOrUpdateNote>("assets/smithereen/activities/create_note.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_pleroma_activities() {
|
fn test_parse_pleroma_activities() -> LemmyResult<()> {
|
||||||
test_json::<CreateOrUpdateNote>("assets/pleroma/activities/create_note.json").unwrap();
|
test_json::<CreateOrUpdateNote>("assets/pleroma/activities/create_note.json")?;
|
||||||
test_json::<Delete>("assets/pleroma/activities/delete.json").unwrap();
|
test_json::<Delete>("assets/pleroma/activities/delete.json")?;
|
||||||
test_json::<Follow>("assets/pleroma/activities/follow.json").unwrap();
|
test_json::<Follow>("assets/pleroma/activities/follow.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_mastodon_activities() {
|
fn test_parse_mastodon_activities() -> LemmyResult<()> {
|
||||||
test_json::<CreateOrUpdateNote>("assets/mastodon/activities/create_note.json").unwrap();
|
test_json::<CreateOrUpdateNote>("assets/mastodon/activities/create_note.json")?;
|
||||||
test_json::<Delete>("assets/mastodon/activities/delete.json").unwrap();
|
test_json::<Delete>("assets/mastodon/activities/delete.json")?;
|
||||||
test_json::<Follow>("assets/mastodon/activities/follow.json").unwrap();
|
test_json::<Follow>("assets/mastodon/activities/follow.json")?;
|
||||||
test_json::<UndoFollow>("assets/mastodon/activities/undo_follow.json").unwrap();
|
test_json::<UndoFollow>("assets/mastodon/activities/undo_follow.json")?;
|
||||||
test_json::<Vote>("assets/mastodon/activities/like_page.json").unwrap();
|
test_json::<Vote>("assets/mastodon/activities/like_page.json")?;
|
||||||
test_json::<UndoVote>("assets/mastodon/activities/undo_like_page.json").unwrap();
|
test_json::<UndoVote>("assets/mastodon/activities/undo_like_page.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_lotide_activities() {
|
fn test_parse_lotide_activities() -> LemmyResult<()> {
|
||||||
test_json::<Follow>("assets/lotide/activities/follow.json").unwrap();
|
test_json::<Follow>("assets/lotide/activities/follow.json")?;
|
||||||
test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page.json").unwrap();
|
test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page.json")?;
|
||||||
test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page_image.json").unwrap();
|
test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page_image.json")?;
|
||||||
test_json::<CreateOrUpdateNote>("assets/lotide/activities/create_note_reply.json").unwrap();
|
test_json::<CreateOrUpdateNote>("assets/lotide/activities/create_note_reply.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_friendica_activities() {
|
fn test_parse_friendica_activities() -> LemmyResult<()> {
|
||||||
test_json::<CreateOrUpdatePage>("assets/friendica/activities/create_page_1.json").unwrap();
|
test_json::<CreateOrUpdatePage>("assets/friendica/activities/create_page_1.json")?;
|
||||||
test_json::<CreateOrUpdatePage>("assets/friendica/activities/create_page_2.json").unwrap();
|
test_json::<CreateOrUpdatePage>("assets/friendica/activities/create_page_2.json")?;
|
||||||
test_json::<CreateOrUpdateNote>("assets/friendica/activities/create_note.json").unwrap();
|
test_json::<CreateOrUpdateNote>("assets/friendica/activities/create_note.json")?;
|
||||||
test_json::<CreateOrUpdateNote>("assets/friendica/activities/update_note.json").unwrap();
|
test_json::<CreateOrUpdateNote>("assets/friendica/activities/update_note.json")?;
|
||||||
test_json::<Delete>("assets/friendica/activities/delete.json").unwrap();
|
test_json::<Delete>("assets/friendica/activities/delete.json")?;
|
||||||
test_json::<Vote>("assets/friendica/activities/like_page.json").unwrap();
|
test_json::<Vote>("assets/friendica/activities/like_page.json")?;
|
||||||
test_json::<Vote>("assets/friendica/activities/dislike_page.json").unwrap();
|
test_json::<Vote>("assets/friendica/activities/dislike_page.json")?;
|
||||||
test_json::<UndoVote>("assets/friendica/activities/undo_dislike_page.json").unwrap();
|
test_json::<UndoVote>("assets/friendica/activities/undo_dislike_page.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_gnusocial_activities() {
|
fn test_parse_gnusocial_activities() -> LemmyResult<()> {
|
||||||
test_json::<CreateOrUpdatePage>("assets/gnusocial/activities/create_page.json").unwrap();
|
test_json::<CreateOrUpdatePage>("assets/gnusocial/activities/create_page.json")?;
|
||||||
test_json::<CreateOrUpdateNote>("assets/gnusocial/activities/create_note.json").unwrap();
|
test_json::<CreateOrUpdateNote>("assets/gnusocial/activities/create_note.json")?;
|
||||||
test_json::<Vote>("assets/gnusocial/activities/like_note.json").unwrap();
|
test_json::<Vote>("assets/gnusocial/activities/like_note.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_peertube_activities() {
|
fn test_parse_peertube_activities() -> LemmyResult<()> {
|
||||||
test_json::<AnnounceActivity>("assets/peertube/activities/announce_video.json").unwrap();
|
test_json::<AnnounceActivity>("assets/peertube/activities/announce_video.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,22 +3,19 @@ pub mod vote;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use crate::protocol::{
|
use crate::protocol::{
|
||||||
activities::voting::{undo_vote::UndoVote, vote::Vote},
|
activities::voting::{undo_vote::UndoVote, vote::Vote},
|
||||||
tests::test_parse_lemmy_item,
|
tests::test_parse_lemmy_item,
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_lemmy_voting() {
|
fn test_parse_lemmy_voting() -> LemmyResult<()> {
|
||||||
test_parse_lemmy_item::<Vote>("assets/lemmy/activities/voting/like_note.json").unwrap();
|
test_parse_lemmy_item::<Vote>("assets/lemmy/activities/voting/like_note.json")?;
|
||||||
test_parse_lemmy_item::<Vote>("assets/lemmy/activities/voting/dislike_page.json").unwrap();
|
test_parse_lemmy_item::<Vote>("assets/lemmy/activities/voting/dislike_page.json")?;
|
||||||
|
|
||||||
test_parse_lemmy_item::<UndoVote>("assets/lemmy/activities/voting/undo_like_note.json")
|
test_parse_lemmy_item::<UndoVote>("assets/lemmy/activities/voting/undo_like_note.json")?;
|
||||||
.unwrap();
|
test_parse_lemmy_item::<UndoVote>("assets/lemmy/activities/voting/undo_dislike_page.json")?;
|
||||||
test_parse_lemmy_item::<UndoVote>("assets/lemmy/activities/voting/undo_dislike_page.json")
|
Ok(())
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,6 @@ pub(crate) mod group_outbox;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use crate::protocol::{
|
use crate::protocol::{
|
||||||
collections::{
|
collections::{
|
||||||
empty_outbox::EmptyOutbox,
|
empty_outbox::EmptyOutbox,
|
||||||
|
@ -19,23 +16,23 @@ mod tests {
|
||||||
},
|
},
|
||||||
tests::{test_json, test_parse_lemmy_item},
|
tests::{test_json, test_parse_lemmy_item},
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_lemmy_collections() {
|
fn test_parse_lemmy_collections() -> LemmyResult<()> {
|
||||||
test_parse_lemmy_item::<GroupFollowers>("assets/lemmy/collections/group_followers.json")
|
test_parse_lemmy_item::<GroupFollowers>("assets/lemmy/collections/group_followers.json")?;
|
||||||
.unwrap();
|
|
||||||
let outbox =
|
let outbox =
|
||||||
test_parse_lemmy_item::<GroupOutbox>("assets/lemmy/collections/group_outbox.json").unwrap();
|
test_parse_lemmy_item::<GroupOutbox>("assets/lemmy/collections/group_outbox.json")?;
|
||||||
assert_eq!(outbox.ordered_items.len() as i32, outbox.total_items);
|
assert_eq!(outbox.ordered_items.len() as i32, outbox.total_items);
|
||||||
test_parse_lemmy_item::<GroupFeatured>("assets/lemmy/collections/group_featured_posts.json")
|
test_parse_lemmy_item::<GroupFeatured>("assets/lemmy/collections/group_featured_posts.json")?;
|
||||||
.unwrap();
|
test_parse_lemmy_item::<GroupModerators>("assets/lemmy/collections/group_moderators.json")?;
|
||||||
test_parse_lemmy_item::<GroupModerators>("assets/lemmy/collections/group_moderators.json")
|
test_parse_lemmy_item::<EmptyOutbox>("assets/lemmy/collections/person_outbox.json")?;
|
||||||
.unwrap();
|
Ok(())
|
||||||
test_parse_lemmy_item::<EmptyOutbox>("assets/lemmy/collections/person_outbox.json").unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_mastodon_collections() {
|
fn test_parse_mastodon_collections() -> LemmyResult<()> {
|
||||||
test_json::<GroupFeatured>("assets/mastodon/collections/featured.json").unwrap();
|
test_json::<GroupFeatured>("assets/mastodon/collections/featured.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,9 +89,6 @@ pub trait InCommunity {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use activitypub_federation::protocol::context::WithContext;
|
use activitypub_federation::protocol::context::WithContext;
|
||||||
use assert_json_diff::assert_json_include;
|
use assert_json_diff::assert_json_include;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
|
@ -95,9 +95,6 @@ impl LanguageTag {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use crate::protocol::{
|
use crate::protocol::{
|
||||||
objects::{
|
objects::{
|
||||||
chat_message::ChatMessage,
|
chat_message::ChatMessage,
|
||||||
|
@ -110,77 +107,87 @@ mod tests {
|
||||||
},
|
},
|
||||||
tests::{test_json, test_parse_lemmy_item},
|
tests::{test_json, test_parse_lemmy_item},
|
||||||
};
|
};
|
||||||
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_objects_lemmy() {
|
fn test_parse_objects_lemmy() -> LemmyResult<()> {
|
||||||
test_parse_lemmy_item::<Instance>("assets/lemmy/objects/instance.json").unwrap();
|
test_parse_lemmy_item::<Instance>("assets/lemmy/objects/instance.json")?;
|
||||||
test_parse_lemmy_item::<Group>("assets/lemmy/objects/group.json").unwrap();
|
test_parse_lemmy_item::<Group>("assets/lemmy/objects/group.json")?;
|
||||||
test_parse_lemmy_item::<Person>("assets/lemmy/objects/person.json").unwrap();
|
test_parse_lemmy_item::<Person>("assets/lemmy/objects/person.json")?;
|
||||||
test_parse_lemmy_item::<Page>("assets/lemmy/objects/page.json").unwrap();
|
test_parse_lemmy_item::<Page>("assets/lemmy/objects/page.json")?;
|
||||||
test_parse_lemmy_item::<Note>("assets/lemmy/objects/note.json").unwrap();
|
test_parse_lemmy_item::<Note>("assets/lemmy/objects/note.json")?;
|
||||||
test_parse_lemmy_item::<ChatMessage>("assets/lemmy/objects/chat_message.json").unwrap();
|
test_parse_lemmy_item::<ChatMessage>("assets/lemmy/objects/chat_message.json")?;
|
||||||
test_parse_lemmy_item::<Tombstone>("assets/lemmy/objects/tombstone.json").unwrap();
|
test_parse_lemmy_item::<Tombstone>("assets/lemmy/objects/tombstone.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_objects_pleroma() {
|
fn test_parse_objects_pleroma() -> LemmyResult<()> {
|
||||||
test_json::<Person>("assets/pleroma/objects/person.json").unwrap();
|
test_json::<Person>("assets/pleroma/objects/person.json")?;
|
||||||
test_json::<Note>("assets/pleroma/objects/note.json").unwrap();
|
test_json::<Note>("assets/pleroma/objects/note.json")?;
|
||||||
test_json::<ChatMessage>("assets/pleroma/objects/chat_message.json").unwrap();
|
test_json::<ChatMessage>("assets/pleroma/objects/chat_message.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_objects_smithereen() {
|
fn test_parse_objects_smithereen() -> LemmyResult<()> {
|
||||||
test_json::<Person>("assets/smithereen/objects/person.json").unwrap();
|
test_json::<Person>("assets/smithereen/objects/person.json")?;
|
||||||
test_json::<Note>("assets/smithereen/objects/note.json").unwrap();
|
test_json::<Note>("assets/smithereen/objects/note.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_objects_mastodon() {
|
fn test_parse_objects_mastodon() -> LemmyResult<()> {
|
||||||
test_json::<Person>("assets/mastodon/objects/person.json").unwrap();
|
test_json::<Person>("assets/mastodon/objects/person.json")?;
|
||||||
test_json::<Note>("assets/mastodon/objects/note.json").unwrap();
|
test_json::<Note>("assets/mastodon/objects/note.json")?;
|
||||||
test_json::<Page>("assets/mastodon/objects/page.json").unwrap();
|
test_json::<Page>("assets/mastodon/objects/page.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_objects_lotide() {
|
fn test_parse_objects_lotide() -> LemmyResult<()> {
|
||||||
test_json::<Group>("assets/lotide/objects/group.json").unwrap();
|
test_json::<Group>("assets/lotide/objects/group.json")?;
|
||||||
test_json::<Person>("assets/lotide/objects/person.json").unwrap();
|
test_json::<Person>("assets/lotide/objects/person.json")?;
|
||||||
test_json::<Note>("assets/lotide/objects/note.json").unwrap();
|
test_json::<Note>("assets/lotide/objects/note.json")?;
|
||||||
test_json::<Page>("assets/lotide/objects/page.json").unwrap();
|
test_json::<Page>("assets/lotide/objects/page.json")?;
|
||||||
test_json::<Tombstone>("assets/lotide/objects/tombstone.json").unwrap();
|
test_json::<Tombstone>("assets/lotide/objects/tombstone.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_object_friendica() {
|
fn test_parse_object_friendica() -> LemmyResult<()> {
|
||||||
test_json::<Person>("assets/friendica/objects/person_1.json").unwrap();
|
test_json::<Person>("assets/friendica/objects/person_1.json")?;
|
||||||
test_json::<Person>("assets/friendica/objects/person_2.json").unwrap();
|
test_json::<Person>("assets/friendica/objects/person_2.json")?;
|
||||||
test_json::<Page>("assets/friendica/objects/page_1.json").unwrap();
|
test_json::<Page>("assets/friendica/objects/page_1.json")?;
|
||||||
test_json::<Page>("assets/friendica/objects/page_2.json").unwrap();
|
test_json::<Page>("assets/friendica/objects/page_2.json")?;
|
||||||
test_json::<Note>("assets/friendica/objects/note_1.json").unwrap();
|
test_json::<Note>("assets/friendica/objects/note_1.json")?;
|
||||||
test_json::<Note>("assets/friendica/objects/note_2.json").unwrap();
|
test_json::<Note>("assets/friendica/objects/note_2.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_object_gnusocial() {
|
fn test_parse_object_gnusocial() -> LemmyResult<()> {
|
||||||
test_json::<Person>("assets/gnusocial/objects/person.json").unwrap();
|
test_json::<Person>("assets/gnusocial/objects/person.json")?;
|
||||||
test_json::<Group>("assets/gnusocial/objects/group.json").unwrap();
|
test_json::<Group>("assets/gnusocial/objects/group.json")?;
|
||||||
test_json::<Page>("assets/gnusocial/objects/page.json").unwrap();
|
test_json::<Page>("assets/gnusocial/objects/page.json")?;
|
||||||
test_json::<Note>("assets/gnusocial/objects/note.json").unwrap();
|
test_json::<Note>("assets/gnusocial/objects/note.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_object_peertube() {
|
fn test_parse_object_peertube() -> LemmyResult<()> {
|
||||||
test_json::<Person>("assets/peertube/objects/person.json").unwrap();
|
test_json::<Person>("assets/peertube/objects/person.json")?;
|
||||||
test_json::<Group>("assets/peertube/objects/group.json").unwrap();
|
test_json::<Group>("assets/peertube/objects/group.json")?;
|
||||||
test_json::<Page>("assets/peertube/objects/video.json").unwrap();
|
test_json::<Page>("assets/peertube/objects/video.json")?;
|
||||||
test_json::<Note>("assets/peertube/objects/note.json").unwrap();
|
test_json::<Note>("assets/peertube/objects/note.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_object_mobilizon() {
|
fn test_parse_object_mobilizon() -> LemmyResult<()> {
|
||||||
test_json::<Group>("assets/mobilizon/objects/group.json").unwrap();
|
test_json::<Group>("assets/mobilizon/objects/group.json")?;
|
||||||
test_json::<Page>("assets/mobilizon/objects/event.json").unwrap();
|
test_json::<Page>("assets/mobilizon/objects/event.json")?;
|
||||||
test_json::<Person>("assets/mobilizon/objects/person.json").unwrap();
|
test_json::<Person>("assets/mobilizon/objects/person.json")?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,9 +242,6 @@ where
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#![allow(clippy::unwrap_used)]
|
|
||||||
#![allow(clippy::indexing_slicing)]
|
|
||||||
|
|
||||||
use crate::protocol::{objects::page::Page, tests::test_parse_lemmy_item};
|
use crate::protocol::{objects::page::Page, tests::test_parse_lemmy_item};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue