Add tests for build_undo_follow() and build_move_person()

This commit is contained in:
silverpill 2022-12-05 19:04:32 +00:00
parent 10cd778f40
commit ff745cfe64
3 changed files with 84 additions and 1 deletions

View file

@ -67,7 +67,7 @@ mod tests {
const INSTANCE_URL: &str = "https://example.com";
#[test]
fn test_create_activity_accept_follow() {
fn test_build_accept_follow() {
let target = DbActorProfile {
username: "user".to_string(),
..Default::default()
@ -82,6 +82,7 @@ mod tests {
);
assert_eq!(activity.id.starts_with(INSTANCE_URL), true);
assert_eq!(activity.activity_type, "Accept");
assert_eq!(activity.object["id"], follow_activity_id);
assert_eq!(activity.to.unwrap(), json!([follower_id]));
}

View file

@ -71,3 +71,49 @@ pub fn prepare_signed_move_person(
followers,
)
}
#[cfg(test)]
mod tests {
use crate::models::profiles::types::DbActorProfile;
use crate::utils::id::new_uuid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";
#[test]
fn test_build_move_person() {
let sender = User {
profile: DbActorProfile {
username: "testuser".to_string(),
..Default::default()
},
..Default::default()
};
let from_actor_id = "https://server0.org/users/test";
let followers = vec![
"https://server1.org/users/1".to_string(),
"https://server2.org/users/2".to_string(),
];
let internal_activity_id = new_uuid();
let activity = build_move_person(
INSTANCE_URL,
&sender,
from_actor_id,
&followers,
&internal_activity_id,
);
assert_eq!(
activity.id,
format!("{}/objects/{}", INSTANCE_URL, internal_activity_id),
);
assert_eq!(activity.activity_type, "Move");
assert_eq!(
activity.actor,
format!("{}/users/{}", INSTANCE_URL, sender.profile.username),
);
assert_eq!(activity.object, from_actor_id);
assert_eq!(activity.target, activity.actor);
assert_eq!(activity.to, followers);
}
}

View file

@ -68,3 +68,39 @@ pub fn prepare_undo_follow(
recipients,
)
}
#[cfg(test)]
mod tests {
use crate::utils::id::new_uuid;
use super::*;
const INSTANCE_URL: &str = "https://example.com";
#[test]
fn test_build_undo_follow() {
let actor_profile = DbActorProfile {
username: "user".to_string(),
..Default::default()
};
let target_actor_id = "https://test.remote/users/123";
let follow_request_id = new_uuid();
let activity = build_undo_follow(
INSTANCE_URL,
&actor_profile,
target_actor_id,
&follow_request_id,
);
assert_eq!(
activity.id,
format!("{}/objects/{}/undo", INSTANCE_URL, follow_request_id),
);
assert_eq!(activity.activity_type, "Undo");
assert_eq!(
activity.object["id"],
format!("{}/objects/{}", INSTANCE_URL, follow_request_id),
);
assert_eq!(activity.object["object"], target_actor_id);
assert_eq!(activity.to.unwrap(), json!([target_actor_id]));
}
}