Add more tests for activity builders

This commit is contained in:
silverpill 2022-07-14 09:00:25 +00:00
parent b89bd7e570
commit 4f2979f568

View file

@ -221,6 +221,7 @@ pub fn create_activity_undo_announce(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::activitypub::actor::Actor;
use crate::utils::id::new_uuid; use crate::utils::id::new_uuid;
use super::*; use super::*;
@ -246,4 +247,81 @@ mod tests {
assert_eq!(activity.object, json!(note_id)); assert_eq!(activity.object, json!(note_id));
assert_eq!(activity.to.unwrap(), json!([AP_PUBLIC, note_author_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]));
}
} }