Add tests for Delete(Note) activity builder

This commit is contained in:
silverpill 2022-07-29 08:19:07 +00:00
parent a70c841955
commit edc64bbbb2
2 changed files with 89 additions and 0 deletions

View file

@ -285,6 +285,53 @@ mod tests {
assert_eq!(note.cc.is_empty(), true);
}
#[test]
fn test_build_note_subscribers_only() {
let post = Post {
visibility: Visibility::Subscribers,
..Default::default()
};
let subscriber_id = "https://test.com/users/3";
let subscriber = DbActorProfile {
username: "subscriber".to_string(),
actor_json: Some(Actor {
id: subscriber_id.to_string(),
..Default::default()
}),
actor_id: Some(subscriber_id.to_string()),
..Default::default()
};
let note = build_note(INSTANCE_HOST, INSTANCE_URL, &post, vec![subscriber]);
assert_eq!(note.to, vec![
local_actor_subscribers(INSTANCE_URL, &post.author.username),
]);
assert_eq!(note.cc, vec![subscriber_id]);
}
#[test]
fn test_build_note_direct() {
let mentioned_id = "https://test.com/users/3";
let mentioned = DbActorProfile {
username: "mention".to_string(),
actor_json: Some(Actor {
id: mentioned_id.to_string(),
..Default::default()
}),
actor_id: Some(mentioned_id.to_string()),
..Default::default()
};
let post = Post {
visibility: Visibility::Direct,
mentions: vec![mentioned],
..Default::default()
};
let note = build_note(INSTANCE_HOST, INSTANCE_URL, &post, vec![]);
assert_eq!(note.to, vec![mentioned_id]);
assert_eq!(note.cc.is_empty(), true);
}
#[test]
fn test_build_note_with_local_parent() {
let parent = Post::default();

View file

@ -76,3 +76,45 @@ pub async fn prepare_delete_note(
recipients,
})
}
#[cfg(test)]
mod tests {
use serde_json::json;
use crate::activitypub::{
constants::AP_PUBLIC,
identifiers::local_actor_followers,
};
use super::*;
const INSTANCE_HOST: &str = "example.com";
const INSTANCE_URL: &str = "https://example.com";
#[test]
fn test_build_delete_note() {
let author = DbActorProfile {
username: "author".to_string(),
..Default::default()
};
let post = Post { author, ..Default::default() };
let activity = build_delete_note(
INSTANCE_HOST,
INSTANCE_URL,
&post,
vec![],
);
assert_eq!(
activity.id,
format!("{}/objects/{}/delete", INSTANCE_URL, post.id),
);
assert_eq!(
activity.object["id"],
format!("{}/objects/{}", INSTANCE_URL, post.id),
);
assert_eq!(activity.to.unwrap(), json!([AP_PUBLIC]));
assert_eq!(
activity.cc.unwrap(),
json!([local_actor_followers(INSTANCE_URL, "author")]),
);
}
}