From 64838ad864bd23e290ca5d2ca7f54742a13168bd Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 9 Jan 2022 08:19:32 +0900 Subject: [PATCH] Add test for Follow::to_activity() --- plume-models/src/follows.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/plume-models/src/follows.rs b/plume-models/src/follows.rs index 9450b59b..27a50bbb 100644 --- a/plume-models/src/follows.rs +++ b/plume-models/src/follows.rs @@ -219,8 +219,10 @@ impl IntoId for Follow { #[cfg(test)] mod tests { use super::*; - use crate::{tests::db, users::tests as user_tests}; + use crate::{tests::db, users::tests as user_tests, users::tests::fill_database}; + use assert_json_diff::assert_json_eq; use diesel::Connection; + use serde_json::{json, to_value}; #[test] fn test_id() { @@ -255,4 +257,37 @@ mod tests { Ok(()) }) } + + #[test] + fn to_activity() { + let conn = db(); + conn.test_transaction::<_, Error, _>(|| { + let users = fill_database(&conn); + let following = &users[1]; + let follower = &users[2]; + let mut follow = Follow::insert( + &conn, + NewFollow { + follower_id: follower.id, + following_id: following.id, + ap_url: "".into(), + }, + )?; + follow.ap_url = format!("https://plu.me/follows/{}", follow.id); + let act = follow.to_activity(&conn)?; + + let expected = json!({ + "actor": "https://plu.me/@/other/", + "cc": ["https://www.w3.org/ns/activitystreams#Public"], + "id": format!("https://plu.me/follows/{}", follow.id), + "object": "https://plu.me/@/user/", + "to": ["https://plu.me/@/user/"], + "type": "Follow" + }); + + assert_json_eq!(to_value(act)?, expected); + + Ok(()) + }); + } }