From 4f2979f56856ab0a87291715eba39d8397104f7e Mon Sep 17 00:00:00 2001 From: silverpill Date: Thu, 14 Jul 2022 09:00:25 +0000 Subject: [PATCH] Add more tests for activity builders --- src/activitypub/activity.rs | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/activitypub/activity.rs b/src/activitypub/activity.rs index 18c3a3b..f36379b 100644 --- a/src/activitypub/activity.rs +++ b/src/activitypub/activity.rs @@ -221,6 +221,7 @@ pub fn create_activity_undo_announce( #[cfg(test)] mod tests { + use crate::activitypub::actor::Actor; use crate::utils::id::new_uuid; use super::*; @@ -246,4 +247,81 @@ mod tests { assert_eq!(activity.object, json!(note_id)); assert_eq!(activity.to.unwrap(), json!([AP_PUBLIC, note_author_id])); } + + #[test] + fn test_create_activity_undo_like() { + let author = DbActorProfile::default(); + let note_author_id = "https://example.com/users/test"; + let reaction_id = new_uuid(); + let activity = create_activity_undo_like( + INSTANCE_URL, + &author, + &reaction_id, + note_author_id, + ); + assert_eq!( + activity.id, + format!("{}/objects/{}/undo", INSTANCE_URL, reaction_id), + ); + assert_eq!( + activity.object, + format!("{}/objects/{}", INSTANCE_URL, reaction_id), + ); + assert_eq!(activity.to.unwrap(), json!([AP_PUBLIC, note_author_id])); + } + + #[test] + fn test_create_activity_announce() { + let post_author_id = "https://test.net/user/test"; + let post_author = DbActorProfile { + actor_json: Some(Actor { + id: post_author_id.to_string(), + ..Default::default() + }), + actor_id: Some(post_author_id.to_string()), + ..Default::default() + }; + let post_id = "https://test.net/obj/123"; + let post = Post { + author: post_author.clone(), + object_id: Some(post_id.to_string()), + ..Default::default() + }; + let announcer = DbActorProfile::default(); + let repost_id = new_uuid(); + let activity = create_activity_announce( + INSTANCE_URL, + &announcer, + &post, + &repost_id, + ); + assert_eq!( + activity.id, + format!("{}/objects/{}", INSTANCE_URL, repost_id), + ); + assert_eq!(activity.object, post_id); + assert_eq!(activity.to.unwrap(), json!([AP_PUBLIC, post_author_id])); + } + + #[test] + fn test_create_activity_undo_announce() { + let announcer = DbActorProfile::default(); + let post_author_id = "https://example.com/users/test"; + let repost_id = new_uuid(); + let activity = create_activity_undo_announce( + INSTANCE_URL, + &announcer, + &repost_id, + post_author_id, + ); + assert_eq!( + activity.id, + format!("{}/objects/{}/undo", INSTANCE_URL, repost_id), + ); + assert_eq!( + activity.object, + format!("{}/objects/{}", INSTANCE_URL, repost_id), + ); + assert_eq!(activity.to.unwrap(), json!([AP_PUBLIC, post_author_id])); + } }