+ assert_eq!(1, read_liked_comment_views.len());
+
+ let read_disliked_comment_views: Vec<CommentView> = CommentQuery {
+ local_user: (Some(&data.local_user_view)),
+ disliked_only: (Some(true)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+
+ assert!(read_disliked_comment_views.is_empty());
+
+ cleanup(data, pool).await;
+ }
+
+ #[tokio::test]
+ #[serial]
+ async fn test_comment_tree() {
+ let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
+ let data = init_data(pool).await;
+
+ let top_path = data.inserted_comment_0.path.clone();
+ let read_comment_views_top_path = CommentQuery {
+ post_id: (Some(data.inserted_post.id)),
+ parent_path: (Some(top_path)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+
+ let child_path = data.inserted_comment_1.path.clone();
+ let read_comment_views_child_path = CommentQuery {
+ post_id: (Some(data.inserted_post.id)),
+ parent_path: (Some(child_path)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+
+ // Make sure the comment parent-limited fetch is correct
+ assert_eq!(6, read_comment_views_top_path.len());
+ assert_eq!(4, read_comment_views_child_path.len());
+
+ // Make sure it contains the parent, but not the comment from the other tree
+ let child_comments = read_comment_views_child_path
+ .into_iter()
+ .map(|c| c.comment)
+ .collect::<Vec<Comment>>();
+ assert!(child_comments.contains(&data.inserted_comment_1));
+ assert!(!child_comments.contains(&data.inserted_comment_2));
+
+ let read_comment_views_top_max_depth = CommentQuery {
+ post_id: (Some(data.inserted_post.id)),
+ max_depth: (Some(1)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+
+ // Make sure a depth limited one only has the top comment
+ assert_eq!(
+ expected_comment_view(&data, pool).await,
+ read_comment_views_top_max_depth[0]
+ );
+ assert_eq!(1, read_comment_views_top_max_depth.len());
+
+ let child_path = data.inserted_comment_1.path.clone();
+ let read_comment_views_parent_max_depth = CommentQuery {
+ post_id: (Some(data.inserted_post.id)),
+ parent_path: (Some(child_path)),
+ max_depth: (Some(1)),
+ sort: (Some(CommentSortType::New)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+
+ // Make sure a depth limited one, and given child comment 1, has 3
+ assert!(read_comment_views_parent_max_depth[2]
+ .comment
+ .content
+ .eq("Comment 3"));
+ assert_eq!(3, read_comment_views_parent_max_depth.len());
+
+ cleanup(data, pool).await;
+ }
+
+ #[tokio::test]
+ #[serial]
+ async fn test_languages() {
+ let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
+ let data = init_data(pool).await;
+
+ // by default, user has all languages enabled and should see all comments
+ // (except from blocked user)
+ let all_languages = CommentQuery {
+ local_user: (Some(&data.local_user_view)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+ assert_eq!(5, all_languages.len());
+
+ // change user lang to finnish, should only show one post in finnish and one undetermined
+ let finnish_id = Language::read_id_from_code(pool, Some("fi"))
+ .await
+ .unwrap()
+ .unwrap();
+ LocalUserLanguage::update(pool, vec![finnish_id], data.local_user_view.local_user.id)
+ .await
+ .unwrap();
+ let finnish_comments = CommentQuery {
+ local_user: (Some(&data.local_user_view)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+ assert_eq!(2, finnish_comments.len());
+ let finnish_comment = finnish_comments
+ .iter()
+ .find(|c| c.comment.language_id == finnish_id);
+ assert!(finnish_comment.is_some());
+ assert_eq!(
+ data.inserted_comment_2.content,
+ finnish_comment.unwrap().comment.content
+ );
+
+ // now show all comments with undetermined language (which is the default value)
+ LocalUserLanguage::update(
+ pool,
+ vec![UNDETERMINED_ID],
+ data.local_user_view.local_user.id,
+ )
+ .await
+ .unwrap();
+ let undetermined_comment = CommentQuery {
+ local_user: (Some(&data.local_user_view)),
+ ..Default::default()
+ }
+ .list(pool)
+ .await
+ .unwrap();
+ assert_eq!(1, undetermined_comment.len());
+
+ cleanup(data, pool).await;
+ }
+
+ async fn cleanup(data: Data, pool: &mut DbPool<'_>) {
+ CommentLike::remove(
+ pool,
+ data.local_user_view.person.id,
+ data.inserted_comment_0.id,
+ )
+ .await
+ .unwrap();
+ Comment::delete(pool, data.inserted_comment_0.id)
+ .await
+ .unwrap();
+ Comment::delete(pool, data.inserted_comment_1.id)
+ .await
+ .unwrap();
+ Post::delete(pool, data.inserted_post.id).await.unwrap();
+ Community::delete(pool, data.inserted_community.id)
+ .await
+ .unwrap();
+ Person::delete(pool, data.local_user_view.person.id)
+ .await
+ .unwrap();
+ Person::delete(pool, data.inserted_person_2.id)
+ .await
+ .unwrap();
+ Instance::delete(pool, data.inserted_instance.id)
+ .await
+ .unwrap();
+ }
+
+ async fn expected_comment_view(data: &Data, pool: &mut DbPool<'_>) -> CommentView {
+ let agg = CommentAggregates::read(pool, data.inserted_comment_0.id)
+ .await
+ .unwrap();
+ CommentView {