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)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use crate::{
|
||||
activity_lists::{GroupInboxActivities, PersonInboxActivities, SharedInboxActivities},
|
||||
protocol::tests::{test_json, test_parse_lemmy_item},
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
||||
#[test]
|
||||
fn test_group_inbox() {
|
||||
test_parse_lemmy_item::<GroupInboxActivities>("assets/lemmy/activities/following/follow.json")
|
||||
.unwrap();
|
||||
fn test_group_inbox() -> LemmyResult<()> {
|
||||
test_parse_lemmy_item::<GroupInboxActivities>("assets/lemmy/activities/following/follow.json")?;
|
||||
test_parse_lemmy_item::<GroupInboxActivities>(
|
||||
"assets/lemmy/activities/create_or_update/create_note.json",
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_person_inbox() {
|
||||
test_parse_lemmy_item::<PersonInboxActivities>("assets/lemmy/activities/following/accept.json")
|
||||
.unwrap();
|
||||
fn test_person_inbox() -> LemmyResult<()> {
|
||||
test_parse_lemmy_item::<PersonInboxActivities>(
|
||||
"assets/lemmy/activities/following/accept.json",
|
||||
)?;
|
||||
test_parse_lemmy_item::<PersonInboxActivities>(
|
||||
"assets/lemmy/activities/create_or_update/create_note.json",
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
test_parse_lemmy_item::<PersonInboxActivities>(
|
||||
"assets/lemmy/activities/create_or_update/create_private_message.json",
|
||||
)
|
||||
.unwrap();
|
||||
test_json::<PersonInboxActivities>("assets/mastodon/activities/follow.json").unwrap();
|
||||
)?;
|
||||
test_json::<PersonInboxActivities>("assets/mastodon/activities/follow.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shared_inbox() {
|
||||
fn test_shared_inbox() -> LemmyResult<()> {
|
||||
test_parse_lemmy_item::<SharedInboxActivities>(
|
||||
"assets/lemmy/activities/deletion/delete_user.json",
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -277,7 +277,6 @@ pub async fn import_settings(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use crate::{
|
||||
|
@ -297,7 +296,7 @@ mod tests {
|
|||
};
|
||||
use lemmy_db_views::structs::LocalUserView;
|
||||
use lemmy_db_views_actor::structs::CommunityFollowerView;
|
||||
use lemmy_utils::error::LemmyErrorType;
|
||||
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
||||
use serial_test::serial;
|
||||
use std::time::Duration;
|
||||
use tokio::time::sleep;
|
||||
|
@ -306,10 +305,8 @@ mod tests {
|
|||
name: String,
|
||||
bio: Option<String>,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> LocalUserView {
|
||||
let instance = Instance::read_or_create(&mut context.pool(), "example.com".to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
) -> LemmyResult<LocalUserView> {
|
||||
let instance = Instance::read_or_create(&mut context.pool(), "example.com".to_string()).await?;
|
||||
let person_form = PersonInsertForm::builder()
|
||||
.name(name.clone())
|
||||
.display_name(Some(name.clone()))
|
||||
|
@ -317,63 +314,49 @@ mod tests {
|
|||
.public_key("asd".to_string())
|
||||
.instance_id(instance.id)
|
||||
.build();
|
||||
let person = Person::create(&mut context.pool(), &person_form)
|
||||
.await
|
||||
.unwrap();
|
||||
let person = Person::create(&mut context.pool(), &person_form).await?;
|
||||
|
||||
let user_form = LocalUserInsertForm::builder()
|
||||
.person_id(person.id)
|
||||
.password_encrypted("pass".to_string())
|
||||
.build();
|
||||
let local_user = LocalUser::create(&mut context.pool(), &user_form)
|
||||
.await
|
||||
.unwrap();
|
||||
let local_user = LocalUser::create(&mut context.pool(), &user_form).await?;
|
||||
|
||||
LocalUserView::read(&mut context.pool(), local_user.id)
|
||||
.await
|
||||
.unwrap()
|
||||
Ok(LocalUserView::read(&mut context.pool(), local_user.id).await?)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_settings_export_import() {
|
||||
let context = init_context().await;
|
||||
async fn test_settings_export_import() -> LemmyResult<()> {
|
||||
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()
|
||||
.name("testcom".to_string())
|
||||
.title("testcom".to_string())
|
||||
.instance_id(export_user.person.instance_id)
|
||||
.build();
|
||||
let community = Community::create(&mut context.pool(), &community_form)
|
||||
.await
|
||||
.unwrap();
|
||||
let community = Community::create(&mut context.pool(), &community_form).await?;
|
||||
let follower_form = CommunityFollowerForm {
|
||||
community_id: community.id,
|
||||
person_id: export_user.person.id,
|
||||
pending: false,
|
||||
};
|
||||
CommunityFollower::follow(&mut context.pool(), &follower_form)
|
||||
.await
|
||||
.unwrap();
|
||||
CommunityFollower::follow(&mut context.pool(), &follower_form).await?;
|
||||
|
||||
let backup = export_settings(export_user.clone(), context.reset_request_count())
|
||||
.await
|
||||
.unwrap();
|
||||
let backup = export_settings(export_user.clone(), context.reset_request_count()).await?;
|
||||
|
||||
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())
|
||||
.await
|
||||
.unwrap();
|
||||
import_settings(backup, import_user.clone(), context.reset_request_count()).await?;
|
||||
|
||||
// wait for background task to finish
|
||||
sleep(Duration::from_millis(1000)).await;
|
||||
|
||||
let import_user_updated = LocalUserView::read(&mut context.pool(), import_user.local_user.id)
|
||||
.await
|
||||
.unwrap();
|
||||
let import_user_updated =
|
||||
LocalUserView::read(&mut context.pool(), import_user.local_user.id).await?;
|
||||
|
||||
assert_eq!(
|
||||
export_user.person.display_name,
|
||||
|
@ -381,61 +364,49 @@ mod tests {
|
|||
);
|
||||
assert_eq!(export_user.person.bio, import_user_updated.person.bio);
|
||||
|
||||
let follows = CommunityFollowerView::for_person(&mut context.pool(), import_user.person.id)
|
||||
.await
|
||||
.unwrap();
|
||||
let follows =
|
||||
CommunityFollowerView::for_person(&mut context.pool(), import_user.person.id).await?;
|
||||
assert_eq!(follows.len(), 1);
|
||||
assert_eq!(follows[0].community.actor_id, community.actor_id);
|
||||
|
||||
LocalUser::delete(&mut context.pool(), export_user.local_user.id)
|
||||
.await
|
||||
.unwrap();
|
||||
LocalUser::delete(&mut context.pool(), import_user.local_user.id)
|
||||
.await
|
||||
.unwrap();
|
||||
LocalUser::delete(&mut context.pool(), export_user.local_user.id).await?;
|
||||
LocalUser::delete(&mut context.pool(), import_user.local_user.id).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn disallow_large_backup() {
|
||||
let context = init_context().await;
|
||||
async fn disallow_large_backup() -> LemmyResult<()> {
|
||||
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())
|
||||
.await
|
||||
.unwrap();
|
||||
let mut backup = export_settings(export_user.clone(), context.reset_request_count()).await?;
|
||||
|
||||
for _ in 0..251 {
|
||||
backup
|
||||
.followed_communities
|
||||
.push("http://example.com".parse().unwrap());
|
||||
.push("http://example.com".parse()?);
|
||||
backup
|
||||
.blocked_communities
|
||||
.push("http://example2.com".parse().unwrap());
|
||||
backup
|
||||
.saved_posts
|
||||
.push("http://example3.com".parse().unwrap());
|
||||
backup
|
||||
.saved_comments
|
||||
.push("http://example4.com".parse().unwrap());
|
||||
.push("http://example2.com".parse()?);
|
||||
backup.saved_posts.push("http://example3.com".parse()?);
|
||||
backup.saved_comments.push("http://example4.com".parse()?);
|
||||
}
|
||||
|
||||
let import_user = create_user("charles".to_string(), None, &context).await;
|
||||
let import_user = create_user("charles".to_string(), None, &context).await?;
|
||||
|
||||
let imported =
|
||||
import_settings(backup, import_user.clone(), context.reset_request_count()).await;
|
||||
|
||||
assert_eq!(
|
||||
imported.err().unwrap().error_type,
|
||||
LemmyErrorType::TooManyItems
|
||||
imported.err().map(|e| e.error_type),
|
||||
Some(LemmyErrorType::TooManyItems)
|
||||
);
|
||||
|
||||
LocalUser::delete(&mut context.pool(), export_user.local_user.id)
|
||||
.await
|
||||
.unwrap();
|
||||
LocalUser::delete(&mut context.pool(), import_user.local_user.id)
|
||||
.await
|
||||
.unwrap();
|
||||
LocalUser::delete(&mut context.pool(), export_user.local_user.id).await?;
|
||||
LocalUser::delete(&mut context.pool(), import_user.local_user.id).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,6 @@ impl Collection for ApubCommunityModerators {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use super::*;
|
||||
|
@ -123,20 +122,19 @@ mod tests {
|
|||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
use serial_test::serial;
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_parse_lemmy_community_moderators() {
|
||||
let context = init_context().await;
|
||||
let (new_mod, site) = parse_lemmy_person(&context).await;
|
||||
let community = parse_lemmy_community(&context).await;
|
||||
async fn test_parse_lemmy_community_moderators() -> LemmyResult<()> {
|
||||
let context = init_context().await?;
|
||||
let (new_mod, site) = parse_lemmy_person(&context).await?;
|
||||
let community = parse_lemmy_community(&context).await?;
|
||||
let community_id = community.id;
|
||||
|
||||
let inserted_instance =
|
||||
Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string())
|
||||
.await
|
||||
.unwrap();
|
||||
Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?;
|
||||
|
||||
let old_mod = PersonInsertForm::builder()
|
||||
.name("holly".into())
|
||||
|
@ -144,49 +142,34 @@ mod tests {
|
|||
.instance_id(inserted_instance.id)
|
||||
.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 {
|
||||
community_id: community.id,
|
||||
person_id: old_mod.id,
|
||||
};
|
||||
|
||||
CommunityModerator::join(&mut context.pool(), &community_moderator_form)
|
||||
.await
|
||||
.unwrap();
|
||||
CommunityModerator::join(&mut context.pool(), &community_moderator_form).await?;
|
||||
|
||||
assert_eq!(site.actor_id.to_string(), "https://enterprise.lemmy.ml/");
|
||||
|
||||
let json: GroupModerators =
|
||||
file_to_json_object("assets/lemmy/collections/group_moderators.json").unwrap();
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/c/tenforward").unwrap();
|
||||
ApubCommunityModerators::verify(&json, &url, &context)
|
||||
.await
|
||||
.unwrap();
|
||||
ApubCommunityModerators::from_json(json, &community, &context)
|
||||
.await
|
||||
.unwrap();
|
||||
file_to_json_object("assets/lemmy/collections/group_moderators.json")?;
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/c/tenforward")?;
|
||||
ApubCommunityModerators::verify(&json, &url, &context).await?;
|
||||
ApubCommunityModerators::from_json(json, &community, &context).await?;
|
||||
assert_eq!(context.request_count(), 0);
|
||||
|
||||
let current_moderators =
|
||||
CommunityModeratorView::for_community(&mut context.pool(), community_id)
|
||||
.await
|
||||
.unwrap();
|
||||
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||
|
||||
assert_eq!(current_moderators.len(), 1);
|
||||
assert_eq!(current_moderators[0].moderator.id, new_mod.id);
|
||||
|
||||
Person::delete(&mut context.pool(), old_mod.id)
|
||||
.await
|
||||
.unwrap();
|
||||
Person::delete(&mut context.pool(), new_mod.id)
|
||||
.await
|
||||
.unwrap();
|
||||
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();
|
||||
Person::delete(&mut context.pool(), old_mod.id).await?;
|
||||
Person::delete(&mut context.pool(), new_mod.id).await?;
|
||||
Community::delete(&mut context.pool(), community.id).await?;
|
||||
Site::delete(&mut context.pool(), site.id).await?;
|
||||
Instance::delete(&mut context.pool(), inserted_instance.id).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -183,9 +183,6 @@ impl Object for ApubComment {
|
|||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
objects::{
|
||||
|
@ -200,46 +197,45 @@ pub(crate) mod tests {
|
|||
use assert_json_diff::assert_json_include;
|
||||
use html2md::parse_html;
|
||||
use lemmy_db_schema::source::site::Site;
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
use serial_test::serial;
|
||||
|
||||
async fn prepare_comment_test(
|
||||
url: &Url,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> (ApubPerson, ApubCommunity, ApubPost, ApubSite) {
|
||||
) -> LemmyResult<(ApubPerson, ApubCommunity, ApubPost, ApubSite)> {
|
||||
// use separate counter so this doesnt affect tests
|
||||
let context2 = context.reset_request_count();
|
||||
let (person, site) = parse_lemmy_person(&context2).await;
|
||||
let community = parse_lemmy_community(&context2).await;
|
||||
let post_json = file_to_json_object("assets/lemmy/objects/page.json").unwrap();
|
||||
ApubPost::verify(&post_json, url, &context2).await.unwrap();
|
||||
let post = ApubPost::from_json(post_json, &context2).await.unwrap();
|
||||
(person, community, post, site)
|
||||
let (person, site) = parse_lemmy_person(&context2).await?;
|
||||
let community = parse_lemmy_community(&context2).await?;
|
||||
let post_json = file_to_json_object("assets/lemmy/objects/page.json")?;
|
||||
ApubPost::verify(&post_json, url, &context2).await?;
|
||||
let post = ApubPost::from_json(post_json, &context2).await?;
|
||||
Ok((person, community, post, site))
|
||||
}
|
||||
|
||||
async fn cleanup(data: (ApubPerson, ApubCommunity, ApubPost, ApubSite), context: &LemmyContext) {
|
||||
Post::delete(&mut context.pool(), data.2.id).await.unwrap();
|
||||
Community::delete(&mut context.pool(), data.1.id)
|
||||
.await
|
||||
.unwrap();
|
||||
Person::delete(&mut context.pool(), data.0.id)
|
||||
.await
|
||||
.unwrap();
|
||||
Site::delete(&mut context.pool(), data.3.id).await.unwrap();
|
||||
LocalSite::delete(&mut context.pool()).await.unwrap();
|
||||
async fn cleanup(
|
||||
data: (ApubPerson, ApubCommunity, ApubPost, ApubSite),
|
||||
context: &LemmyContext,
|
||||
) -> LemmyResult<()> {
|
||||
Post::delete(&mut context.pool(), data.2.id).await?;
|
||||
Community::delete(&mut context.pool(), data.1.id).await?;
|
||||
Person::delete(&mut context.pool(), data.0.id).await?;
|
||||
Site::delete(&mut context.pool(), data.3.id).await?;
|
||||
LocalSite::delete(&mut context.pool()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
pub(crate) async fn test_parse_lemmy_comment() {
|
||||
let context = init_context().await;
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741").unwrap();
|
||||
let data = prepare_comment_test(&url, &context).await;
|
||||
pub(crate) async fn test_parse_lemmy_comment() -> LemmyResult<()> {
|
||||
let context = init_context().await?;
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741")?;
|
||||
let data = prepare_comment_test(&url, &context).await?;
|
||||
|
||||
let json: Note = file_to_json_object("assets/lemmy/objects/note.json").unwrap();
|
||||
ApubComment::verify(&json, &url, &context).await.unwrap();
|
||||
let comment = ApubComment::from_json(json.clone(), &context)
|
||||
.await
|
||||
.unwrap();
|
||||
let json: Note = file_to_json_object("assets/lemmy/objects/note.json")?;
|
||||
ApubComment::verify(&json, &url, &context).await?;
|
||||
let comment = ApubComment::from_json(json.clone(), &context).await?;
|
||||
|
||||
assert_eq!(comment.ap_id, url.into());
|
||||
assert_eq!(comment.content.len(), 14);
|
||||
|
@ -247,45 +243,38 @@ pub(crate) mod tests {
|
|||
assert_eq!(context.request_count(), 0);
|
||||
|
||||
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);
|
||||
|
||||
Comment::delete(&mut context.pool(), comment_id)
|
||||
.await
|
||||
.unwrap();
|
||||
cleanup(data, &context).await;
|
||||
Comment::delete(&mut context.pool(), comment_id).await?;
|
||||
cleanup(data, &context).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_parse_pleroma_comment() {
|
||||
let context = init_context().await;
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741").unwrap();
|
||||
let data = prepare_comment_test(&url, &context).await;
|
||||
async fn test_parse_pleroma_comment() -> LemmyResult<()> {
|
||||
let context = init_context().await?;
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/comment/38741")?;
|
||||
let data = prepare_comment_test(&url, &context).await?;
|
||||
|
||||
let pleroma_url =
|
||||
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").unwrap();
|
||||
ApubPerson::verify(&person_json, &pleroma_url, &context)
|
||||
.await
|
||||
.unwrap();
|
||||
ApubPerson::from_json(person_json, &context).await.unwrap();
|
||||
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();
|
||||
Url::parse("https://queer.hacktivis.me/objects/8d4973f4-53de-49cd-8c27-df160e16a9c2")?;
|
||||
let person_json = file_to_json_object("assets/pleroma/objects/person.json")?;
|
||||
ApubPerson::verify(&person_json, &pleroma_url, &context).await?;
|
||||
ApubPerson::from_json(person_json, &context).await?;
|
||||
let json = file_to_json_object("assets/pleroma/objects/note.json")?;
|
||||
ApubComment::verify(&json, &pleroma_url, &context).await?;
|
||||
let comment = ApubComment::from_json(json, &context).await?;
|
||||
|
||||
assert_eq!(comment.ap_id, pleroma_url.into());
|
||||
assert_eq!(comment.content.len(), 64);
|
||||
assert!(!comment.local);
|
||||
assert_eq!(context.request_count(), 1);
|
||||
|
||||
Comment::delete(&mut context.pool(), comment.id)
|
||||
.await
|
||||
.unwrap();
|
||||
cleanup(data, &context).await;
|
||||
Comment::delete(&mut context.pool(), comment.id).await?;
|
||||
cleanup(data, &context).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
|
|
@ -216,9 +216,6 @@ impl ApubCommunity {
|
|||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
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 lemmy_db_schema::{source::site::Site, traits::Crud};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
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
|
||||
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
|
||||
json.attributed_to = None;
|
||||
json.outbox =
|
||||
CollectionId::parse("https://enterprise.lemmy.ml/c/tenforward/not_outbox").unwrap();
|
||||
json.followers =
|
||||
CollectionId::parse("https://enterprise.lemmy.ml/c/tenforward/not_followers").unwrap();
|
||||
json.outbox = CollectionId::parse("https://enterprise.lemmy.ml/c/tenforward/not_outbox")?;
|
||||
json.followers = CollectionId::parse("https://enterprise.lemmy.ml/c/tenforward/not_followers")?;
|
||||
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/c/tenforward").unwrap();
|
||||
ApubCommunity::verify(&json, &url, &context2).await.unwrap();
|
||||
let community = ApubCommunity::from_json(json, &context2).await.unwrap();
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/c/tenforward")?;
|
||||
ApubCommunity::verify(&json, &url, &context2).await?;
|
||||
let community = ApubCommunity::from_json(json, &context2).await?;
|
||||
// this makes requests to the (intentionally broken) outbox and followers collections
|
||||
assert_eq!(context2.request_count(), 2);
|
||||
community
|
||||
Ok(community)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_parse_lemmy_community() {
|
||||
let context = init_context().await;
|
||||
let site = parse_lemmy_instance(&context).await;
|
||||
let community = parse_lemmy_community(&context).await;
|
||||
async fn test_parse_lemmy_community() -> LemmyResult<()> {
|
||||
let context = init_context().await?;
|
||||
let site = parse_lemmy_instance(&context).await?;
|
||||
let community = parse_lemmy_community(&context).await?;
|
||||
|
||||
assert_eq!(community.title, "Ten Forward");
|
||||
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)
|
||||
.await
|
||||
.unwrap();
|
||||
Site::delete(&mut context.pool(), site.id).await.unwrap();
|
||||
Community::delete(&mut context.pool(), community.id).await?;
|
||||
Site::delete(&mut context.pool(), site.id).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,32 +204,34 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object<T: Into<Url> + C
|
|||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use super::*;
|
||||
use crate::{objects::tests::init_context, protocol::tests::file_to_json_object};
|
||||
use lemmy_db_schema::traits::Crud;
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
use serial_test::serial;
|
||||
|
||||
pub(crate) async fn parse_lemmy_instance(context: &Data<LemmyContext>) -> ApubSite {
|
||||
let json: Instance = file_to_json_object("assets/lemmy/objects/instance.json").unwrap();
|
||||
let id = Url::parse("https://enterprise.lemmy.ml/").unwrap();
|
||||
ApubSite::verify(&json, &id, context).await.unwrap();
|
||||
let site = ApubSite::from_json(json, context).await.unwrap();
|
||||
pub(crate) async fn parse_lemmy_instance(context: &Data<LemmyContext>) -> LemmyResult<ApubSite> {
|
||||
let json: Instance = file_to_json_object("assets/lemmy/objects/instance.json")?;
|
||||
let id = Url::parse("https://enterprise.lemmy.ml/")?;
|
||||
ApubSite::verify(&json, &id, context).await?;
|
||||
let site = ApubSite::from_json(json, context).await?;
|
||||
assert_eq!(context.request_count(), 0);
|
||||
site
|
||||
Ok(site)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_parse_lemmy_instance() {
|
||||
let context = init_context().await;
|
||||
let site = parse_lemmy_instance(&context).await;
|
||||
async fn test_parse_lemmy_instance() -> LemmyResult<()> {
|
||||
let context = init_context().await?;
|
||||
let site = parse_lemmy_instance(&context).await?;
|
||||
|
||||
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)]
|
||||
pub(crate) mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use activitypub_federation::config::{Data, FederationConfig};
|
||||
use anyhow::anyhow;
|
||||
use lemmy_api_common::{context::LemmyContext, request::client_builder};
|
||||
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_middleware::{ClientBuilder, Middleware, Next};
|
||||
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.
|
||||
pub(crate) async fn init_context() -> Data<LemmyContext> {
|
||||
pub(crate) async fn init_context() -> LemmyResult<Data<LemmyContext>> {
|
||||
// call this to run migrations
|
||||
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 secret = Secret {
|
||||
|
@ -101,8 +98,7 @@ pub(crate) mod tests {
|
|||
.domain("example.com")
|
||||
.app_data(context)
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
config.to_request_data()
|
||||
.await?;
|
||||
Ok(config.to_request_data())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -208,9 +208,6 @@ impl GetActorType for ApubPerson {
|
|||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
objects::{
|
||||
|
@ -221,60 +218,64 @@ pub(crate) mod tests {
|
|||
};
|
||||
use activitypub_federation::fetch::object_id::ObjectId;
|
||||
use lemmy_db_schema::{source::site::Site, traits::Crud};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
use serial_test::serial;
|
||||
|
||||
pub(crate) async fn parse_lemmy_person(context: &Data<LemmyContext>) -> (ApubPerson, ApubSite) {
|
||||
let site = parse_lemmy_instance(context).await;
|
||||
let json = file_to_json_object("assets/lemmy/objects/person.json").unwrap();
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/u/picard").unwrap();
|
||||
ApubPerson::verify(&json, &url, context).await.unwrap();
|
||||
let person = ApubPerson::from_json(json, context).await.unwrap();
|
||||
pub(crate) async fn parse_lemmy_person(
|
||||
context: &Data<LemmyContext>,
|
||||
) -> LemmyResult<(ApubPerson, ApubSite)> {
|
||||
let site = parse_lemmy_instance(context).await?;
|
||||
let json = file_to_json_object("assets/lemmy/objects/person.json")?;
|
||||
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);
|
||||
(person, site)
|
||||
Ok((person, site))
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_parse_lemmy_person() {
|
||||
let context = init_context().await;
|
||||
let (person, site) = parse_lemmy_person(&context).await;
|
||||
async fn test_parse_lemmy_person() -> LemmyResult<()> {
|
||||
let context = init_context().await?;
|
||||
let (person, site) = parse_lemmy_person(&context).await?;
|
||||
|
||||
assert_eq!(person.display_name, Some("Jean-Luc Picard".to_string()));
|
||||
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]
|
||||
#[serial]
|
||||
async fn test_parse_pleroma_person() {
|
||||
let context = init_context().await;
|
||||
async fn test_parse_pleroma_person() -> LemmyResult<()> {
|
||||
let context = init_context().await?;
|
||||
|
||||
// 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();
|
||||
json.id = ObjectId::parse("https://queer.hacktivis.me/").unwrap();
|
||||
let url = Url::parse("https://queer.hacktivis.me/users/lanodan").unwrap();
|
||||
ApubSite::verify(&json, &url, &context).await.unwrap();
|
||||
let site = ApubSite::from_json(json, &context).await.unwrap();
|
||||
let mut json: Instance = file_to_json_object("assets/lemmy/objects/instance.json")?;
|
||||
json.id = ObjectId::parse("https://queer.hacktivis.me/")?;
|
||||
let url = Url::parse("https://queer.hacktivis.me/users/lanodan")?;
|
||||
ApubSite::verify(&json, &url, &context).await?;
|
||||
let site = ApubSite::from_json(json, &context).await?;
|
||||
|
||||
let json = file_to_json_object("assets/pleroma/objects/person.json").unwrap();
|
||||
ApubPerson::verify(&json, &url, &context).await.unwrap();
|
||||
let person = ApubPerson::from_json(json, &context).await.unwrap();
|
||||
let json = file_to_json_object("assets/pleroma/objects/person.json")?;
|
||||
ApubPerson::verify(&json, &url, &context).await?;
|
||||
let person = ApubPerson::from_json(json, &context).await?;
|
||||
|
||||
assert_eq!(person.actor_id, url.into());
|
||||
assert_eq!(person.name, "lanodan");
|
||||
assert!(!person.local);
|
||||
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) {
|
||||
DbPerson::delete(&mut context.pool(), data.0.id)
|
||||
.await
|
||||
.unwrap();
|
||||
Site::delete(&mut context.pool(), data.1.id).await.unwrap();
|
||||
async fn cleanup(data: (ApubPerson, ApubSite), context: &LemmyContext) -> LemmyResult<()> {
|
||||
DbPerson::delete(&mut context.pool(), data.0.id).await?;
|
||||
Site::delete(&mut context.pool(), data.1.id).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -292,9 +292,6 @@ impl Object for ApubPost {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
objects::{
|
||||
|
@ -307,44 +304,47 @@ mod tests {
|
|||
protocol::tests::file_to_json_object,
|
||||
};
|
||||
use lemmy_db_schema::source::site::Site;
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
use serial_test::serial;
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_parse_lemmy_post() {
|
||||
let context = init_context().await;
|
||||
let (person, site) = parse_lemmy_person(&context).await;
|
||||
let community = parse_lemmy_community(&context).await;
|
||||
async fn test_parse_lemmy_post() -> LemmyResult<()> {
|
||||
let context = init_context().await?;
|
||||
let (person, site) = parse_lemmy_person(&context).await?;
|
||||
let community = parse_lemmy_community(&context).await?;
|
||||
|
||||
let json = file_to_json_object("assets/lemmy/objects/page.json").unwrap();
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/post/55143").unwrap();
|
||||
ApubPost::verify(&json, &url, &context).await.unwrap();
|
||||
let post = ApubPost::from_json(json, &context).await.unwrap();
|
||||
let json = file_to_json_object("assets/lemmy/objects/page.json")?;
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/post/55143")?;
|
||||
ApubPost::verify(&json, &url, &context).await?;
|
||||
let post = ApubPost::from_json(json, &context).await?;
|
||||
|
||||
assert_eq!(post.ap_id, url.into());
|
||||
assert_eq!(post.name, "Post title");
|
||||
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.featured_community);
|
||||
assert_eq!(context.request_count(), 0);
|
||||
|
||||
cleanup(&context, person, site, community, post).await;
|
||||
cleanup(&context, person, site, community, post).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_convert_mastodon_post_title() {
|
||||
let context = init_context().await;
|
||||
let (person, site) = parse_lemmy_person(&context).await;
|
||||
let community = parse_lemmy_community(&context).await;
|
||||
async fn test_convert_mastodon_post_title() -> LemmyResult<()> {
|
||||
let context = init_context().await?;
|
||||
let (person, site) = parse_lemmy_person(&context).await?;
|
||||
let community = parse_lemmy_community(&context).await?;
|
||||
|
||||
let json = file_to_json_object("assets/mastodon/objects/page.json").unwrap();
|
||||
let post = ApubPost::from_json(json, &context).await.unwrap();
|
||||
let json = file_to_json_object("assets/mastodon/objects/page.json")?;
|
||||
let post = ApubPost::from_json(json, &context).await?;
|
||||
|
||||
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(
|
||||
|
@ -353,14 +353,11 @@ mod tests {
|
|||
site: ApubSite,
|
||||
community: ApubCommunity,
|
||||
post: ApubPost,
|
||||
) {
|
||||
Post::delete(&mut context.pool(), post.id).await.unwrap();
|
||||
Person::delete(&mut context.pool(), person.id)
|
||||
.await
|
||||
.unwrap();
|
||||
Community::delete(&mut context.pool(), community.id)
|
||||
.await
|
||||
.unwrap();
|
||||
Site::delete(&mut context.pool(), site.id).await.unwrap();
|
||||
) -> LemmyResult<()> {
|
||||
Post::delete(&mut context.pool(), post.id).await?;
|
||||
Person::delete(&mut context.pool(), person.id).await?;
|
||||
Community::delete(&mut context.pool(), community.id).await?;
|
||||
Site::delete(&mut context.pool(), site.id).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,9 +141,6 @@ impl Object for ApubPrivateMessage {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use super::*;
|
||||
use crate::{
|
||||
objects::{
|
||||
|
@ -155,90 +152,75 @@ mod tests {
|
|||
};
|
||||
use assert_json_diff::assert_json_include;
|
||||
use lemmy_db_schema::source::site::Site;
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
use serial_test::serial;
|
||||
|
||||
async fn prepare_comment_test(
|
||||
url: &Url,
|
||||
context: &Data<LemmyContext>,
|
||||
) -> (ApubPerson, ApubPerson, ApubSite) {
|
||||
) -> LemmyResult<(ApubPerson, ApubPerson, ApubSite)> {
|
||||
let context2 = context.reset_request_count();
|
||||
let lemmy_person = file_to_json_object("assets/lemmy/objects/person.json").unwrap();
|
||||
let site = parse_lemmy_instance(&context2).await;
|
||||
ApubPerson::verify(&lemmy_person, url, &context2)
|
||||
.await
|
||||
.unwrap();
|
||||
let person1 = ApubPerson::from_json(lemmy_person, &context2)
|
||||
.await
|
||||
.unwrap();
|
||||
let pleroma_person = file_to_json_object("assets/pleroma/objects/person.json").unwrap();
|
||||
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)
|
||||
let lemmy_person = file_to_json_object("assets/lemmy/objects/person.json")?;
|
||||
let site = parse_lemmy_instance(&context2).await?;
|
||||
ApubPerson::verify(&lemmy_person, url, &context2).await?;
|
||||
let person1 = ApubPerson::from_json(lemmy_person, &context2).await?;
|
||||
let pleroma_person = file_to_json_object("assets/pleroma/objects/person.json")?;
|
||||
let pleroma_url = Url::parse("https://queer.hacktivis.me/users/lanodan")?;
|
||||
ApubPerson::verify(&pleroma_person, &pleroma_url, &context2).await?;
|
||||
let person2 = ApubPerson::from_json(pleroma_person, &context2).await?;
|
||||
Ok((person1, person2, site))
|
||||
}
|
||||
|
||||
async fn cleanup(data: (ApubPerson, ApubPerson, ApubSite), context: &Data<LemmyContext>) {
|
||||
Person::delete(&mut context.pool(), data.0.id)
|
||||
.await
|
||||
.unwrap();
|
||||
Person::delete(&mut context.pool(), data.1.id)
|
||||
.await
|
||||
.unwrap();
|
||||
Site::delete(&mut context.pool(), data.2.id).await.unwrap();
|
||||
async fn cleanup(
|
||||
data: (ApubPerson, ApubPerson, ApubSite),
|
||||
context: &Data<LemmyContext>,
|
||||
) -> LemmyResult<()> {
|
||||
Person::delete(&mut context.pool(), data.0.id).await?;
|
||||
Person::delete(&mut context.pool(), data.1.id).await?;
|
||||
Site::delete(&mut context.pool(), data.2.id).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_parse_lemmy_pm() {
|
||||
let context = init_context().await;
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap();
|
||||
let data = prepare_comment_test(&url, &context).await;
|
||||
let json: ChatMessage = file_to_json_object("assets/lemmy/objects/chat_message.json").unwrap();
|
||||
ApubPrivateMessage::verify(&json, &url, &context)
|
||||
.await
|
||||
.unwrap();
|
||||
let pm = ApubPrivateMessage::from_json(json.clone(), &context)
|
||||
.await
|
||||
.unwrap();
|
||||
async fn test_parse_lemmy_pm() -> LemmyResult<()> {
|
||||
let context = init_context().await?;
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621")?;
|
||||
let data = prepare_comment_test(&url, &context).await?;
|
||||
let json: ChatMessage = file_to_json_object("assets/lemmy/objects/chat_message.json")?;
|
||||
ApubPrivateMessage::verify(&json, &url, &context).await?;
|
||||
let pm = ApubPrivateMessage::from_json(json.clone(), &context).await?;
|
||||
|
||||
assert_eq!(pm.ap_id.clone(), url.into());
|
||||
assert_eq!(pm.content.len(), 20);
|
||||
assert_eq!(context.request_count(), 0);
|
||||
|
||||
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);
|
||||
|
||||
PrivateMessage::delete(&mut context.pool(), pm_id)
|
||||
.await
|
||||
.unwrap();
|
||||
cleanup(data, &context).await;
|
||||
PrivateMessage::delete(&mut context.pool(), pm_id).await?;
|
||||
cleanup(data, &context).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_parse_pleroma_pm() {
|
||||
let context = init_context().await;
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621").unwrap();
|
||||
let data = prepare_comment_test(&url, &context).await;
|
||||
let pleroma_url = Url::parse("https://queer.hacktivis.me/objects/2").unwrap();
|
||||
let json = file_to_json_object("assets/pleroma/objects/chat_message.json").unwrap();
|
||||
ApubPrivateMessage::verify(&json, &pleroma_url, &context)
|
||||
.await
|
||||
.unwrap();
|
||||
let pm = ApubPrivateMessage::from_json(json, &context).await.unwrap();
|
||||
async fn test_parse_pleroma_pm() -> LemmyResult<()> {
|
||||
let context = init_context().await?;
|
||||
let url = Url::parse("https://enterprise.lemmy.ml/private_message/1621")?;
|
||||
let data = prepare_comment_test(&url, &context).await?;
|
||||
let pleroma_url = Url::parse("https://queer.hacktivis.me/objects/2")?;
|
||||
let json = file_to_json_object("assets/pleroma/objects/chat_message.json")?;
|
||||
ApubPrivateMessage::verify(&json, &pleroma_url, &context).await?;
|
||||
let pm = ApubPrivateMessage::from_json(json, &context).await?;
|
||||
|
||||
assert_eq!(pm.ap_id, pleroma_url.into());
|
||||
assert_eq!(pm.content.len(), 3);
|
||||
assert_eq!(context.request_count(), 0);
|
||||
|
||||
PrivateMessage::delete(&mut context.pool(), pm.id)
|
||||
.await
|
||||
.unwrap();
|
||||
cleanup(data, &context).await;
|
||||
PrivateMessage::delete(&mut context.pool(), pm.id).await?;
|
||||
cleanup(data, &context).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,18 +3,16 @@ pub mod undo_block_user;
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use crate::protocol::{
|
||||
activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
|
||||
tests::test_parse_lemmy_item,
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
||||
#[test]
|
||||
fn test_parse_lemmy_block() {
|
||||
test_parse_lemmy_item::<BlockUser>("assets/lemmy/activities/block/block_user.json").unwrap();
|
||||
test_parse_lemmy_item::<UndoBlockUser>("assets/lemmy/activities/block/undo_block_user.json")
|
||||
.unwrap();
|
||||
fn test_parse_lemmy_block() -> LemmyResult<()> {
|
||||
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")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,9 +7,6 @@ pub mod update;
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use crate::protocol::{
|
||||
activities::community::{
|
||||
announce::AnnounceActivity,
|
||||
|
@ -21,37 +18,32 @@ mod tests {
|
|||
},
|
||||
tests::test_parse_lemmy_item,
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
||||
#[test]
|
||||
fn test_parse_lemmy_community_activities() {
|
||||
fn test_parse_lemmy_community_activities() -> LemmyResult<()> {
|
||||
test_parse_lemmy_item::<AnnounceActivity>(
|
||||
"assets/lemmy/activities/community/announce_create_page.json",
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
|
||||
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")
|
||||
.unwrap();
|
||||
test_parse_lemmy_item::<CollectionAdd>("assets/lemmy/activities/community/add_mod.json")?;
|
||||
test_parse_lemmy_item::<CollectionRemove>("assets/lemmy/activities/community/remove_mod.json")?;
|
||||
|
||||
test_parse_lemmy_item::<CollectionAdd>(
|
||||
"assets/lemmy/activities/community/add_featured_post.json",
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
test_parse_lemmy_item::<CollectionRemove>(
|
||||
"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::<UndoLockPage>("assets/lemmy/activities/community/undo_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::<UpdateCommunity>(
|
||||
"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)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use crate::protocol::{
|
||||
activities::create_or_update::{
|
||||
chat_message::CreateOrUpdateChatMessage,
|
||||
|
@ -15,24 +12,22 @@ mod tests {
|
|||
},
|
||||
tests::test_parse_lemmy_item,
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
||||
#[test]
|
||||
fn test_parse_lemmy_create_or_update() {
|
||||
fn test_parse_lemmy_create_or_update() -> LemmyResult<()> {
|
||||
test_parse_lemmy_item::<CreateOrUpdatePage>(
|
||||
"assets/lemmy/activities/create_or_update/create_page.json",
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
test_parse_lemmy_item::<CreateOrUpdatePage>(
|
||||
"assets/lemmy/activities/create_or_update/update_page.json",
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
test_parse_lemmy_item::<CreateOrUpdateNote>(
|
||||
"assets/lemmy/activities/create_or_update/create_note.json",
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
test_parse_lemmy_item::<CreateOrUpdateChatMessage>(
|
||||
"assets/lemmy/activities/create_or_update/create_private_message.json",
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,31 +4,27 @@ pub mod undo_delete;
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use crate::protocol::{
|
||||
activities::deletion::{delete::Delete, delete_user::DeleteUser, undo_delete::UndoDelete},
|
||||
tests::test_parse_lemmy_item,
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
||||
#[test]
|
||||
fn test_parse_lemmy_deletion() {
|
||||
test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/remove_note.json").unwrap();
|
||||
test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/delete_page.json").unwrap();
|
||||
fn test_parse_lemmy_deletion() -> LemmyResult<()> {
|
||||
test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/remove_note.json")?;
|
||||
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")
|
||||
.unwrap();
|
||||
test_parse_lemmy_item::<UndoDelete>("assets/lemmy/activities/deletion/undo_delete_page.json")
|
||||
.unwrap();
|
||||
test_parse_lemmy_item::<Delete>("assets/lemmy/activities/deletion/delete_private_message.json")
|
||||
.unwrap();
|
||||
test_parse_lemmy_item::<UndoDelete>("assets/lemmy/activities/deletion/undo_remove_note.json")?;
|
||||
test_parse_lemmy_item::<UndoDelete>("assets/lemmy/activities/deletion/undo_delete_page.json")?;
|
||||
test_parse_lemmy_item::<Delete>(
|
||||
"assets/lemmy/activities/deletion/delete_private_message.json",
|
||||
)?;
|
||||
test_parse_lemmy_item::<UndoDelete>(
|
||||
"assets/lemmy/activities/deletion/undo_delete_private_message.json",
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
|
||||
test_parse_lemmy_item::<DeleteUser>("assets/lemmy/activities/deletion/delete_user.json")
|
||||
.unwrap();
|
||||
test_parse_lemmy_item::<DeleteUser>("assets/lemmy/activities/deletion/delete_user.json")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,19 +4,17 @@ pub mod undo_follow;
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use crate::protocol::{
|
||||
activities::following::{accept::AcceptFollow, follow::Follow, undo_follow::UndoFollow},
|
||||
tests::test_parse_lemmy_item,
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
||||
#[test]
|
||||
fn test_parse_lemmy_accept_follow() {
|
||||
test_parse_lemmy_item::<Follow>("assets/lemmy/activities/following/follow.json").unwrap();
|
||||
test_parse_lemmy_item::<AcceptFollow>("assets/lemmy/activities/following/accept.json").unwrap();
|
||||
test_parse_lemmy_item::<UndoFollow>("assets/lemmy/activities/following/undo_follow.json")
|
||||
.unwrap();
|
||||
fn test_parse_lemmy_accept_follow() -> LemmyResult<()> {
|
||||
test_parse_lemmy_item::<Follow>("assets/lemmy/activities/following/follow.json")?;
|
||||
test_parse_lemmy_item::<AcceptFollow>("assets/lemmy/activities/following/accept.json")?;
|
||||
test_parse_lemmy_item::<UndoFollow>("assets/lemmy/activities/following/undo_follow.json")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,6 @@ pub enum CreateOrUpdateType {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use crate::protocol::{
|
||||
activities::{
|
||||
community::announce::AnnounceActivity,
|
||||
|
@ -29,58 +26,66 @@ mod tests {
|
|||
},
|
||||
tests::test_json,
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
||||
#[test]
|
||||
fn test_parse_smithereen_activities() {
|
||||
test_json::<CreateOrUpdateNote>("assets/smithereen/activities/create_note.json").unwrap();
|
||||
fn test_parse_smithereen_activities() -> LemmyResult<()> {
|
||||
test_json::<CreateOrUpdateNote>("assets/smithereen/activities/create_note.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_pleroma_activities() {
|
||||
test_json::<CreateOrUpdateNote>("assets/pleroma/activities/create_note.json").unwrap();
|
||||
test_json::<Delete>("assets/pleroma/activities/delete.json").unwrap();
|
||||
test_json::<Follow>("assets/pleroma/activities/follow.json").unwrap();
|
||||
fn test_parse_pleroma_activities() -> LemmyResult<()> {
|
||||
test_json::<CreateOrUpdateNote>("assets/pleroma/activities/create_note.json")?;
|
||||
test_json::<Delete>("assets/pleroma/activities/delete.json")?;
|
||||
test_json::<Follow>("assets/pleroma/activities/follow.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_mastodon_activities() {
|
||||
test_json::<CreateOrUpdateNote>("assets/mastodon/activities/create_note.json").unwrap();
|
||||
test_json::<Delete>("assets/mastodon/activities/delete.json").unwrap();
|
||||
test_json::<Follow>("assets/mastodon/activities/follow.json").unwrap();
|
||||
test_json::<UndoFollow>("assets/mastodon/activities/undo_follow.json").unwrap();
|
||||
test_json::<Vote>("assets/mastodon/activities/like_page.json").unwrap();
|
||||
test_json::<UndoVote>("assets/mastodon/activities/undo_like_page.json").unwrap();
|
||||
fn test_parse_mastodon_activities() -> LemmyResult<()> {
|
||||
test_json::<CreateOrUpdateNote>("assets/mastodon/activities/create_note.json")?;
|
||||
test_json::<Delete>("assets/mastodon/activities/delete.json")?;
|
||||
test_json::<Follow>("assets/mastodon/activities/follow.json")?;
|
||||
test_json::<UndoFollow>("assets/mastodon/activities/undo_follow.json")?;
|
||||
test_json::<Vote>("assets/mastodon/activities/like_page.json")?;
|
||||
test_json::<UndoVote>("assets/mastodon/activities/undo_like_page.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_lotide_activities() {
|
||||
test_json::<Follow>("assets/lotide/activities/follow.json").unwrap();
|
||||
test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page.json").unwrap();
|
||||
test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page_image.json").unwrap();
|
||||
test_json::<CreateOrUpdateNote>("assets/lotide/activities/create_note_reply.json").unwrap();
|
||||
fn test_parse_lotide_activities() -> LemmyResult<()> {
|
||||
test_json::<Follow>("assets/lotide/activities/follow.json")?;
|
||||
test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page.json")?;
|
||||
test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page_image.json")?;
|
||||
test_json::<CreateOrUpdateNote>("assets/lotide/activities/create_note_reply.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_friendica_activities() {
|
||||
test_json::<CreateOrUpdatePage>("assets/friendica/activities/create_page_1.json").unwrap();
|
||||
test_json::<CreateOrUpdatePage>("assets/friendica/activities/create_page_2.json").unwrap();
|
||||
test_json::<CreateOrUpdateNote>("assets/friendica/activities/create_note.json").unwrap();
|
||||
test_json::<CreateOrUpdateNote>("assets/friendica/activities/update_note.json").unwrap();
|
||||
test_json::<Delete>("assets/friendica/activities/delete.json").unwrap();
|
||||
test_json::<Vote>("assets/friendica/activities/like_page.json").unwrap();
|
||||
test_json::<Vote>("assets/friendica/activities/dislike_page.json").unwrap();
|
||||
test_json::<UndoVote>("assets/friendica/activities/undo_dislike_page.json").unwrap();
|
||||
fn test_parse_friendica_activities() -> LemmyResult<()> {
|
||||
test_json::<CreateOrUpdatePage>("assets/friendica/activities/create_page_1.json")?;
|
||||
test_json::<CreateOrUpdatePage>("assets/friendica/activities/create_page_2.json")?;
|
||||
test_json::<CreateOrUpdateNote>("assets/friendica/activities/create_note.json")?;
|
||||
test_json::<CreateOrUpdateNote>("assets/friendica/activities/update_note.json")?;
|
||||
test_json::<Delete>("assets/friendica/activities/delete.json")?;
|
||||
test_json::<Vote>("assets/friendica/activities/like_page.json")?;
|
||||
test_json::<Vote>("assets/friendica/activities/dislike_page.json")?;
|
||||
test_json::<UndoVote>("assets/friendica/activities/undo_dislike_page.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_gnusocial_activities() {
|
||||
test_json::<CreateOrUpdatePage>("assets/gnusocial/activities/create_page.json").unwrap();
|
||||
test_json::<CreateOrUpdateNote>("assets/gnusocial/activities/create_note.json").unwrap();
|
||||
test_json::<Vote>("assets/gnusocial/activities/like_note.json").unwrap();
|
||||
fn test_parse_gnusocial_activities() -> LemmyResult<()> {
|
||||
test_json::<CreateOrUpdatePage>("assets/gnusocial/activities/create_page.json")?;
|
||||
test_json::<CreateOrUpdateNote>("assets/gnusocial/activities/create_note.json")?;
|
||||
test_json::<Vote>("assets/gnusocial/activities/like_note.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_peertube_activities() {
|
||||
test_json::<AnnounceActivity>("assets/peertube/activities/announce_video.json").unwrap();
|
||||
fn test_parse_peertube_activities() -> LemmyResult<()> {
|
||||
test_json::<AnnounceActivity>("assets/peertube/activities/announce_video.json")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,22 +3,19 @@ pub mod vote;
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use crate::protocol::{
|
||||
activities::voting::{undo_vote::UndoVote, vote::Vote},
|
||||
tests::test_parse_lemmy_item,
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
||||
#[test]
|
||||
fn test_parse_lemmy_voting() {
|
||||
test_parse_lemmy_item::<Vote>("assets/lemmy/activities/voting/like_note.json").unwrap();
|
||||
test_parse_lemmy_item::<Vote>("assets/lemmy/activities/voting/dislike_page.json").unwrap();
|
||||
fn test_parse_lemmy_voting() -> LemmyResult<()> {
|
||||
test_parse_lemmy_item::<Vote>("assets/lemmy/activities/voting/like_note.json")?;
|
||||
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")
|
||||
.unwrap();
|
||||
test_parse_lemmy_item::<UndoVote>("assets/lemmy/activities/voting/undo_dislike_page.json")
|
||||
.unwrap();
|
||||
test_parse_lemmy_item::<UndoVote>("assets/lemmy/activities/voting/undo_like_note.json")?;
|
||||
test_parse_lemmy_item::<UndoVote>("assets/lemmy/activities/voting/undo_dislike_page.json")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,6 @@ pub(crate) mod group_outbox;
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use crate::protocol::{
|
||||
collections::{
|
||||
empty_outbox::EmptyOutbox,
|
||||
|
@ -19,23 +16,23 @@ mod tests {
|
|||
},
|
||||
tests::{test_json, test_parse_lemmy_item},
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
||||
#[test]
|
||||
fn test_parse_lemmy_collections() {
|
||||
test_parse_lemmy_item::<GroupFollowers>("assets/lemmy/collections/group_followers.json")
|
||||
.unwrap();
|
||||
fn test_parse_lemmy_collections() -> LemmyResult<()> {
|
||||
test_parse_lemmy_item::<GroupFollowers>("assets/lemmy/collections/group_followers.json")?;
|
||||
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);
|
||||
test_parse_lemmy_item::<GroupFeatured>("assets/lemmy/collections/group_featured_posts.json")
|
||||
.unwrap();
|
||||
test_parse_lemmy_item::<GroupModerators>("assets/lemmy/collections/group_moderators.json")
|
||||
.unwrap();
|
||||
test_parse_lemmy_item::<EmptyOutbox>("assets/lemmy/collections/person_outbox.json").unwrap();
|
||||
test_parse_lemmy_item::<GroupFeatured>("assets/lemmy/collections/group_featured_posts.json")?;
|
||||
test_parse_lemmy_item::<GroupModerators>("assets/lemmy/collections/group_moderators.json")?;
|
||||
test_parse_lemmy_item::<EmptyOutbox>("assets/lemmy/collections/person_outbox.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_mastodon_collections() {
|
||||
test_json::<GroupFeatured>("assets/mastodon/collections/featured.json").unwrap();
|
||||
fn test_parse_mastodon_collections() -> LemmyResult<()> {
|
||||
test_json::<GroupFeatured>("assets/mastodon/collections/featured.json")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,9 +89,6 @@ pub trait InCommunity {
|
|||
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use activitypub_federation::protocol::context::WithContext;
|
||||
use assert_json_diff::assert_json_include;
|
||||
use lemmy_utils::error::LemmyError;
|
||||
|
|
|
@ -95,9 +95,6 @@ impl LanguageTag {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use crate::protocol::{
|
||||
objects::{
|
||||
chat_message::ChatMessage,
|
||||
|
@ -110,77 +107,87 @@ mod tests {
|
|||
},
|
||||
tests::{test_json, test_parse_lemmy_item},
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
||||
#[test]
|
||||
fn test_parse_objects_lemmy() {
|
||||
test_parse_lemmy_item::<Instance>("assets/lemmy/objects/instance.json").unwrap();
|
||||
test_parse_lemmy_item::<Group>("assets/lemmy/objects/group.json").unwrap();
|
||||
test_parse_lemmy_item::<Person>("assets/lemmy/objects/person.json").unwrap();
|
||||
test_parse_lemmy_item::<Page>("assets/lemmy/objects/page.json").unwrap();
|
||||
test_parse_lemmy_item::<Note>("assets/lemmy/objects/note.json").unwrap();
|
||||
test_parse_lemmy_item::<ChatMessage>("assets/lemmy/objects/chat_message.json").unwrap();
|
||||
test_parse_lemmy_item::<Tombstone>("assets/lemmy/objects/tombstone.json").unwrap();
|
||||
fn test_parse_objects_lemmy() -> LemmyResult<()> {
|
||||
test_parse_lemmy_item::<Instance>("assets/lemmy/objects/instance.json")?;
|
||||
test_parse_lemmy_item::<Group>("assets/lemmy/objects/group.json")?;
|
||||
test_parse_lemmy_item::<Person>("assets/lemmy/objects/person.json")?;
|
||||
test_parse_lemmy_item::<Page>("assets/lemmy/objects/page.json")?;
|
||||
test_parse_lemmy_item::<Note>("assets/lemmy/objects/note.json")?;
|
||||
test_parse_lemmy_item::<ChatMessage>("assets/lemmy/objects/chat_message.json")?;
|
||||
test_parse_lemmy_item::<Tombstone>("assets/lemmy/objects/tombstone.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_objects_pleroma() {
|
||||
test_json::<Person>("assets/pleroma/objects/person.json").unwrap();
|
||||
test_json::<Note>("assets/pleroma/objects/note.json").unwrap();
|
||||
test_json::<ChatMessage>("assets/pleroma/objects/chat_message.json").unwrap();
|
||||
fn test_parse_objects_pleroma() -> LemmyResult<()> {
|
||||
test_json::<Person>("assets/pleroma/objects/person.json")?;
|
||||
test_json::<Note>("assets/pleroma/objects/note.json")?;
|
||||
test_json::<ChatMessage>("assets/pleroma/objects/chat_message.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_objects_smithereen() {
|
||||
test_json::<Person>("assets/smithereen/objects/person.json").unwrap();
|
||||
test_json::<Note>("assets/smithereen/objects/note.json").unwrap();
|
||||
fn test_parse_objects_smithereen() -> LemmyResult<()> {
|
||||
test_json::<Person>("assets/smithereen/objects/person.json")?;
|
||||
test_json::<Note>("assets/smithereen/objects/note.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_objects_mastodon() {
|
||||
test_json::<Person>("assets/mastodon/objects/person.json").unwrap();
|
||||
test_json::<Note>("assets/mastodon/objects/note.json").unwrap();
|
||||
test_json::<Page>("assets/mastodon/objects/page.json").unwrap();
|
||||
fn test_parse_objects_mastodon() -> LemmyResult<()> {
|
||||
test_json::<Person>("assets/mastodon/objects/person.json")?;
|
||||
test_json::<Note>("assets/mastodon/objects/note.json")?;
|
||||
test_json::<Page>("assets/mastodon/objects/page.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_objects_lotide() {
|
||||
test_json::<Group>("assets/lotide/objects/group.json").unwrap();
|
||||
test_json::<Person>("assets/lotide/objects/person.json").unwrap();
|
||||
test_json::<Note>("assets/lotide/objects/note.json").unwrap();
|
||||
test_json::<Page>("assets/lotide/objects/page.json").unwrap();
|
||||
test_json::<Tombstone>("assets/lotide/objects/tombstone.json").unwrap();
|
||||
fn test_parse_objects_lotide() -> LemmyResult<()> {
|
||||
test_json::<Group>("assets/lotide/objects/group.json")?;
|
||||
test_json::<Person>("assets/lotide/objects/person.json")?;
|
||||
test_json::<Note>("assets/lotide/objects/note.json")?;
|
||||
test_json::<Page>("assets/lotide/objects/page.json")?;
|
||||
test_json::<Tombstone>("assets/lotide/objects/tombstone.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_object_friendica() {
|
||||
test_json::<Person>("assets/friendica/objects/person_1.json").unwrap();
|
||||
test_json::<Person>("assets/friendica/objects/person_2.json").unwrap();
|
||||
test_json::<Page>("assets/friendica/objects/page_1.json").unwrap();
|
||||
test_json::<Page>("assets/friendica/objects/page_2.json").unwrap();
|
||||
test_json::<Note>("assets/friendica/objects/note_1.json").unwrap();
|
||||
test_json::<Note>("assets/friendica/objects/note_2.json").unwrap();
|
||||
fn test_parse_object_friendica() -> LemmyResult<()> {
|
||||
test_json::<Person>("assets/friendica/objects/person_1.json")?;
|
||||
test_json::<Person>("assets/friendica/objects/person_2.json")?;
|
||||
test_json::<Page>("assets/friendica/objects/page_1.json")?;
|
||||
test_json::<Page>("assets/friendica/objects/page_2.json")?;
|
||||
test_json::<Note>("assets/friendica/objects/note_1.json")?;
|
||||
test_json::<Note>("assets/friendica/objects/note_2.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_object_gnusocial() {
|
||||
test_json::<Person>("assets/gnusocial/objects/person.json").unwrap();
|
||||
test_json::<Group>("assets/gnusocial/objects/group.json").unwrap();
|
||||
test_json::<Page>("assets/gnusocial/objects/page.json").unwrap();
|
||||
test_json::<Note>("assets/gnusocial/objects/note.json").unwrap();
|
||||
fn test_parse_object_gnusocial() -> LemmyResult<()> {
|
||||
test_json::<Person>("assets/gnusocial/objects/person.json")?;
|
||||
test_json::<Group>("assets/gnusocial/objects/group.json")?;
|
||||
test_json::<Page>("assets/gnusocial/objects/page.json")?;
|
||||
test_json::<Note>("assets/gnusocial/objects/note.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_object_peertube() {
|
||||
test_json::<Person>("assets/peertube/objects/person.json").unwrap();
|
||||
test_json::<Group>("assets/peertube/objects/group.json").unwrap();
|
||||
test_json::<Page>("assets/peertube/objects/video.json").unwrap();
|
||||
test_json::<Note>("assets/peertube/objects/note.json").unwrap();
|
||||
fn test_parse_object_peertube() -> LemmyResult<()> {
|
||||
test_json::<Person>("assets/peertube/objects/person.json")?;
|
||||
test_json::<Group>("assets/peertube/objects/group.json")?;
|
||||
test_json::<Page>("assets/peertube/objects/video.json")?;
|
||||
test_json::<Note>("assets/peertube/objects/note.json")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_object_mobilizon() {
|
||||
test_json::<Group>("assets/mobilizon/objects/group.json").unwrap();
|
||||
test_json::<Page>("assets/mobilizon/objects/event.json").unwrap();
|
||||
test_json::<Person>("assets/mobilizon/objects/person.json").unwrap();
|
||||
fn test_parse_object_mobilizon() -> LemmyResult<()> {
|
||||
test_json::<Group>("assets/mobilizon/objects/group.json")?;
|
||||
test_json::<Page>("assets/mobilizon/objects/event.json")?;
|
||||
test_json::<Person>("assets/mobilizon/objects/person.json")?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,9 +242,6 @@ where
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#![allow(clippy::unwrap_used)]
|
||||
#![allow(clippy::indexing_slicing)]
|
||||
|
||||
use crate::protocol::{objects::page::Page, tests::test_parse_lemmy_item};
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue