From 489156f4a3baba9218ac061d82164a30e2647eca Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Sun, 3 Apr 2022 19:25:32 +0900 Subject: [PATCH] Add test for Post's self federation --- plume-models/src/posts.rs | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index dd08af41..2590760f 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -1476,6 +1476,56 @@ mod tests { }); } + // creates a post, get it's Create activity, delete the post, + // "send" the Create to the inbox, and check it works + #[test] + fn self_federation07() { + let conn = &db(); + conn.test_transaction::<_, (), _>(|| { + let (_, users, blogs) = fill_database(&conn); + let post = Post::insert( + &conn, + NewPost { + blog_id: blogs[0].id, + slug: "yo".into(), + title: "Yo".into(), + content: SafeString::new("Hello"), + published: true, + license: "WTFPL".to_string(), + creation_date: None, + ap_url: String::new(), // automatically updated when inserting + subtitle: "Testing".into(), + source: "Hello".into(), + cover_id: None, + }, + ) + .unwrap(); + PostAuthor::insert( + &conn, + NewPostAuthor { + post_id: post.id, + author_id: users[0].id, + }, + ) + .unwrap(); + let create = post.create_activity07(&conn).unwrap(); + post.delete(&conn).unwrap(); + + match inbox(&conn, serde_json::to_value(create).unwrap()).unwrap() { + InboxResult::Post(p) => { + assert!(p.is_author(&conn, users[0].id).unwrap()); + assert_eq!(p.source, "Hello".to_owned()); + assert_eq!(p.blog_id, blogs[0].id); + assert_eq!(p.content, SafeString::new("Hello")); + assert_eq!(p.subtitle, "Testing".to_owned()); + assert_eq!(p.title, "Yo".to_owned()); + } + _ => panic!("Unexpected result"), + }; + Ok(()) + }); + } + #[test] fn licensed_article_serde() { let mut article = Article::default();