+ // 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.inserted_local_user)),
+ ..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.inserted_local_user.id)
+ .await
+ .unwrap();
+ let finnish_comments = CommentQuery {
+ local_user: (Some(&data.inserted_local_user)),
+ ..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.inserted_local_user.id)
+ .await
+ .unwrap();
+ let undetermined_comment = CommentQuery {
+ local_user: (Some(&data.inserted_local_user)),
+ ..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.inserted_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.inserted_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 {