From 6107842303408704969f95d4bf898e413cb60302 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 9 Jan 2022 21:05:47 +0900 Subject: [PATCH] Add tests for Comment::to_activity() and build_delete() --- plume-models/src/comments.rs | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/plume-models/src/comments.rs b/plume-models/src/comments.rs index 8a1e0271..1da82a36 100644 --- a/plume-models/src/comments.rs +++ b/plume-models/src/comments.rs @@ -522,4 +522,60 @@ mod tests { Ok(()) }) } + + #[test] + fn to_activity() { + let conn = db(); + conn.test_transaction::<_, Error, _>(|| { + let (comment, _posts, _users, _blogs) = prepare_activity(&conn); + let act = comment.to_activity(&conn)?; + + let expected = json!({ + "attributedTo": "https://plu.me/@/admin/", + "content": r###"

My comment, mentioning to @user

+"###, + "id": format!("https://plu.me/~/BlogName/testing/comment/{}", comment.id), + "inReplyTo": "https://plu.me/~/BlogName/testing", + "published": format_datetime(&comment.creation_date), + "summary": "My CW", + "tag": [ + { + "href": "https://plu.me/@/user/", + "name": "@user", + "type": "Mention" + } + ], + "to": ["https://www.w3.org/ns/activitystreams#Public"], + "type": "Note" + }); + + assert_json_eq!(to_value(act)?, expected); + + Ok(()) + }); + } + + #[test] + fn build_delete() { + let conn = db(); + conn.test_transaction::<_, Error, _>(|| { + let (comment, _posts, _users, _blogs) = prepare_activity(&conn); + let act = comment.build_delete(&conn)?; + + let expected = json!({ + "actor": "https://plu.me/@/admin/", + "id": format!("https://plu.me/~/BlogName/testing/comment/{}#delete", comment.id), + "object": { + "id": format!("https://plu.me/~/BlogName/testing/comment/{}", comment.id), + "type": "Tombstone" + }, + "to": ["https://www.w3.org/ns/activitystreams#Public"], + "type": "Delete" + }); + + assert_json_eq!(to_value(act)?, expected); + + Ok(()) + }); + } }