From 0ed91b89ff6bfd5d2b36045f9bf7a6db1c7ef89c Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Wed, 23 Feb 2022 02:09:11 +0900 Subject: [PATCH] Add test for Blog::outbox_collection() --- plume-models/src/blogs.rs | 63 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 33c3586c..8e8776b0 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -644,8 +644,14 @@ impl NewBlog { pub(crate) mod tests { use super::*; use crate::{ - blog_authors::*, instance::tests as instance_tests, medias::NewMedia, tests::db, - users::tests as usersTests, Connection as Conn, + blog_authors::*, + instance::tests as instance_tests, + medias::NewMedia, + post_authors::{NewPostAuthor, PostAuthor}, + posts::{NewPost, Post}, + tests::db, + users::tests as usersTests, + Connection as Conn, ITEMS_PER_PAGE, }; use assert_json_diff::assert_json_eq; use diesel::Connection; @@ -727,6 +733,37 @@ pub(crate) mod tests { }, ) .unwrap(); + + for i in 1..(ITEMS_PER_PAGE * 4 + 3) { + let title = format!("Post {}", i); + let content = format!("Content for post {}.", i); + let post = Post::insert( + conn, + NewPost { + blog_id: blog1.id, + slug: title.clone(), + title: title.clone(), + content: SafeString::new(&content), + published: true, + license: "CC-0".into(), + creation_date: None, + ap_url: format!("{}/{}", blog1.ap_url, title), + subtitle: "".into(), + source: content, + cover_id: None, + }, + ) + .unwrap(); + PostAuthor::insert( + conn, + NewPostAuthor { + post_id: post.id, + author_id: users[0].id, + }, + ) + .unwrap(); + } + (users, vec![blog1, blog2, blog3]) } @@ -1090,4 +1127,26 @@ pub(crate) mod tests { Ok(()) }); } + + #[test] + fn outbox_collection() { + let conn = &db(); + conn.test_transaction::<_, Error, _>(|| { + let (_users, blogs) = fill_database(conn); + let blog = &blogs[0]; + let act = blog.outbox_collection(conn)?; + + let expected = json!({ + "items": [], + "totalItems": 0, + "first": "https://plu.me/~/BlogName/outbox?page=1", + "last": "https://plu.me/~/BlogName/outbox?page=0", + "type": "OrderedCollection" + }); + + assert_json_eq!(to_value(act)?, expected); + + Ok(()) + }); + } }