From 3e872e4749b312a9e4868e11cc0899e56647894f Mon Sep 17 00:00:00 2001 From: mydearxym Date: Tue, 15 Jun 2021 18:07:57 +0800 Subject: [PATCH 1/4] refactor(cite-workflow): wip --- lib/groupher_server/cms/cms.ex | 3 + .../cms/delegates/cited_content.ex | 68 +++++++++++++++++++ .../cms/cite_contents/cite_blog_test.exs | 3 - .../cms/cite_contents/cite_job_test.exs | 3 - .../cms/cite_contents/cite_post_test.exs | 27 ++++++-- 5 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 lib/groupher_server/cms/delegates/cited_content.ex diff --git a/lib/groupher_server/cms/cms.ex b/lib/groupher_server/cms/cms.ex index 4ae88df50..95685e128 100644 --- a/lib/groupher_server/cms/cms.ex +++ b/lib/groupher_server/cms/cms.ex @@ -12,6 +12,7 @@ defmodule GroupherServer.CMS do ArticleCURD, ArticleCommunity, ArticleEmotion, + CitedContent, CommentCurd, ArticleCollect, ArticleUpvote, @@ -96,6 +97,8 @@ defmodule GroupherServer.CMS do defdelegate sink_article(thread, id), to: ArticleCURD defdelegate undo_sink_article(thread, id), to: ArticleCURD + defdelegate paged_citing_contents(id, filter), to: CitedContent + defdelegate upvote_article(thread, article_id, user), to: ArticleUpvote defdelegate undo_upvote_article(thread, article_id, user), to: ArticleUpvote diff --git a/lib/groupher_server/cms/delegates/cited_content.ex b/lib/groupher_server/cms/delegates/cited_content.ex new file mode 100644 index 000000000..2ad86d1b2 --- /dev/null +++ b/lib/groupher_server/cms/delegates/cited_content.ex @@ -0,0 +1,68 @@ +defmodule GroupherServer.CMS.Delegate.CitedContent do + @moduledoc """ + CURD operation on post/job ... + """ + import Ecto.Query, warn: false + + import GroupherServer.CMS.Helper.Matcher + import Helper.Utils, only: [done: 1, get_config: 2] + import ShortMaps + + alias GroupherServer.{CMS, Repo} + alias Helper.ORM + + alias CMS.Model.CitedContent + + @article_threads get_config(:article, :threads) + @cited_preloads @article_threads |> Enum.map(&Keyword.new([{&1, [author: :user]}])) + + """ + article: + thread title timestamp who + + comment: + thread title/的评论(digest)中 timestamp who + + %Article { + thread: "", + id: "", + title: "", + updatedAt: "", + user: %User{}, + block_linker: [], + + in_comment: boolean + + user: %User{}, + } + """ + + @doc "get paged citing contents" + def paged_citing_contents(cited_by_id, %{page: page, size: size} = filter) do + CitedContent + |> where([c], c.cited_by_id == ^cited_by_id) + |> ORM.paginater(~m(page size)a) + |> extract_contents + |> IO.inspect(label: "bb") + end + + def extract_contents(%{entries: entries} = paged_contents) do + entries = entries |> Repo.preload(@cited_preloads) |> Enum.map(&shape_article(&1)) + + Map.put(paged_contents, :entries, entries) + end + + def shape_article(%CitedContent{} = cited) do + thread = cited.cited_by_type |> String.downcase() |> String.to_atom() + # original_community + block_linker = cited.block_linker + article = Map.get(cited, thread) + + thread = get_in(article, [:meta]) |> Map.get(:thread) + user = get_in(article, [:author, :user]) |> Map.take([:login, :nickname, :avatar]) + + article + |> Map.take([:title, :updated_at]) + |> Map.merge(%{user: user, thread: thread, block_linker: block_linker}) + end +end diff --git a/test/groupher_server/cms/cite_contents/cite_blog_test.exs b/test/groupher_server/cms/cite_contents/cite_blog_test.exs index 31868364b..806c04390 100644 --- a/test/groupher_server/cms/cite_contents/cite_blog_test.exs +++ b/test/groupher_server/cms/cite_contents/cite_blog_test.exs @@ -73,7 +73,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Blog do assert blog.meta.citing_count == 0 end - @tag :wip test "cited comment itself should not work", ~m(user blog)a do {:ok, cited_comment} = CMS.create_comment(:blog, blog.id, mock_rich_text("hello"), user) @@ -91,7 +90,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Blog do assert cited_comment.meta.citing_count == 0 end - @tag :wip test "can cite blog's comment in blog", ~m(community user blog blog2 blog_attrs)a do {:ok, comment} = CMS.create_comment(:blog, blog.id, mock_rich_text("hello"), user) @@ -111,7 +109,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Blog do assert cite_content.cited_by_type == "COMMENT" end - @tag :wip test "can cite a comment in a comment", ~m(user blog)a do {:ok, cited_comment} = CMS.create_comment(:blog, blog.id, mock_rich_text("hello"), user) diff --git a/test/groupher_server/cms/cite_contents/cite_job_test.exs b/test/groupher_server/cms/cite_contents/cite_job_test.exs index 9e40ed24e..7af500046 100644 --- a/test/groupher_server/cms/cite_contents/cite_job_test.exs +++ b/test/groupher_server/cms/cite_contents/cite_job_test.exs @@ -73,7 +73,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Job do assert job.meta.citing_count == 0 end - @tag :wip test "cited comment itself should not work", ~m(user job)a do {:ok, cited_comment} = CMS.create_comment(:job, job.id, mock_rich_text("hello"), user) @@ -91,7 +90,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Job do assert cited_comment.meta.citing_count == 0 end - @tag :wip test "can cite job's comment in job", ~m(community user job job2 job_attrs)a do {:ok, comment} = CMS.create_comment(:job, job.id, mock_rich_text("hello"), user) @@ -111,7 +109,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Job do assert cite_content.cited_by_type == "COMMENT" end - @tag :wip test "can cite a comment in a comment", ~m(user job)a do {:ok, cited_comment} = CMS.create_comment(:job, job.id, mock_rich_text("hello"), user) diff --git a/test/groupher_server/cms/cite_contents/cite_post_test.exs b/test/groupher_server/cms/cite_contents/cite_post_test.exs index f5f71fcfb..616349e30 100644 --- a/test/groupher_server/cms/cite_contents/cite_post_test.exs +++ b/test/groupher_server/cms/cite_contents/cite_post_test.exs @@ -27,6 +27,29 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do {:ok, ~m(user user2 community post post2 post3 post4 post5 post_attrs)a} end + describe "[cite pagi]" do + @tag :wip + test "--can get paged cited articles.", ~m(user community post2 post_attrs)a do + body = + mock_rich_text( + ~s(the ), + ~s(the ) + ) + + post_attrs = post_attrs |> Map.merge(%{body: body}) + {:ok, post_x} = CMS.create_article(community, :post, post_attrs, user) + + body = mock_rich_text(~s(the )) + post_attrs = post_attrs |> Map.merge(%{body: body}) + {:ok, post_y} = CMS.create_article(community, :post, post_attrs, user) + + CiteTasks.handle(post_x) + CiteTasks.handle(post_y) + + CMS.paged_citing_contents(post2.id, %{page: 1, size: 10}) + end + end + describe "[cite basic]" do # test "cited multi post should work", ~m(user community post2 post3 post4 post5 post_attrs)a do @@ -62,7 +85,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do assert post5.meta.citing_count == 1 end - @tag :wip test "cited post itself should not work", ~m(user community post_attrs)a do {:ok, post} = CMS.create_article(community, :post, post_attrs, user) @@ -75,7 +97,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do assert post.meta.citing_count == 0 end - @tag :wip test "cited comment itself should not work", ~m(user post)a do {:ok, cited_comment} = CMS.create_comment(:post, post.id, mock_rich_text("hello"), user) @@ -93,7 +114,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do assert cited_comment.meta.citing_count == 0 end - @tag :wip test "can cite post's comment in post", ~m(community user post post2 post_attrs)a do {:ok, comment} = CMS.create_comment(:post, post.id, mock_rich_text("hello"), user) @@ -113,7 +133,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do assert cite_content.cited_by_type == "COMMENT" end - @tag :wip test "can cite a comment in a comment", ~m(user post)a do {:ok, cited_comment} = CMS.create_comment(:post, post.id, mock_rich_text("hello"), user) From 8e19455d9c21e974d70ad357c13378d0b80ab126 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Tue, 15 Jun 2021 20:55:01 +0800 Subject: [PATCH 2/4] refactor(cite-workflow): wip --- .../cms/delegates/cited_content.ex | 63 ++++++++------- lib/helper/types.ex | 16 +++- .../cms/cite_contents/cite_blog_test.exs | 53 +++++++++++++ .../cms/cite_contents/cite_post_test.exs | 76 +++++++++++++------ 4 files changed, 155 insertions(+), 53 deletions(-) diff --git a/lib/groupher_server/cms/delegates/cited_content.ex b/lib/groupher_server/cms/delegates/cited_content.ex index 2ad86d1b2..11265cf3e 100644 --- a/lib/groupher_server/cms/delegates/cited_content.ex +++ b/lib/groupher_server/cms/delegates/cited_content.ex @@ -4,46 +4,29 @@ defmodule GroupherServer.CMS.Delegate.CitedContent do """ import Ecto.Query, warn: false - import GroupherServer.CMS.Helper.Matcher import Helper.Utils, only: [done: 1, get_config: 2] import ShortMaps + alias Helper.Types, as: T alias GroupherServer.{CMS, Repo} alias Helper.ORM alias CMS.Model.CitedContent @article_threads get_config(:article, :threads) - @cited_preloads @article_threads |> Enum.map(&Keyword.new([{&1, [author: :user]}])) - """ - article: - thread title timestamp who - - comment: - thread title/的评论(digest)中 timestamp who - - %Article { - thread: "", - id: "", - title: "", - updatedAt: "", - user: %User{}, - block_linker: [], + @article_preloads @article_threads |> Enum.map(&Keyword.new([{&1, [author: :user]}])) - in_comment: boolean - - user: %User{}, - } - """ + @comment_article_preloads @article_threads |> Enum.map(&Keyword.new([{:comment, &1}])) + @cited_preloads @article_preloads ++ [[comment: :author] ++ @comment_article_preloads] @doc "get paged citing contents" - def paged_citing_contents(cited_by_id, %{page: page, size: size} = filter) do + def paged_citing_contents(cited_by_id, %{page: page, size: size}) do CitedContent |> where([c], c.cited_by_id == ^cited_by_id) |> ORM.paginater(~m(page size)a) |> extract_contents - |> IO.inspect(label: "bb") + |> done end def extract_contents(%{entries: entries} = paged_contents) do @@ -52,17 +35,39 @@ defmodule GroupherServer.CMS.Delegate.CitedContent do Map.put(paged_contents, :entries, entries) end - def shape_article(%CitedContent{} = cited) do - thread = cited.cited_by_type |> String.downcase() |> String.to_atom() - # original_community - block_linker = cited.block_linker + defp thread_to_atom(thread), do: thread |> String.downcase() |> String.to_atom() + + # shape comment cite + @spec shape_article(CitedContent.t()) :: T.cite_info() + defp shape_article(%CitedContent{comment_id: comment_id} = cited) when not is_nil(comment_id) do + %{block_linker: block_linker, cited_by_type: cited_by_type, comment: comment} = cited + + comment_thread = comment.thread |> String.downcase() |> String.to_atom() + article = comment |> Map.get(comment_thread) + user = comment.author |> Map.take([:login, :nickname, :avatar]) + + article + |> Map.take([:id, :title]) + |> Map.merge(%{ + updated_at: comment.updated_at, + user: user, + thread: thread_to_atom(cited_by_type), + comment_id: comment.id, + block_linker: block_linker + }) + end + + # shape general article cite + defp shape_article(%CitedContent{} = cited) do + %{block_linker: block_linker, cited_by_type: cited_by_type} = cited + + thread = thread_to_atom(cited_by_type) article = Map.get(cited, thread) - thread = get_in(article, [:meta]) |> Map.get(:thread) user = get_in(article, [:author, :user]) |> Map.take([:login, :nickname, :avatar]) article - |> Map.take([:title, :updated_at]) + |> Map.take([:id, :title, :updated_at]) |> Map.merge(%{user: user, thread: thread, block_linker: block_linker}) end end diff --git a/lib/helper/types.ex b/lib/helper/types.ex index 6d251d40b..825afc354 100644 --- a/lib/helper/types.ex +++ b/lib/helper/types.ex @@ -33,7 +33,7 @@ defmodule Helper.Types do company: nil | String.t() } - @type article_thread :: :post | :job | :repo + @type article_thread :: :post | :job | :repo | :blog @type paged_filter :: %{ page: Integer.t(), @@ -182,4 +182,18 @@ defmodule Helper.Types do html fragment """ @type html :: String.t() + + @type cite_info :: %{ + id: Integer.t(), + thread: article_thread, + title: String.t(), + updated_at: String.t(), + block_linker: [String.t()], + comment_id: Integer.t() | nil, + user: %{ + login: String.t(), + avatar: String.t(), + nickname: String.t() + } + } end diff --git a/test/groupher_server/cms/cite_contents/cite_blog_test.exs b/test/groupher_server/cms/cite_contents/cite_blog_test.exs index 806c04390..cfdfbf78b 100644 --- a/test/groupher_server/cms/cite_contents/cite_blog_test.exs +++ b/test/groupher_server/cms/cite_contents/cite_blog_test.exs @@ -161,4 +161,57 @@ defmodule GroupherServer.Test.CMS.CiteContent.Blog do assert blog5.meta.citing_count == 1 end end + + describe "[cite pagi]" do + @tag :wip + test "can get paged cited articles.", ~m(user community blog2 blog_attrs)a do + {:ok, comment} = + CMS.create_comment( + :blog, + blog2.id, + mock_comment(~s(the )), + user + ) + + body = + mock_rich_text( + ~s(the ), + ~s(the ) + ) + + blog_attrs = blog_attrs |> Map.merge(%{body: body}) + {:ok, blog_x} = CMS.create_article(community, :blog, blog_attrs, user) + + body = mock_rich_text(~s(the )) + blog_attrs = blog_attrs |> Map.merge(%{body: body}) + {:ok, blog_y} = CMS.create_article(community, :blog, blog_attrs, user) + + CiteTasks.handle(blog_x) + CiteTasks.handle(comment) + CiteTasks.handle(blog_y) + + {:ok, result} = CMS.paged_citing_contents(blog2.id, %{page: 1, size: 10}) + + entries = result.entries + first = entries |> List.first() + middle = entries |> Enum.at(1) + last = entries |> List.last() + article_map_keys = [:block_linker, :id, :thread, :title, :updated_at, :user] + + assert first.id == blog_x.id + assert first.block_linker |> length == 2 + assert first |> Map.keys() == article_map_keys + + assert middle.comment_id == comment.id + assert middle.id == blog2.id + assert middle.title == blog2.title + + assert last.id == blog_y.id + assert last.block_linker |> length == 1 + assert last |> Map.keys() == article_map_keys + + assert result |> is_valid_pagination?(:raw) + assert result.total_count == 3 + end + end end diff --git a/test/groupher_server/cms/cite_contents/cite_post_test.exs b/test/groupher_server/cms/cite_contents/cite_post_test.exs index 616349e30..09bd62ec5 100644 --- a/test/groupher_server/cms/cite_contents/cite_post_test.exs +++ b/test/groupher_server/cms/cite_contents/cite_post_test.exs @@ -27,29 +27,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do {:ok, ~m(user user2 community post post2 post3 post4 post5 post_attrs)a} end - describe "[cite pagi]" do - @tag :wip - test "--can get paged cited articles.", ~m(user community post2 post_attrs)a do - body = - mock_rich_text( - ~s(the ), - ~s(the ) - ) - - post_attrs = post_attrs |> Map.merge(%{body: body}) - {:ok, post_x} = CMS.create_article(community, :post, post_attrs, user) - - body = mock_rich_text(~s(the )) - post_attrs = post_attrs |> Map.merge(%{body: body}) - {:ok, post_y} = CMS.create_article(community, :post, post_attrs, user) - - CiteTasks.handle(post_x) - CiteTasks.handle(post_y) - - CMS.paged_citing_contents(post2.id, %{page: 1, size: 10}) - end - end - describe "[cite basic]" do # test "cited multi post should work", ~m(user community post2 post3 post4 post5 post_attrs)a do @@ -185,4 +162,57 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do assert post5.meta.citing_count == 1 end end + + describe "[cite pagi]" do + @tag :wip + test "can get paged cited articles.", ~m(user community post2 post_attrs)a do + {:ok, comment} = + CMS.create_comment( + :post, + post2.id, + mock_comment(~s(the )), + user + ) + + body = + mock_rich_text( + ~s(the ), + ~s(the ) + ) + + post_attrs = post_attrs |> Map.merge(%{body: body}) + {:ok, post_x} = CMS.create_article(community, :post, post_attrs, user) + + body = mock_rich_text(~s(the )) + post_attrs = post_attrs |> Map.merge(%{body: body}) + {:ok, post_y} = CMS.create_article(community, :post, post_attrs, user) + + CiteTasks.handle(post_x) + CiteTasks.handle(comment) + CiteTasks.handle(post_y) + + {:ok, result} = CMS.paged_citing_contents(post2.id, %{page: 1, size: 10}) + + entries = result.entries + first = entries |> List.first() + middle = entries |> Enum.at(1) + last = entries |> List.last() + article_map_keys = [:block_linker, :id, :thread, :title, :updated_at, :user] + + assert first.id == post_x.id + assert first.block_linker |> length == 2 + assert first |> Map.keys() == article_map_keys + + assert middle.comment_id == comment.id + assert middle.id == post2.id + assert middle.title == post2.title + + assert last.id == post_y.id + assert last.block_linker |> length == 1 + assert last |> Map.keys() == article_map_keys + + assert result |> is_valid_pagination?(:raw) + assert result.total_count == 3 + end + end end From f6d4db1c4b250937fc46553a792c4ebcb10a1507 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Tue, 15 Jun 2021 21:55:25 +0800 Subject: [PATCH 3/4] refactor(cite-workflow): wip --- lib/groupher_server/cms/cms.ex | 2 +- .../cms/delegates/cited_content.ex | 27 ++++++--- lib/helper/types.ex | 2 +- .../cms/cite_contents/cite_blog_test.exs | 39 +++++++------ .../cms/cite_contents/cite_job_test.exs | 57 +++++++++++++++++++ .../cms/cite_contents/cite_post_test.exs | 39 +++++++------ 6 files changed, 122 insertions(+), 44 deletions(-) diff --git a/lib/groupher_server/cms/cms.ex b/lib/groupher_server/cms/cms.ex index 95685e128..d883a9935 100644 --- a/lib/groupher_server/cms/cms.ex +++ b/lib/groupher_server/cms/cms.ex @@ -97,7 +97,7 @@ defmodule GroupherServer.CMS do defdelegate sink_article(thread, id), to: ArticleCURD defdelegate undo_sink_article(thread, id), to: ArticleCURD - defdelegate paged_citing_contents(id, filter), to: CitedContent + defdelegate paged_citing_contents(type, id, filter), to: CitedContent defdelegate upvote_article(thread, article_id, user), to: ArticleUpvote defdelegate undo_upvote_article(thread, article_id, user), to: ArticleUpvote diff --git a/lib/groupher_server/cms/delegates/cited_content.ex b/lib/groupher_server/cms/delegates/cited_content.ex index 11265cf3e..32cf1dfe9 100644 --- a/lib/groupher_server/cms/delegates/cited_content.ex +++ b/lib/groupher_server/cms/delegates/cited_content.ex @@ -9,7 +9,7 @@ defmodule GroupherServer.CMS.Delegate.CitedContent do alias Helper.Types, as: T alias GroupherServer.{CMS, Repo} - alias Helper.ORM + alias Helper.{ORM, QueryBuilder} alias CMS.Model.CitedContent @@ -21,9 +21,10 @@ defmodule GroupherServer.CMS.Delegate.CitedContent do @cited_preloads @article_preloads ++ [[comment: :author] ++ @comment_article_preloads] @doc "get paged citing contents" - def paged_citing_contents(cited_by_id, %{page: page, size: size}) do + def paged_citing_contents(cited_by_type, cited_by_id, %{page: page, size: size} = filter) do CitedContent - |> where([c], c.cited_by_id == ^cited_by_id) + |> where([c], c.cited_by_id == ^cited_by_id and c.cited_by_type == ^cited_by_type) + |> QueryBuilder.filter_pack(Map.merge(filter, %{sort: :asc_inserted})) |> ORM.paginater(~m(page size)a) |> extract_contents |> done @@ -40,7 +41,12 @@ defmodule GroupherServer.CMS.Delegate.CitedContent do # shape comment cite @spec shape_article(CitedContent.t()) :: T.cite_info() defp shape_article(%CitedContent{comment_id: comment_id} = cited) when not is_nil(comment_id) do - %{block_linker: block_linker, cited_by_type: cited_by_type, comment: comment} = cited + %{ + block_linker: block_linker, + cited_by_type: cited_by_type, + comment: comment, + inserted_at: inserted_at + } = cited comment_thread = comment.thread |> String.downcase() |> String.to_atom() article = comment |> Map.get(comment_thread) @@ -49,7 +55,7 @@ defmodule GroupherServer.CMS.Delegate.CitedContent do article |> Map.take([:id, :title]) |> Map.merge(%{ - updated_at: comment.updated_at, + inserted_at: inserted_at, user: user, thread: thread_to_atom(cited_by_type), comment_id: comment.id, @@ -59,7 +65,7 @@ defmodule GroupherServer.CMS.Delegate.CitedContent do # shape general article cite defp shape_article(%CitedContent{} = cited) do - %{block_linker: block_linker, cited_by_type: cited_by_type} = cited + %{block_linker: block_linker, cited_by_type: cited_by_type, inserted_at: inserted_at} = cited thread = thread_to_atom(cited_by_type) article = Map.get(cited, thread) @@ -67,7 +73,12 @@ defmodule GroupherServer.CMS.Delegate.CitedContent do user = get_in(article, [:author, :user]) |> Map.take([:login, :nickname, :avatar]) article - |> Map.take([:id, :title, :updated_at]) - |> Map.merge(%{user: user, thread: thread, block_linker: block_linker}) + |> Map.take([:id, :title]) + |> Map.merge(%{ + user: user, + thread: thread, + block_linker: block_linker, + inserted_at: inserted_at + }) end end diff --git a/lib/helper/types.ex b/lib/helper/types.ex index 825afc354..f55404bd9 100644 --- a/lib/helper/types.ex +++ b/lib/helper/types.ex @@ -187,7 +187,7 @@ defmodule Helper.Types do id: Integer.t(), thread: article_thread, title: String.t(), - updated_at: String.t(), + inserted_at: String.t(), block_linker: [String.t()], comment_id: Integer.t() | nil, user: %{ diff --git a/test/groupher_server/cms/cite_contents/cite_blog_test.exs b/test/groupher_server/cms/cite_contents/cite_blog_test.exs index cfdfbf78b..360085bab 100644 --- a/test/groupher_server/cms/cite_contents/cite_blog_test.exs +++ b/test/groupher_server/cms/cite_contents/cite_blog_test.exs @@ -173,6 +173,8 @@ defmodule GroupherServer.Test.CMS.CiteContent.Blog do user ) + Process.sleep(1000) + body = mock_rich_text( ~s(the ), @@ -182,6 +184,7 @@ defmodule GroupherServer.Test.CMS.CiteContent.Blog do blog_attrs = blog_attrs |> Map.merge(%{body: body}) {:ok, blog_x} = CMS.create_article(community, :blog, blog_attrs, user) + Process.sleep(1000) body = mock_rich_text(~s(the )) blog_attrs = blog_attrs |> Map.merge(%{body: body}) {:ok, blog_y} = CMS.create_article(community, :blog, blog_attrs, user) @@ -190,25 +193,27 @@ defmodule GroupherServer.Test.CMS.CiteContent.Blog do CiteTasks.handle(comment) CiteTasks.handle(blog_y) - {:ok, result} = CMS.paged_citing_contents(blog2.id, %{page: 1, size: 10}) + {:ok, result} = CMS.paged_citing_contents("BLOG", blog2.id, %{page: 1, size: 10}) entries = result.entries - first = entries |> List.first() - middle = entries |> Enum.at(1) - last = entries |> List.last() - article_map_keys = [:block_linker, :id, :thread, :title, :updated_at, :user] - - assert first.id == blog_x.id - assert first.block_linker |> length == 2 - assert first |> Map.keys() == article_map_keys - - assert middle.comment_id == comment.id - assert middle.id == blog2.id - assert middle.title == blog2.title - - assert last.id == blog_y.id - assert last.block_linker |> length == 1 - assert last |> Map.keys() == article_map_keys + + result_comment = entries |> List.first() + result_blog_x = entries |> Enum.at(1) + result_blog_y = entries |> List.last() + + article_map_keys = [:block_linker, :id, :inserted_at, :thread, :title, :user] + + assert result_comment.comment_id == comment.id + assert result_comment.id == blog2.id + assert result_comment.title == blog2.title + + assert result_blog_x.id == blog_x.id + assert result_blog_x.block_linker |> length == 2 + assert result_blog_x |> Map.keys() == article_map_keys + + assert result_blog_y.id == blog_y.id + assert result_blog_y.block_linker |> length == 1 + assert result_blog_y |> Map.keys() == article_map_keys assert result |> is_valid_pagination?(:raw) assert result.total_count == 3 diff --git a/test/groupher_server/cms/cite_contents/cite_job_test.exs b/test/groupher_server/cms/cite_contents/cite_job_test.exs index 7af500046..b4b1c9280 100644 --- a/test/groupher_server/cms/cite_contents/cite_job_test.exs +++ b/test/groupher_server/cms/cite_contents/cite_job_test.exs @@ -161,4 +161,61 @@ defmodule GroupherServer.Test.CMS.CiteContent.Job do assert job5.meta.citing_count == 1 end end + + describe "[cite pagi]" do + @tag :wip + test "can get paged cited articles.", ~m(user community job2 job_attrs)a do + {:ok, comment} = + CMS.create_comment( + :job, + job2.id, + mock_comment(~s(the )), + user + ) + + Process.sleep(1000) + + body = + mock_rich_text( + ~s(the ), + ~s(the ) + ) + + job_attrs = job_attrs |> Map.merge(%{body: body}) + {:ok, job_x} = CMS.create_article(community, :job, job_attrs, user) + Process.sleep(1000) + body = mock_rich_text(~s(the )) + job_attrs = job_attrs |> Map.merge(%{body: body}) + {:ok, job_y} = CMS.create_article(community, :job, job_attrs, user) + + CiteTasks.handle(job_x) + CiteTasks.handle(comment) + CiteTasks.handle(job_y) + + {:ok, result} = CMS.paged_citing_contents("JOB", job2.id, %{page: 1, size: 10}) + + entries = result.entries + + result_comment = entries |> List.first() + result_job_x = entries |> Enum.at(1) + result_job_y = entries |> List.last() + + article_map_keys = [:block_linker, :id, :inserted_at, :thread, :title, :user] + + assert result_comment.comment_id == comment.id + assert result_comment.id == job2.id + assert result_comment.title == job2.title + + assert result_job_x.id == job_x.id + assert result_job_x.block_linker |> length == 2 + assert result_job_x |> Map.keys() == article_map_keys + + assert result_job_y.id == job_y.id + assert result_job_y.block_linker |> length == 1 + assert result_job_y |> Map.keys() == article_map_keys + + assert result |> is_valid_pagination?(:raw) + assert result.total_count == 3 + end + end end diff --git a/test/groupher_server/cms/cite_contents/cite_post_test.exs b/test/groupher_server/cms/cite_contents/cite_post_test.exs index 09bd62ec5..25fb5c140 100644 --- a/test/groupher_server/cms/cite_contents/cite_post_test.exs +++ b/test/groupher_server/cms/cite_contents/cite_post_test.exs @@ -174,6 +174,8 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do user ) + Process.sleep(1000) + body = mock_rich_text( ~s(the ), @@ -183,6 +185,7 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do post_attrs = post_attrs |> Map.merge(%{body: body}) {:ok, post_x} = CMS.create_article(community, :post, post_attrs, user) + Process.sleep(1000) body = mock_rich_text(~s(the )) post_attrs = post_attrs |> Map.merge(%{body: body}) {:ok, post_y} = CMS.create_article(community, :post, post_attrs, user) @@ -191,25 +194,27 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do CiteTasks.handle(comment) CiteTasks.handle(post_y) - {:ok, result} = CMS.paged_citing_contents(post2.id, %{page: 1, size: 10}) + {:ok, result} = CMS.paged_citing_contents("POST", post2.id, %{page: 1, size: 10}) entries = result.entries - first = entries |> List.first() - middle = entries |> Enum.at(1) - last = entries |> List.last() - article_map_keys = [:block_linker, :id, :thread, :title, :updated_at, :user] - - assert first.id == post_x.id - assert first.block_linker |> length == 2 - assert first |> Map.keys() == article_map_keys - - assert middle.comment_id == comment.id - assert middle.id == post2.id - assert middle.title == post2.title - - assert last.id == post_y.id - assert last.block_linker |> length == 1 - assert last |> Map.keys() == article_map_keys + + result_comment = entries |> List.first() + result_post_x = entries |> Enum.at(1) + result_post_y = entries |> List.last() + + article_map_keys = [:block_linker, :id, :inserted_at, :thread, :title, :user] + + assert result_comment.comment_id == comment.id + assert result_comment.id == post2.id + assert result_comment.title == post2.title + + assert result_post_x.id == post_x.id + assert result_post_x.block_linker |> length == 2 + assert result_post_x |> Map.keys() == article_map_keys + + assert result_post_y.id == post_y.id + assert result_post_y.block_linker |> length == 1 + assert result_post_y |> Map.keys() == article_map_keys assert result |> is_valid_pagination?(:raw) assert result.total_count == 3 From bd66c25b8871662ef28cbb411657d328fffc6765 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Tue, 15 Jun 2021 23:41:40 +0800 Subject: [PATCH 4/4] refactor(cite-workflow): gq endpoint --- .../accounts/delegates/upvoted_articles.ex | 4 +- .../cms/delegates/article_collect.ex | 8 +- .../cms/delegates/article_community.ex | 10 +-- .../cms/delegates/article_upvote.ex | 4 +- .../cms/delegates/cited_content.ex | 2 + .../resolvers/cms_resolver.ex | 4 + .../schema/cms/cms_metrics.ex | 5 ++ .../schema/cms/cms_queries.ex | 9 ++ .../schema/cms/cms_types.ex | 16 ++++ .../cms/cite_contents/cite_blog_test.exs | 1 - .../cms/cite_contents/cite_job_test.exs | 1 - .../cms/cite_contents/cite_post_test.exs | 2 - .../query/cms/citings/blog_citing_test.exs | 83 +++++++++++++++++++ .../query/cms/citings/job_citing_test.exs | 83 +++++++++++++++++++ .../query/cms/citings/post_citing_test.exs | 83 +++++++++++++++++++ 15 files changed, 297 insertions(+), 18 deletions(-) create mode 100644 test/groupher_server_web/query/cms/citings/blog_citing_test.exs create mode 100644 test/groupher_server_web/query/cms/citings/job_citing_test.exs create mode 100644 test/groupher_server_web/query/cms/citings/post_citing_test.exs diff --git a/lib/groupher_server/accounts/delegates/upvoted_articles.ex b/lib/groupher_server/accounts/delegates/upvoted_articles.ex index 04f4cda40..a015fc093 100644 --- a/lib/groupher_server/accounts/delegates/upvoted_articles.ex +++ b/lib/groupher_server/accounts/delegates/upvoted_articles.ex @@ -17,8 +17,8 @@ defmodule GroupherServer.Accounts.Delegate.UpvotedArticles do get paged upvoted articles """ def paged_upvoted_articles(user_id, %{thread: thread} = filter) do - thread_upcase = thread |> to_string |> String.upcase() - where_query = dynamic([a], a.user_id == ^user_id and a.thread == ^thread_upcase) + thread = thread |> to_string |> String.upcase() + where_query = dynamic([a], a.user_id == ^user_id and a.thread == ^thread) load_upvoted_articles(where_query, filter) end diff --git a/lib/groupher_server/cms/delegates/article_collect.ex b/lib/groupher_server/cms/delegates/article_collect.ex index 5da7f898f..19126bb99 100644 --- a/lib/groupher_server/cms/delegates/article_collect.ex +++ b/lib/groupher_server/cms/delegates/article_collect.ex @@ -46,8 +46,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleCollect do update_article_reaction_user_list(:collect, article, user_id, :add) end) |> Multi.run(:create_collect, fn _, _ -> - thread_upcase = thread |> to_string |> String.upcase() - args = Map.put(%{user_id: user_id, thread: thread_upcase}, info.foreign_key, article.id) + thread = thread |> to_string |> String.upcase() + args = Map.put(%{user_id: user_id, thread: thread}, info.foreign_key, article.id) ORM.create(ArticleCollect, args) end) @@ -131,8 +131,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleCollect do defp collection_findby_args(thread, article_id, user_id) do with {:ok, info} <- match(thread) do - thread_upcase = thread |> to_string |> String.upcase() - %{thread: thread_upcase, user_id: user_id} |> Map.put(info.foreign_key, article_id) + thread = thread |> to_string |> String.upcase() + %{thread: thread, user_id: user_id} |> Map.put(info.foreign_key, article_id) end end diff --git a/lib/groupher_server/cms/delegates/article_community.ex b/lib/groupher_server/cms/delegates/article_community.ex index f11d2d352..f6b2d6c7b 100644 --- a/lib/groupher_server/cms/delegates/article_community.ex +++ b/lib/groupher_server/cms/delegates/article_community.ex @@ -41,10 +41,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do defp pack_pin_args(thread, article_id, community_id) do with {:ok, info} <- match(thread), {:ok, community} <- ORM.find(Community, community_id) do - thread_upcase = thread |> to_string |> String.upcase() + thread = thread |> to_string |> String.upcase() Map.put( - %{community_id: community.id, thread: thread_upcase}, + %{community_id: community.id, thread: thread}, info.foreign_key, article_id ) @@ -145,12 +145,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do # check if the thread has aready enough pinned articles defp check_pinned_article_count(community_id, thread) do - thread_upcase = thread |> to_string |> String.upcase() + thread = thread |> to_string |> String.upcase() query = - from(p in PinnedArticle, - where: p.community_id == ^community_id and p.thread == ^thread_upcase - ) + from(p in PinnedArticle, where: p.community_id == ^community_id and p.thread == ^thread) pinned_articles = query |> Repo.all() diff --git a/lib/groupher_server/cms/delegates/article_upvote.ex b/lib/groupher_server/cms/delegates/article_upvote.ex index 6b5478987..9f0cec4c7 100644 --- a/lib/groupher_server/cms/delegates/article_upvote.ex +++ b/lib/groupher_server/cms/delegates/article_upvote.ex @@ -43,8 +43,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleUpvote do Accounts.achieve(%User{id: achiever_id}, :inc, :upvote) end) |> Multi.run(:create_upvote, fn _, _ -> - thread_upcase = thread |> to_string |> String.upcase() - args = Map.put(%{user_id: user_id, thread: thread_upcase}, info.foreign_key, article.id) + thread = thread |> to_string |> String.upcase() + args = Map.put(%{user_id: user_id, thread: thread}, info.foreign_key, article.id) with {:ok, _} <- ORM.create(ArticleUpvote, args) do ORM.find(info.model, article.id) diff --git a/lib/groupher_server/cms/delegates/cited_content.ex b/lib/groupher_server/cms/delegates/cited_content.ex index 32cf1dfe9..fbcd82bd4 100644 --- a/lib/groupher_server/cms/delegates/cited_content.ex +++ b/lib/groupher_server/cms/delegates/cited_content.ex @@ -22,6 +22,8 @@ defmodule GroupherServer.CMS.Delegate.CitedContent do @doc "get paged citing contents" def paged_citing_contents(cited_by_type, cited_by_id, %{page: page, size: size} = filter) do + cited_by_type = cited_by_type |> to_string |> String.upcase() + CitedContent |> where([c], c.cited_by_id == ^cited_by_id and c.cited_by_type == ^cited_by_type) |> QueryBuilder.filter_pack(Map.merge(filter, %{sort: :asc_inserted})) diff --git a/lib/groupher_server_web/resolvers/cms_resolver.ex b/lib/groupher_server_web/resolvers/cms_resolver.ex index 3c081d0ac..7cf3fad7c 100644 --- a/lib/groupher_server_web/resolvers/cms_resolver.ex +++ b/lib/groupher_server_web/resolvers/cms_resolver.ex @@ -102,6 +102,10 @@ defmodule GroupherServerWeb.Resolvers.CMS do CMS.undo_report_article(thread, id, user) end + def paged_citing_contents(_root, ~m(content id filter)a, _info) do + CMS.paged_citing_contents(content, id, filter) + end + # ####################### # thread reaction .. # ####################### diff --git a/lib/groupher_server_web/schema/cms/cms_metrics.ex b/lib/groupher_server_web/schema/cms/cms_metrics.ex index eba72595f..5257fc809 100644 --- a/lib/groupher_server_web/schema/cms/cms_metrics.ex +++ b/lib/groupher_server_web/schema/cms/cms_metrics.ex @@ -41,6 +41,11 @@ defmodule GroupherServerWeb.Schema.CMS.Metrics do value(:share) end + enum :content do + article_values() + value(:comment) + end + enum :when_enum do value(:today) value(:this_week) diff --git a/lib/groupher_server_web/schema/cms/cms_queries.ex b/lib/groupher_server_web/schema/cms/cms_queries.ex index ad64f0dc3..c45be857a 100644 --- a/lib/groupher_server_web/schema/cms/cms_queries.ex +++ b/lib/groupher_server_web/schema/cms/cms_queries.ex @@ -124,6 +124,15 @@ defmodule GroupherServerWeb.Schema.CMS.Queries do resolve(&R.CMS.paged_reports/3) end + @desc "paged citings list" + field :paged_citing_contents, :paged_citings do + arg(:id, non_null(:id)) + arg(:content, :content, default_value: :post) + arg(:filter, :paged_filter) + + resolve(&R.CMS.paged_citing_contents/3) + end + @desc "search communities by title" field :search_communities, :paged_communities do arg(:title, non_null(:string)) diff --git a/lib/groupher_server_web/schema/cms/cms_types.ex b/lib/groupher_server_web/schema/cms/cms_types.ex index d521bb860..4e774fdfd 100644 --- a/lib/groupher_server_web/schema/cms/cms_types.ex +++ b/lib/groupher_server_web/schema/cms/cms_types.ex @@ -317,6 +317,17 @@ defmodule GroupherServerWeb.Schema.CMS.Types do timestamp_fields() end + object :citing do + field(:id, :id) + field(:thread, :string) + field(:title, :string) + field(:block_linker, list_of(:string)) + field(:comment_id, :id) + field(:user, :common_user) + + timestamp_fields() + end + paged_article_objects() object :paged_reports do @@ -324,6 +335,11 @@ defmodule GroupherServerWeb.Schema.CMS.Types do pagination_fields() end + object :paged_citings do + field(:entries, list_of(:citing)) + pagination_fields() + end + object :paged_categories do field(:entries, list_of(:category)) pagination_fields() diff --git a/test/groupher_server/cms/cite_contents/cite_blog_test.exs b/test/groupher_server/cms/cite_contents/cite_blog_test.exs index 360085bab..27ae3da51 100644 --- a/test/groupher_server/cms/cite_contents/cite_blog_test.exs +++ b/test/groupher_server/cms/cite_contents/cite_blog_test.exs @@ -163,7 +163,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Blog do end describe "[cite pagi]" do - @tag :wip test "can get paged cited articles.", ~m(user community blog2 blog_attrs)a do {:ok, comment} = CMS.create_comment( diff --git a/test/groupher_server/cms/cite_contents/cite_job_test.exs b/test/groupher_server/cms/cite_contents/cite_job_test.exs index b4b1c9280..6710f2ba8 100644 --- a/test/groupher_server/cms/cite_contents/cite_job_test.exs +++ b/test/groupher_server/cms/cite_contents/cite_job_test.exs @@ -163,7 +163,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Job do end describe "[cite pagi]" do - @tag :wip test "can get paged cited articles.", ~m(user community job2 job_attrs)a do {:ok, comment} = CMS.create_comment( diff --git a/test/groupher_server/cms/cite_contents/cite_post_test.exs b/test/groupher_server/cms/cite_contents/cite_post_test.exs index 25fb5c140..d610876c5 100644 --- a/test/groupher_server/cms/cite_contents/cite_post_test.exs +++ b/test/groupher_server/cms/cite_contents/cite_post_test.exs @@ -28,7 +28,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do end describe "[cite basic]" do - # test "cited multi post should work", ~m(user community post2 post3 post4 post5 post_attrs)a do body = mock_rich_text( @@ -164,7 +163,6 @@ defmodule GroupherServer.Test.CMS.CiteContent.Post do end describe "[cite pagi]" do - @tag :wip test "can get paged cited articles.", ~m(user community post2 post_attrs)a do {:ok, comment} = CMS.create_comment( diff --git a/test/groupher_server_web/query/cms/citings/blog_citing_test.exs b/test/groupher_server_web/query/cms/citings/blog_citing_test.exs new file mode 100644 index 000000000..a464d829d --- /dev/null +++ b/test/groupher_server_web/query/cms/citings/blog_citing_test.exs @@ -0,0 +1,83 @@ +defmodule GroupherServer.Test.Query.AbuseReports.BlogCiting do + @moduledoc false + + use GroupherServer.TestTools + import Helper.Utils, only: [get_config: 2] + + alias GroupherServer.CMS + + alias CMS.Delegate.CiteTasks + + @site_host get_config(:general, :site_host) + + setup do + {:ok, blog} = db_insert(:blog) + {:ok, user} = db_insert(:user) + + {:ok, community} = db_insert(:community) + blog_attrs = mock_attrs(:blog, %{community_id: community.id}) + + guest_conn = simu_conn(:guest) + + {:ok, ~m(guest_conn community blog blog_attrs user)a} + end + + describe "[query paged_blogs filter pagination]" do + # id + @query """ + query($content: Content!, $id: ID!, $filter: PageFilter!) { + pagedCitingContents(id: $id, content: $content, filter: $filter) { + entries { + id + title + user { + login + nickname + avatar + } + commentId + } + totalPages + totalCount + pageSize + pageNumber + } + } + """ + @tag :wip + test "should get paged cittings", ~m(guest_conn community blog_attrs user)a do + {:ok, blog2} = db_insert(:blog) + + {:ok, comment} = + CMS.create_comment( + :blog, + blog2.id, + mock_comment(~s(the )), + user + ) + + body = + mock_rich_text( + ~s(the ), + ~s(the ) + ) + + blog_attrs = blog_attrs |> Map.merge(%{body: body}) + {:ok, blog_x} = CMS.create_article(community, :blog, blog_attrs, user) + + body = mock_rich_text(~s(the )) + blog_attrs = blog_attrs |> Map.merge(%{body: body}) + {:ok, blog_y} = CMS.create_article(community, :blog, blog_attrs, user) + + CiteTasks.handle(blog_x) + CiteTasks.handle(comment) + CiteTasks.handle(blog_y) + + variables = %{content: "BLOG", id: blog2.id, filter: %{page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedCitingContents") + + assert results |> is_valid_pagination? + assert results["totalCount"] == 3 + end + end +end diff --git a/test/groupher_server_web/query/cms/citings/job_citing_test.exs b/test/groupher_server_web/query/cms/citings/job_citing_test.exs new file mode 100644 index 000000000..156615c17 --- /dev/null +++ b/test/groupher_server_web/query/cms/citings/job_citing_test.exs @@ -0,0 +1,83 @@ +defmodule GroupherServer.Test.Query.AbuseReports.JobCiting do + @moduledoc false + + use GroupherServer.TestTools + import Helper.Utils, only: [get_config: 2] + + alias GroupherServer.CMS + + alias CMS.Delegate.CiteTasks + + @site_host get_config(:general, :site_host) + + setup do + {:ok, job} = db_insert(:job) + {:ok, user} = db_insert(:user) + + {:ok, community} = db_insert(:community) + job_attrs = mock_attrs(:job, %{community_id: community.id}) + + guest_conn = simu_conn(:guest) + + {:ok, ~m(guest_conn community job job_attrs user)a} + end + + describe "[query paged_jobs filter pagination]" do + # id + @query """ + query($content: Content!, $id: ID!, $filter: PageFilter!) { + pagedCitingContents(id: $id, content: $content, filter: $filter) { + entries { + id + title + user { + login + nickname + avatar + } + commentId + } + totalPages + totalCount + pageSize + pageNumber + } + } + """ + @tag :wip + test "should get paged cittings", ~m(guest_conn community job_attrs user)a do + {:ok, job2} = db_insert(:job) + + {:ok, comment} = + CMS.create_comment( + :job, + job2.id, + mock_comment(~s(the )), + user + ) + + body = + mock_rich_text( + ~s(the ), + ~s(the ) + ) + + job_attrs = job_attrs |> Map.merge(%{body: body}) + {:ok, job_x} = CMS.create_article(community, :job, job_attrs, user) + + body = mock_rich_text(~s(the )) + job_attrs = job_attrs |> Map.merge(%{body: body}) + {:ok, job_y} = CMS.create_article(community, :job, job_attrs, user) + + CiteTasks.handle(job_x) + CiteTasks.handle(comment) + CiteTasks.handle(job_y) + + variables = %{content: "JOB", id: job2.id, filter: %{page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedCitingContents") + + assert results |> is_valid_pagination? + assert results["totalCount"] == 3 + end + end +end diff --git a/test/groupher_server_web/query/cms/citings/post_citing_test.exs b/test/groupher_server_web/query/cms/citings/post_citing_test.exs new file mode 100644 index 000000000..22bdf9f9f --- /dev/null +++ b/test/groupher_server_web/query/cms/citings/post_citing_test.exs @@ -0,0 +1,83 @@ +defmodule GroupherServer.Test.Query.AbuseReports.PostCiting do + @moduledoc false + + use GroupherServer.TestTools + import Helper.Utils, only: [get_config: 2] + + alias GroupherServer.CMS + + alias CMS.Delegate.CiteTasks + + @site_host get_config(:general, :site_host) + + setup do + {:ok, post} = db_insert(:post) + {:ok, user} = db_insert(:user) + + {:ok, community} = db_insert(:community) + post_attrs = mock_attrs(:post, %{community_id: community.id}) + + guest_conn = simu_conn(:guest) + + {:ok, ~m(guest_conn community post post_attrs user)a} + end + + describe "[query paged_posts filter pagination]" do + # id + @query """ + query($content: Content!, $id: ID!, $filter: PageFilter!) { + pagedCitingContents(id: $id, content: $content, filter: $filter) { + entries { + id + title + user { + login + nickname + avatar + } + commentId + } + totalPages + totalCount + pageSize + pageNumber + } + } + """ + @tag :wip + test "should get paged cittings", ~m(guest_conn community post_attrs user)a do + {:ok, post2} = db_insert(:post) + + {:ok, comment} = + CMS.create_comment( + :post, + post2.id, + mock_comment(~s(the )), + user + ) + + body = + mock_rich_text( + ~s(the ), + ~s(the ) + ) + + post_attrs = post_attrs |> Map.merge(%{body: body}) + {:ok, post_x} = CMS.create_article(community, :post, post_attrs, user) + + body = mock_rich_text(~s(the )) + post_attrs = post_attrs |> Map.merge(%{body: body}) + {:ok, post_y} = CMS.create_article(community, :post, post_attrs, user) + + CiteTasks.handle(post_x) + CiteTasks.handle(comment) + CiteTasks.handle(post_y) + + variables = %{content: "POST", id: post2.id, filter: %{page: 1, size: 10}} + results = guest_conn |> query_result(@query, variables, "pagedCitingContents") + + assert results |> is_valid_pagination? + assert results["totalCount"] == 3 + end + end +end