From b37255d92da269e1565d1d976e2d89cb1d9b4a02 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Tue, 8 Jun 2021 23:49:35 +0800 Subject: [PATCH 01/31] refactor(editor-workflow): editor parse wip --- .../cms/delegates/article_curd.ex | 10 +++ lib/helper/converter/article.ex | 48 +++++++++++++ lib/helper/converter/editor_to_html/index.ex | 67 +++++++++---------- lib/helper/converter/html_sanitizer.ex | 43 +++++++----- lib/helper/html.ex | 8 +-- lib/helper/utils/utils.ex | 2 + mix.exs | 3 +- mix.lock | 2 + test/helper/converter/article_test.exs | 38 +++++++++++ .../editor_to_html_test/index_test.exs | 16 ----- test/helper/utils_test.exs | 6 ++ 11 files changed, 169 insertions(+), 74 deletions(-) create mode 100644 lib/helper/converter/article.ex create mode 100644 test/helper/converter/article_test.exs diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index 0ca271631..26982e4d2 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -172,7 +172,9 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do |> Multi.run(:update_user_published_meta, fn _, _ -> Accounts.update_published_states(uid, thread) end) + # TODO: run mini tasks |> Multi.run(:mention_users, fn _, %{create_article: article} -> + # article.body |> Jason.decode!() |> 各种小 task Delivery.mention_from_content(community.raw, thread, article, attrs, %User{id: uid}) {:ok, :pass} end) @@ -387,6 +389,14 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do # for create artilce step in Multi.new defp do_create_article(target, attrs, %Author{id: aid}, %Community{id: cid}) do + # {:ok, { body: body, body_html: body_html }} = Convert.body_coverter() + + # body_map = attrs.body |> to_editor_map + # body = body_map |> Jason.encode + # body_html = body_map |> Convert.to_html + + # |> Ecto.Changeset.put_change(:emotions, @default_emotions) + target |> struct() |> target.changeset(attrs) diff --git a/lib/helper/converter/article.ex b/lib/helper/converter/article.ex new file mode 100644 index 000000000..9cd03003a --- /dev/null +++ b/lib/helper/converter/article.ex @@ -0,0 +1,48 @@ +defmodule Helper.Converter.Article do + @moduledoc """ + convert body + + {:ok, { body: body, body_html: body_html }} = Converter.Article.body_parse(body) + """ + import Helper.Utils, only: [done: 1, uid: 0] + alias Helper.Converter.EditorToHTML + + @doc """ + parse article body field + """ + @spec body_parse(String.t()) :: {:ok, %{body: Map.t(), body_html: String.t()}} + def body_parse(body) when is_binary(body) do + with {:ok, body_map} <- to_editor_map(body), + {:ok, body_html} <- EditorToHTML.to_html(body_map), + {:ok, body_encode} <- Jason.encode(body_map) do + %{body: body_encode, body_html: body_html} |> done + end + end + + def body_parse(_), do: {:error, "wrong body fmt"} + + @doc """ + decode article body string to editor map and assign id for each block + """ + def to_editor_map(string) when is_binary(string) do + with {:ok, map} <- Jason.decode(string) do + blocks = + Enum.map(map["blocks"], fn block -> + block_id = if is_id_valid?(block), do: block["id"], else: "block-#{uid()}" + + Map.merge(block, %{"id" => block_id}) + end) + + Map.merge(map, %{"blocks" => blocks}) |> done + end + end + + def to_editor_map(_), do: {:error, "wrong editor fmt"} + + # use custom block id instead of editor.js's default block id + defp is_id_valid?(block) when is_map(block) do + Map.has_key?(block, "id") and String.starts_with?(block["id"], "block-") + end + + defp is_id_valid?(_), do: false +end diff --git a/lib/helper/converter/editor_to_html/index.ex b/lib/helper/converter/editor_to_html/index.ex index d2aa75fa5..f6a56ffdd 100644 --- a/lib/helper/converter/editor_to_html/index.ex +++ b/lib/helper/converter/editor_to_html/index.ex @@ -8,18 +8,17 @@ defmodule Helper.Converter.EditorToHTML do alias Helper.Types, as: T alias Helper.Utils - alias Helper.Converter.{EditorToHTML, HtmlSanitizer} + alias Helper.Converter.{Article, EditorToHTML, HtmlSanitizer} alias EditorToHTML.{Class, Frags, Validator} # alias EditorToHTML.Assets.{DelimiterIcons} @root_class Class.article() - @spec to_html(String.t()) :: {:ok, T.html()} - def to_html(string) when is_binary(string) do - with {:ok, parsed} = string_to_json(string), - {:ok, _} <- Validator.is_valid(parsed) do + @spec to_html(Map.t()) :: {:ok, T.html()} + def to_html(editor_map) when is_map(editor_map) do + with {:ok, _} <- Validator.is_valid(editor_map) do content = - Enum.reduce(parsed["blocks"], "", fn block, acc -> + Enum.reduce(editor_map["blocks"], "", fn block, acc -> clean_html = block |> parse_block |> HtmlSanitizer.sanitize() acc <> clean_html end) @@ -29,6 +28,13 @@ defmodule Helper.Converter.EditorToHTML do end end + @spec to_html(String.t()) :: {:ok, T.html()} + def to_html(string) when is_binary(string) do + with {:ok, editor_map} = Article.to_editor_map(string) do + to_html(editor_map) + end + end + @doc "used for markdown ast to editor" def to_html(editor_blocks) when is_list(editor_blocks) do content = @@ -41,13 +47,19 @@ defmodule Helper.Converter.EditorToHTML do {:ok, ~s(
#{content}
)} end - defp parse_block(%{"type" => "paragraph", "data" => %{"text" => text}}), do: "

#{text}

" + defp parse_block(%{"id" => id, "type" => "paragraph", "data" => %{"text" => text}}) do + ~s(

#{text}

) + end - defp parse_block(%{"type" => "header", "data" => data}), do: Frags.Header.get(data) + defp parse_block(%{"type" => "header", "data" => data}) do + Frags.Header.get(data) + end - defp parse_block(%{"type" => "quote", "data" => data}), do: Frags.Quote.get(data) + defp parse_block(%{"type" => "quote", "data" => data}) do + Frags.Quote.get(data) + end - defp parse_block(%{"type" => "list", "data" => data}) do + defp parse_block(%{"id" => id, "type" => "list", "data" => data}) do %{"items" => items, "mode" => mode} = data list_wrapper_class = get_in(@root_class, ["list", "wrapper"]) @@ -57,11 +69,10 @@ defmodule Helper.Converter.EditorToHTML do acc <> Frags.List.get_item(mode |> String.to_atom(), item) end) - anchor_id = Utils.uid(:html, data) - ~s(
#{items_content}
) + ~s(
#{items_content}
) end - defp parse_block(%{"type" => "table", "data" => data}) do + defp parse_block(%{"id" => id, "type" => "table", "data" => data}) do %{"items" => items, "columnCount" => column_count} = data # IO.inspect(column_count, label: "the fuck column_count") @@ -75,9 +86,7 @@ defmodule Helper.Converter.EditorToHTML do table_wrapper_class = get_in(@root_class, ["table", "wrapper"]) - anchor_id = Utils.uid(:html, data) - - ~s(
+ ~s(
#{rows_content} @@ -86,7 +95,7 @@ defmodule Helper.Converter.EditorToHTML do ) end - defp parse_block(%{"type" => "image", "data" => %{"mode" => "single"} = data}) do + defp parse_block(%{"id" => id, "type" => "image", "data" => %{"mode" => "single"} = data}) do %{"items" => items} = data image_wrapper_class = get_in(@root_class, ["image", "wrapper"]) @@ -94,12 +103,10 @@ defmodule Helper.Converter.EditorToHTML do items_content = Frags.Image.get_item(:single, List.first(items)) caption_content = Frags.Image.get_caption(:html, List.first(items)) - anchor_id = Utils.uid(:html, data) - - ~s(
#{items_content}#{caption_content}
) + ~s(
#{items_content}#{caption_content}
) end - defp parse_block(%{"type" => "image", "data" => %{"mode" => "jiugongge"} = data}) do + defp parse_block(%{"id" => id, "type" => "image", "data" => %{"mode" => "jiugongge"} = data}) do %{"items" => items} = data image_wrapper_class = get_in(@root_class, ["image", "wrapper"]) @@ -110,16 +117,14 @@ defmodule Helper.Converter.EditorToHTML do acc <> Frags.Image.get_item(:jiugongge, item) end) - anchor_id = Utils.uid(:html, data) - - ~s(
+ ~s(
#{items_content}
) end - defp parse_block(%{"type" => "image", "data" => %{"mode" => "gallery"} = data}) do + defp parse_block(%{"id" => id, "type" => "image", "data" => %{"mode" => "gallery"} = data}) do %{"items" => items} = data image_wrapper_class = get_in(@root_class, ["image", "wrapper"]) @@ -133,9 +138,7 @@ defmodule Helper.Converter.EditorToHTML do minimap_content = Frags.Image.get_minimap(items) - anchor_id = Utils.uid(:html, data) - - ~s(
+ ~s(
#{items_content} @@ -145,7 +148,7 @@ defmodule Helper.Converter.EditorToHTML do
) end - defp parse_block(%{"type" => "people", "data" => %{"mode" => "gallery"} = data}) do + defp parse_block(%{"id" => id, "type" => "people", "data" => %{"mode" => "gallery"} = data}) do %{"items" => items} = data # set id to each people for switch them @@ -157,9 +160,7 @@ defmodule Helper.Converter.EditorToHTML do previewer_content = Frags.People.get_previewer(:gallery, items) card_content = Frags.People.get_card(:gallery, items) - anchor_id = Utils.uid(:html, data) - - ~s(
+ ~s(
#{previewer_content} #{card_content} @@ -180,6 +181,4 @@ defmodule Helper.Converter.EditorToHTML do undown_block_class = @root_class["unknow_block"] ~s("
[unknow block]
") end - - def string_to_json(string), do: Jason.decode(string) end diff --git a/lib/helper/converter/html_sanitizer.ex b/lib/helper/converter/html_sanitizer.ex index 476c014e3..9df1640b9 100644 --- a/lib/helper/converter/html_sanitizer.ex +++ b/lib/helper/converter/html_sanitizer.ex @@ -14,7 +14,7 @@ defmodule Helper.Converter.HtmlSanitizer do Meta.strip_comments() Meta.allow_tag_with_uri_attributes("a", ["href"], ["http", "https"]) - Meta.allow_tag_with_these_attributes("a", ["name", "title", "class", "data-glightbox"]) + Meta.allow_tag_with_these_attributes("a", ["id", "name", "title", "class", "data-glightbox"]) # Meta.allow_tag_with_these_attributes("strong", []) # Meta.allow_tag_with_these_attributes("em", []) @@ -22,33 +22,42 @@ defmodule Helper.Converter.HtmlSanitizer do Meta.allow_tag_with_these_attributes("i", []) Meta.allow_tag_with_these_attributes("mark", ["class"]) - Meta.allow_tag_with_these_attributes("code", ["class"]) - Meta.allow_tag_with_these_attributes("pre", ["class"]) + Meta.allow_tag_with_these_attributes("code", ["id", "class"]) + Meta.allow_tag_with_these_attributes("pre", ["id", "class"]) # Meta.allow_tag_with_these_attributes("p", []) - Meta.allow_tag_with_these_attributes("h1", ["class"]) - Meta.allow_tag_with_these_attributes("h2", ["class"]) - Meta.allow_tag_with_these_attributes("h3", ["class"]) + Meta.allow_tag_with_these_attributes("h1", ["id", "class"]) + Meta.allow_tag_with_these_attributes("h2", ["id", "class"]) + Meta.allow_tag_with_these_attributes("h3", ["id", "class"]) # Meta.allow_tag_with_these_attributes("h4", ["class"]) # Meta.allow_tag_with_these_attributes("h5", ["class"]) # Meta.allow_tag_with_these_attributes("h6", ["class"]) - Meta.allow_tag_with_these_attributes("p", ["class"]) - Meta.allow_tag_with_these_attributes("img", ["class", "src", "style", "alt", "data-index"]) + Meta.allow_tag_with_these_attributes("p", ["id", "class"]) + + Meta.allow_tag_with_these_attributes("img", [ + "id", + "class", + "src", + "style", + "alt", + "data-index" + ]) + Meta.allow_tag_with_these_attributes("div", ["id", "class", "data-index"]) - Meta.allow_tag_with_these_attributes("ul", ["class"]) - Meta.allow_tag_with_these_attributes("ol", ["class"]) - Meta.allow_tag_with_these_attributes("li", ["class"]) + Meta.allow_tag_with_these_attributes("ul", ["id", "class"]) + Meta.allow_tag_with_these_attributes("ol", ["id", "class"]) + Meta.allow_tag_with_these_attributes("li", ["id", "class"]) # table - Meta.allow_tag_with_these_attributes("table", []) - Meta.allow_tag_with_these_attributes("tbody", []) - Meta.allow_tag_with_these_attributes("tr", []) - Meta.allow_tag_with_these_attributes("th", ["class"]) - Meta.allow_tag_with_these_attributes("td", ["class", "style"]) + Meta.allow_tag_with_these_attributes("table", ["id"]) + Meta.allow_tag_with_these_attributes("tbody", ["id"]) + Meta.allow_tag_with_these_attributes("tr", ["id"]) + Meta.allow_tag_with_these_attributes("th", ["id", "class"]) + Meta.allow_tag_with_these_attributes("td", ["id", "class", "style"]) # blockquote Meta.allow_tag_with_these_attributes("blockquote", ["id", "class"]) - Meta.allow_tag_with_these_attributes("image", ["xlink:href"]) + Meta.allow_tag_with_these_attributes("image", ["id", "xlink:href"]) Meta.allow_tag_with_these_attributes("svg", [ "t", diff --git a/lib/helper/html.ex b/lib/helper/html.ex index 6087c7cae..328d8d40e 100644 --- a/lib/helper/html.ex +++ b/lib/helper/html.ex @@ -8,12 +8,8 @@ defmodule Helper.HTML do def safe_string(%Ecto.Changeset{valid?: true, changes: changes} = changeset, field) do case Map.has_key?(changes, field) do - true -> - changeset - |> put_change(field, escape_to_safe_string(changes[field])) - - _ -> - changeset + true -> changeset |> put_change(field, escape_to_safe_string(changes[field])) + _ -> changeset end end diff --git a/lib/helper/utils/utils.ex b/lib/helper/utils/utils.ex index 62a978c72..a242efa0c 100644 --- a/lib/helper/utils/utils.ex +++ b/lib/helper/utils/utils.ex @@ -201,6 +201,8 @@ defmodule Helper.Utils do end end + def uid(str_len \\ 5), do: Nanoid.generate(str_len) + @doc "html uniq id generator for editorjs" @spec uid(:html, map) :: String.t() def uid(:html, %{"id" => id}) when g_none_empty_str(id), do: id diff --git a/mix.exs b/mix.exs index b4ea986b3..c54d973e2 100644 --- a/mix.exs +++ b/mix.exs @@ -107,7 +107,8 @@ defmodule GroupherServer.Mixfile do # 遵循中文排版指南 # https://github.com/cataska/pangu.ex {:pangu, "~> 0.1.0"}, - {:accessible, "~> 0.3.0"} + {:accessible, "~> 0.3.0"}, + {:floki, "~> 0.30.1"} ] end diff --git a/mix.lock b/mix.lock index 1e80ecb3c..b356ab1b0 100644 --- a/mix.lock +++ b/mix.lock @@ -36,12 +36,14 @@ "excoveralls": {:hex, :excoveralls, "0.14.1", "14140e4ef343f2af2de33d35268c77bc7983d7824cb945e6c2af54235bc2e61f", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "4a588f9f8cf9dc140cc1f3d0ea4d849b2f76d5d8bee66b73c304bb3d3689c8b0"}, "faker": {:hex, :faker, "0.16.0", "1e2cf3e8d60d44a30741fb98118fcac18b2020379c7e00d18f1a005841b2f647", [:mix], [], "hexpm", "fbcb9bf1299dff3c9dd7e50f41802bbc472ffbb84e7656394c8aa913ec315141"}, "file_system": {:hex, :file_system, "0.2.8", "f632bd287927a1eed2b718f22af727c5aeaccc9a98d8c2bd7bff709e851dc986", [:mix], [], "hexpm", "97a3b6f8d63ef53bd0113070102db2ce05352ecf0d25390eb8d747c2bde98bca"}, + "floki": {:hex, :floki, "0.30.1", "75d35526d3a1459920b6e87fdbc2e0b8a3670f965dd0903708d2b267e0904c55", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "e9c03524447d1c4cbfccd672d739b8c18453eee377846b119d4fd71b1a176bb8"}, "fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], [], "hexpm"}, "gen_stage": {:hex, :gen_stage, "0.14.2", "6a2a578a510c5bfca8a45e6b27552f613b41cf584b58210f017088d3d17d0b14", [:mix], [], "hexpm", "1f201083ca2ee1ea2b8e1eb6e98d9842ef93f2e5efa2d602740ab0c56c2bc90b"}, "gen_state_machine": {:hex, :gen_state_machine, "2.0.5", "9ac15ec6e66acac994cc442dcc2c6f9796cf380ec4b08267223014be1c728a95", [:mix], [], "hexpm", "5cacd405e72b2609a7e1f891bddb80c53d0b3b7b0036d1648e7382ca108c41c8"}, "gettext": {:hex, :gettext, "0.18.2", "7df3ea191bb56c0309c00a783334b288d08a879f53a7014341284635850a6e55", [:mix], [], "hexpm", "f9f537b13d4fdd30f3039d33cb80144c3aa1f8d9698e47d7bcbcc8df93b1f5c5"}, "guardian": {:hex, :guardian, "2.1.1", "1f02b349f6ba765647cc834036a8d76fa4bd65605342fe3a031df3c99d0d411a", [:mix], [{:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "189b87ba7ce6b40d6ba029138098b96ffc4ae78f229f5b39539b9141af8bf0f8"}, "hackney": {:hex, :hackney, "1.17.4", "99da4674592504d3fb0cfef0db84c3ba02b4508bae2dff8c0108baa0d6e0977c", [:rebar3], [{:certifi, "~>2.6.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "de16ff4996556c8548d512f4dbe22dd58a587bf3332e7fd362430a7ef3986b16"}, + "html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"}, "html_sanitize_ex": {:hex, :html_sanitize_ex, "1.4.1", "e8a67da405fe9f0d1be121a40a60f70811192033a5b8d00a95dddd807f5e053e", [:mix], [{:mochiweb, "~> 2.15", [hex: :mochiweb, repo: "hexpm", optional: false]}], "hexpm", "68d92656f47cd73598c45ad2394561f025c8c65d146001b955fd7b517858962a"}, "httpoison": {:hex, :httpoison, "1.6.2", "ace7c8d3a361cebccbed19c283c349b3d26991eff73a1eaaa8abae2e3c8089b6", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "aa2c74bd271af34239a3948779612f87df2422c2fdcfdbcec28d9c105f0773fe"}, "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, diff --git a/test/helper/converter/article_test.exs b/test/helper/converter/article_test.exs new file mode 100644 index 000000000..564806deb --- /dev/null +++ b/test/helper/converter/article_test.exs @@ -0,0 +1,38 @@ +defmodule GroupherServer.Test.Helper.Converter.Article do + @moduledoc false + + use GroupherServerWeb.ConnCase, async: true + + alias Helper.Converter.{Article, EditorToHTML} + + describe "[snaitizer test]" do + @tag :wip + test "body_parse should return valid format" do + body = """ + { + "time": 11, + "blocks": [ + { + "id" : "FLHF-eF_x4", + "type" : "paragraph", + "data" : { + "text" : "this is a paragraph." + } + } + ], + "version": "2.20" + } + """ + + {:ok, %{body: body, body_html: body_html}} = Article.body_parse(body) + {:ok, body_map} = Jason.decode(body) + + assert body_html |> String.contains?("

List.first() + + assert EditorToHTML.Validator.is_valid(body_map) + assert p_block["id"] |> String.starts_with?("block-") + end + end +end diff --git a/test/helper/converter/editor_to_html_test/index_test.exs b/test/helper/converter/editor_to_html_test/index_test.exs index 240311aab..3425f97da 100644 --- a/test/helper/converter/editor_to_html_test/index_test.exs +++ b/test/helper/converter/editor_to_html_test/index_test.exs @@ -25,13 +25,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML do }) describe "[basic convert]" do - test "basic string_json parse should work" do - string = ~S({"time":1566184478687,"blocks":[{}],"version":"2.15.0"}) - {:ok, converted} = Parser.string_to_json(string) - - assert converted["version"] == "2.15.0" - end - @editor_json %{ "time" => 1_567_250_876_713, "blocks" => [], @@ -101,15 +94,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML do assert String.contains?(error, "undown block: 1") end - - test "real-world editor.js data should work" do - {:ok, converted} = Parser.string_to_json(@real_editor_data) - - assert not Enum.empty?(converted["blocks"]) - assert converted["blocks"] |> is_list - assert converted["version"] |> is_binary - assert converted["time"] |> is_integer - end end describe "[secure issues]" do diff --git a/test/helper/utils_test.exs b/test/helper/utils_test.exs index 389e5279c..c6cfbcd24 100644 --- a/test/helper/utils_test.exs +++ b/test/helper/utils_test.exs @@ -181,6 +181,12 @@ defmodule GroupherServer.Test.Helper.UtilsTest do end describe "[uid generator]" do + @tag :wip + test "default id should have length of 5" do + uid_str = Utils.uid() + assert String.length(uid_str) == 5 + end + test "should gen uniq id with lengh of 5" do uid_str = Utils.uid(:html, "what_ever") assert String.length(uid_str) == 5 From f8936b771b41beaaabe0ad5dee8754a51ec721a0 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 11:49:45 +0800 Subject: [PATCH 02/31] refactor(editor-workflow): editor parse test fix --- lib/helper/converter/article.ex | 32 +++++++----- .../converter/editor_to_html/frags/header.ex | 25 ++++------ .../converter/editor_to_html/frags/quote.ex | 18 +++---- lib/helper/converter/editor_to_html/index.ex | 50 +++++++++---------- lib/helper/utils/utils.ex | 4 +- test/helper/converter/article_test.exs | 1 - .../editor_to_html_test/header_test.exs | 21 ++++---- .../editor_to_html_test/image_test.exs | 6 +-- .../editor_to_html_test/index_test.exs | 13 +++-- .../editor_to_html_test/paragraph_test.exs | 4 +- .../editor_to_html_test/table_test.exs | 6 +-- test/helper/converter/md_to_editor_test.exs | 12 +++-- test/helper/utils_test.exs | 1 - 13 files changed, 102 insertions(+), 91 deletions(-) diff --git a/lib/helper/converter/article.ex b/lib/helper/converter/article.ex index 9cd03003a..87ff9ffa9 100644 --- a/lib/helper/converter/article.ex +++ b/lib/helper/converter/article.ex @@ -4,7 +4,8 @@ defmodule Helper.Converter.Article do {:ok, { body: body, body_html: body_html }} = Converter.Article.body_parse(body) """ - import Helper.Utils, only: [done: 1, uid: 0] + import Helper.Utils, only: [done: 1, uid: 0, keys_to_strings: 1] + alias Helper.Converter.EditorToHTML @doc """ @@ -25,24 +26,31 @@ defmodule Helper.Converter.Article do decode article body string to editor map and assign id for each block """ def to_editor_map(string) when is_binary(string) do - with {:ok, map} <- Jason.decode(string) do - blocks = - Enum.map(map["blocks"], fn block -> - block_id = if is_id_valid?(block), do: block["id"], else: "block-#{uid()}" - - Map.merge(block, %{"id" => block_id}) - end) - + with {:ok, map} <- Jason.decode(string), + {:ok, _} <- EditorToHTML.Validator.is_valid(map) do + blocks = Enum.map(map["blocks"], &Map.merge(&1, %{"id" => get_block_id(&1)})) Map.merge(map, %{"blocks" => blocks}) |> done end end + # for markdown blocks + def to_editor_map(blocks) when is_list(blocks) do + Enum.map(blocks, fn block -> + block = keys_to_strings(block) + Map.merge(block, %{"id" => get_block_id(block)}) + end) + |> done + end + def to_editor_map(_), do: {:error, "wrong editor fmt"} # use custom block id instead of editor.js's default block id - defp is_id_valid?(block) when is_map(block) do - Map.has_key?(block, "id") and String.starts_with?(block["id"], "block-") + defp get_block_id(%{"id" => id} = block) when not is_nil(id) do + case String.starts_with?(block["id"], "block-") do + true -> id + false -> "block-#{uid()}" + end end - defp is_id_valid?(_), do: false + defp get_block_id(_), do: "block-#{uid()}" end diff --git a/lib/helper/converter/editor_to_html/frags/header.ex b/lib/helper/converter/editor_to_html/frags/header.ex index 1acf4968d..5169ae53f 100644 --- a/lib/helper/converter/editor_to_html/frags/header.ex +++ b/lib/helper/converter/editor_to_html/frags/header.ex @@ -5,47 +5,40 @@ defmodule Helper.Converter.EditorToHTML.Frags.Header do see https://editorjs.io/ """ alias Helper.Types, as: T - alias Helper.Utils - alias Helper.Converter.EditorToHTML.Class @class get_in(Class.article(), ["header"]) - @spec get(T.editor_header()) :: T.html() - def get(%{"eyebrowTitle" => eyebrow_title, "footerTitle" => footer_title} = data) do + @spec get(String.t(), T.editor_header()) :: T.html() + def get(id, %{"eyebrowTitle" => eyebrow_title, "footerTitle" => footer_title} = data) do %{"text" => text, "level" => level} = data - anchor_id = Utils.uid(:html, data) - ~s(

+ ~s(
#{eyebrow_title}
#{text}
#{footer_title}
) end - def get(%{"eyebrowTitle" => eyebrow_title} = data) do + def get(id, %{"eyebrowTitle" => eyebrow_title} = data) do %{"text" => text, "level" => level} = data - anchor_id = Utils.uid(:html, data) - ~s(
+ ~s(
#{eyebrow_title}
#{text}
) end - def get(%{"footerTitle" => footer_title} = data) do + def get(id, %{"footerTitle" => footer_title} = data) do %{"text" => text, "level" => level} = data - anchor_id = Utils.uid(:html, data) - ~s(
+ ~s(
#{text}
#{footer_title}
) end - def get(%{"text" => text, "level" => level} = data) do - anchor_id = Utils.uid(:html, data) - - ~s(#{text}) + def get(id, %{"text" => text, "level" => level} = data) do + ~s(#{text}) end end diff --git a/lib/helper/converter/editor_to_html/frags/quote.ex b/lib/helper/converter/editor_to_html/frags/quote.ex index 0309350ab..a6301449d 100644 --- a/lib/helper/converter/editor_to_html/frags/quote.ex +++ b/lib/helper/converter/editor_to_html/frags/quote.ex @@ -8,32 +8,28 @@ defmodule Helper.Converter.EditorToHTML.Frags.Quote do alias Helper.Converter.EditorToHTML.Class alias Helper.Types, as: T - alias Helper.Utils @class get_in(Class.article(), ["quote"]) - @spec get(T.editor_quote()) :: T.html() - def get(%{"mode" => "short", "text" => text} = data) do - anchor_id = Utils.uid(:html, data) - - ~s(
+ @spec get(String.t(), T.editor_quote()) :: T.html() + def get(id, %{"mode" => "short", "text" => text} = data) do + ~s(
#{text}
) end - def get(%{"mode" => "long", "text" => text, "caption" => caption} = data) + def get(id, %{"mode" => "long", "text" => text, "caption" => caption} = data) when g_none_empty_str(caption) do caption_content = frag(:caption, caption) - anchor_id = Utils.uid(:html, data) - ~s(
+ ~s(
#{text}
#{caption_content}
) end - def get(%{"mode" => "long", "text" => text}) do - ~s(
+ def get(id, %{"mode" => "long", "text" => text}) do + ~s(
#{text}
) end diff --git a/lib/helper/converter/editor_to_html/index.ex b/lib/helper/converter/editor_to_html/index.ex index f6a56ffdd..2d3d7dacd 100644 --- a/lib/helper/converter/editor_to_html/index.ex +++ b/lib/helper/converter/editor_to_html/index.ex @@ -9,54 +9,55 @@ defmodule Helper.Converter.EditorToHTML do alias Helper.Utils alias Helper.Converter.{Article, EditorToHTML, HtmlSanitizer} - alias EditorToHTML.{Class, Frags, Validator} + alias EditorToHTML.{Class, Frags} # alias EditorToHTML.Assets.{DelimiterIcons} @root_class Class.article() @spec to_html(Map.t()) :: {:ok, T.html()} def to_html(editor_map) when is_map(editor_map) do - with {:ok, _} <- Validator.is_valid(editor_map) do - content = - Enum.reduce(editor_map["blocks"], "", fn block, acc -> - clean_html = block |> parse_block |> HtmlSanitizer.sanitize() - acc <> clean_html - end) + content = + Enum.reduce(editor_map["blocks"], "", fn block, acc -> + clean_html = block |> parse_block |> HtmlSanitizer.sanitize() + acc <> clean_html + end) - viewer_class = @root_class["viewer"] - {:ok, ~s(
#{content}
)} - end + viewer_class = @root_class["viewer"] + {:ok, ~s(
#{content}
)} end @spec to_html(String.t()) :: {:ok, T.html()} def to_html(string) when is_binary(string) do - with {:ok, editor_map} = Article.to_editor_map(string) do + with {:ok, editor_map} <- Article.to_editor_map(string) do to_html(editor_map) end end @doc "used for markdown ast to editor" def to_html(editor_blocks) when is_list(editor_blocks) do - content = - Enum.reduce(editor_blocks, "", fn block, acc -> - clean_html = block |> Utils.keys_to_strings() |> parse_block |> HtmlSanitizer.sanitize() - acc <> clean_html - end) + with {:ok, editor_blocks} <- Article.to_editor_map(editor_blocks) do + content = + Enum.reduce(editor_blocks, "", fn block, acc -> + clean_html = block |> parse_block |> HtmlSanitizer.sanitize() - viewer_class = @root_class["viewer"] - {:ok, ~s(
#{content}
)} + acc <> clean_html + end) + + viewer_class = @root_class["viewer"] + {:ok, ~s(
#{content}
)} + end end defp parse_block(%{"id" => id, "type" => "paragraph", "data" => %{"text" => text}}) do ~s(

#{text}

) end - defp parse_block(%{"type" => "header", "data" => data}) do - Frags.Header.get(data) + defp parse_block(%{"id" => id, "type" => "header", "data" => data}) do + Frags.Header.get(id, data) end - defp parse_block(%{"type" => "quote", "data" => data}) do - Frags.Quote.get(data) + defp parse_block(%{"id" => id, "type" => "quote", "data" => data}) do + Frags.Quote.get(id, data) end defp parse_block(%{"id" => id, "type" => "list", "data" => data}) do @@ -168,13 +169,12 @@ defmodule Helper.Converter.EditorToHTML do
) end - defp parse_block(%{"type" => "code", "data" => data}) do + defp parse_block(%{"id" => id, "type" => "code", "data" => data}) do text = get_in(data, ["text"]) code = text |> Phoenix.HTML.html_escape() |> Phoenix.HTML.safe_to_string() lang = get_in(data, ["lang"]) - "
#{code}
" - # |> IO.inspect(label: "code ret") + ~s(
#{code}
) end defp parse_block(_block) do diff --git a/lib/helper/utils/utils.ex b/lib/helper/utils/utils.ex index a242efa0c..18885476b 100644 --- a/lib/helper/utils/utils.ex +++ b/lib/helper/utils/utils.ex @@ -201,7 +201,9 @@ defmodule Helper.Utils do end end - def uid(str_len \\ 5), do: Nanoid.generate(str_len) + def uid(str_len \\ 5) do + Nanoid.generate(str_len, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") + end @doc "html uniq id generator for editorjs" @spec uid(:html, map) :: String.t() diff --git a/test/helper/converter/article_test.exs b/test/helper/converter/article_test.exs index 564806deb..ae56e1b5a 100644 --- a/test/helper/converter/article_test.exs +++ b/test/helper/converter/article_test.exs @@ -6,7 +6,6 @@ defmodule GroupherServer.Test.Helper.Converter.Article do alias Helper.Converter.{Article, EditorToHTML} describe "[snaitizer test]" do - @tag :wip test "body_parse should return valid format" do body = """ { diff --git a/test/helper/converter/editor_to_html_test/header_test.exs b/test/helper/converter/editor_to_html_test/header_test.exs index 7c8602f22..9454fe66d 100644 --- a/test/helper/converter/editor_to_html_test/header_test.exs +++ b/test/helper/converter/editor_to_html_test/header_test.exs @@ -11,11 +11,12 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Header do @class get_in(@root_class, ["header"]) describe "[header block unit]" do - defp set_data(data) do + defp set_data(data, id \\ "") do %{ "time" => 1_567_250_876_713, "blocks" => [ %{ + "id" => id, "type" => "header", "data" => data } @@ -82,18 +83,20 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Header do test "edit exsit block will not change id value" do editor_json = - set_data(%{ - "id" => "exist", - "text" => "header content", - "level" => 1, - "eyebrowTitle" => "eyebrow title content", - "footerTitle" => "footer title content" - }) + set_data( + %{ + "text" => "header content", + "level" => 1, + "eyebrowTitle" => "eyebrow title content", + "footerTitle" => "footer title content" + }, + "block-id-exist" + ) {:ok, editor_string} = Jason.encode(editor_json) {:ok, converted} = Parser.to_html(editor_string) - assert Utils.str_occurence(converted, ~s(id="exist")) == 1 + assert converted |> String.contains?(~s(
1_567_250_876_713, "blocks" => [ %{ + "id" => id, "type" => "image", "data" => %{ - "id" => id, "mode" => mode, "items" => items } @@ -166,13 +166,13 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Image do "caption" => "this is a caption 1" } end), - "exsit" + "block-id-exsit" ) {:ok, editor_string} = Jason.encode(editor_json) {:ok, converted} = Parser.to_html(editor_string) - assert Utils.str_occurence(converted, "id=\"exsit\"") == 1 + assert Utils.str_occurence(converted, ~s(id="block-id-exsit")) == 1 end test "invalid mode parse should raise error message" do diff --git a/test/helper/converter/editor_to_html_test/index_test.exs b/test/helper/converter/editor_to_html_test/index_test.exs index 3425f97da..bfa214eaf 100644 --- a/test/helper/converter/editor_to_html_test/index_test.exs +++ b/test/helper/converter/editor_to_html_test/index_test.exs @@ -45,6 +45,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML do } {:ok, editor_string} = Jason.encode(editor_json) + {:error, error} = Parser.to_html(editor_string) assert error == [ @@ -114,8 +115,8 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML do {:ok, editor_string} = Jason.encode(editor_json) {:ok, converted} = Parser.to_html(editor_string) - assert converted == - ~s(

evel script

) + assert converted |> String.contains?(~s(
)) + assert converted |> String.contains?(~s(

1_567_250_876_713, @@ -133,8 +134,12 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML do {:ok, editor_string} = Jason.encode(editor_json) {:ok, converted} = Parser.to_html(editor_string) - assert converted == - ~s(

Editor.js is an element <script>evel script</script>

) + assert converted |> String.contains?(~s(
)) + + assert converted + |> String.contains?( + ~s(Editor.js is an element <script>evel script</script>) + ) end end end diff --git a/test/helper/converter/editor_to_html_test/paragraph_test.exs b/test/helper/converter/editor_to_html_test/paragraph_test.exs index a5f2ce506..f69eb121f 100644 --- a/test/helper/converter/editor_to_html_test/paragraph_test.exs +++ b/test/helper/converter/editor_to_html_test/paragraph_test.exs @@ -26,7 +26,9 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Paragraph do {:ok, editor_string} = Jason.encode(@editor_json) {:ok, converted} = Parser.to_html(editor_string) - assert converted == ~s(

paragraph content

) + assert converted |> String.contains?(~s(
)) + assert converted |> String.contains?(~s(

1_567_250_876_713, "blocks" => [ %{ + "id" => id, "type" => "table", "data" => %{ - "id" => id, "columnCount" => column_count, "items" => items } @@ -122,13 +122,13 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.Table do "width" => "180px" } ], - "exist" + "block-id-exist" ) {:ok, editor_string} = Jason.encode(editor_json) {:ok, converted} = Parser.to_html(editor_string) - assert Utils.str_occurence(converted, ~s(id="exist")) == 1 + assert Utils.str_occurence(converted, ~s(id="block-id-exist")) == 1 end test "invalid table field parse should raise error message" do diff --git a/test/helper/converter/md_to_editor_test.exs b/test/helper/converter/md_to_editor_test.exs index ecc23c98d..04530f4a9 100644 --- a/test/helper/converter/md_to_editor_test.exs +++ b/test/helper/converter/md_to_editor_test.exs @@ -231,6 +231,8 @@ defmodule GroupherServer.Test.Helper.Converter.MdToEditor do ] end + @tag :wip + # TODO: inline code parse test "complex ast parser should work" do markdown = """ @@ -249,10 +251,12 @@ defmodule GroupherServer.Test.Helper.Converter.MdToEditor do {:ok, html} = EditorToHTML.to_html(editor_blocks) - viewer_class = @root_class["viewer"] - - assert html == - ~s(

hello

this is a basic markdown text

delete me

italic me

My in-line-code-content is best

) + assert html |> String.contains?(~s(
)) + assert html |> String.contains?(~s(

String.contains?(~s(italic me)) + assert html |> String.contains?(~s(

Date: Wed, 9 Jun 2021 12:07:41 +0800 Subject: [PATCH 03/31] refactor(editor-workflow): editor parse test list case --- test/helper/converter/editor_to_html_test/list_test.exs | 7 ++++--- test/helper/converter/md_to_editor_test.exs | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/helper/converter/editor_to_html_test/list_test.exs b/test/helper/converter/editor_to_html_test/list_test.exs index 07e1bae07..5dc6a8ff7 100644 --- a/test/helper/converter/editor_to_html_test/list_test.exs +++ b/test/helper/converter/editor_to_html_test/list_test.exs @@ -16,9 +16,9 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do "time" => 1_567_250_876_713, "blocks" => [ %{ + "id" => id, "type" => "list", "data" => %{ - "id" => id, "mode" => mode, "items" => items } @@ -105,6 +105,7 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do assert Utils.str_occurence(converted, @class["order_list_prefix"]) == 3 end + @tag :wip test "edit exsit block will not change id value" do editor_json = set_items( @@ -121,13 +122,13 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do "一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。一个带着中文的很长的句子。" } ], - "exsit" + "block-id-exist" ) {:ok, editor_string} = Jason.encode(editor_json) {:ok, converted} = Parser.to_html(editor_string) - assert Utils.str_occurence(converted, "id=\"exsit\"") == 1 + assert Utils.str_occurence(converted, ~s(id="block-id-exist")) == 1 end test "basic checklist parse should work" do diff --git a/test/helper/converter/md_to_editor_test.exs b/test/helper/converter/md_to_editor_test.exs index 04530f4a9..0d0b6a20a 100644 --- a/test/helper/converter/md_to_editor_test.exs +++ b/test/helper/converter/md_to_editor_test.exs @@ -231,7 +231,6 @@ defmodule GroupherServer.Test.Helper.Converter.MdToEditor do ] end - @tag :wip # TODO: inline code parse test "complex ast parser should work" do markdown = """ From ed422a48c6a37b11773e8a4c522132e5542b7436 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 12:55:05 +0800 Subject: [PATCH 04/31] refactor(editor-workflow): add body_html to all articles --- .../cms/delegates/article_curd.ex | 9 ++------ lib/groupher_server/cms/helper/macros.ex | 1 + .../schema/Helper/fields.ex | 1 + .../schema/cms/cms_types.ex | 3 --- lib/helper/validator/schema.ex | 21 ++++++------------- ...210609043242_add_body_html_to_artilces.exs | 15 +++++++++++++ 6 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 priv/repo/migrations/20210609043242_add_body_html_to_artilces.exs diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index 26982e4d2..c243c368f 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -389,13 +389,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do # for create artilce step in Multi.new defp do_create_article(target, attrs, %Author{id: aid}, %Community{id: cid}) do - # {:ok, { body: body, body_html: body_html }} = Convert.body_coverter() - - # body_map = attrs.body |> to_editor_map - # body = body_map |> Jason.encode - # body_html = body_map |> Convert.to_html - - # |> Ecto.Changeset.put_change(:emotions, @default_emotions) + # {:ok, { body: body, body_html: body_html }} = Convert.Article.body_parse + # attrs |> Map.merge(%{body: body, body_html: body_html}) target |> struct() diff --git a/lib/groupher_server/cms/helper/macros.ex b/lib/groupher_server/cms/helper/macros.ex index 5ee406b72..80e1fd391 100644 --- a/lib/groupher_server/cms/helper/macros.ex +++ b/lib/groupher_server/cms/helper/macros.ex @@ -187,6 +187,7 @@ defmodule GroupherServer.CMS.Helper.Macros do quote do field(:title, :string) field(:body, :string) + field(:body_html, :string) field(:digest, :string) belongs_to(:author, Author) diff --git a/lib/groupher_server_web/schema/Helper/fields.ex b/lib/groupher_server_web/schema/Helper/fields.ex index edd51ce39..46d73b3d8 100644 --- a/lib/groupher_server_web/schema/Helper/fields.ex +++ b/lib/groupher_server_web/schema/Helper/fields.ex @@ -19,6 +19,7 @@ defmodule GroupherServerWeb.Schema.Helper.Fields do field(:id, :id) field(:title, :string) field(:body, :string) + field(:body_html, :string) field(:digest, :string) field(:views, :integer) field(:is_pinned, :boolean) diff --git a/lib/groupher_server_web/schema/cms/cms_types.ex b/lib/groupher_server_web/schema/cms/cms_types.ex index 31042e8ec..2ff6bfa30 100644 --- a/lib/groupher_server_web/schema/cms/cms_types.ex +++ b/lib/groupher_server_web/schema/cms/cms_types.ex @@ -61,7 +61,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:length, :integer) field(:link_addr, :string) field(:copy_right, :string) - field(:body, :string) timestamp_fields(:article) end @@ -78,7 +77,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:length, :integer) field(:link_addr, :string) field(:copy_right, :string) - field(:body, :string) timestamp_fields(:article) end @@ -91,7 +89,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do field(:length, :integer) field(:link_addr, :string) - # field(:body, :string) timestamp_fields(:article) end diff --git a/lib/helper/validator/schema.ex b/lib/helper/validator/schema.ex index d30417937..e5cabd944 100644 --- a/lib/helper/validator/schema.ex +++ b/lib/helper/validator/schema.ex @@ -93,33 +93,24 @@ defmodule Helper.Validator.Schema do defp match(field, value, type, [{:min, min} | options]) when type in @support_min and g_not_nil(value) and g_pos_int(min) do case Utils.large_than(value, min) do - true -> - match(field, value, type, options) - - false -> - error(field, value, :min, min) + true -> match(field, value, type, options) + false -> error(field, value, :min, min) end end ## starts_with option for string defp match(field, value, type, [{:starts_with, starts} | options]) when is_binary(value) do case String.starts_with?(value, starts) do - true -> - match(field, value, type, options) - - false -> - error(field, value, :starts_with, starts) + true -> match(field, value, type, options) + false -> error(field, value, :starts_with, starts) end end ## item type for list defp match(field, value, type, [{:type, :map} | options]) when is_list(value) do case Enum.all?(value, &is_map(&1)) do - true -> - match(field, value, type, options) - - false -> - error(field, value, :list_type_map) + true -> match(field, value, type, options) + false -> error(field, value, :list_type_map) end end diff --git a/priv/repo/migrations/20210609043242_add_body_html_to_artilces.exs b/priv/repo/migrations/20210609043242_add_body_html_to_artilces.exs new file mode 100644 index 000000000..a803324fb --- /dev/null +++ b/priv/repo/migrations/20210609043242_add_body_html_to_artilces.exs @@ -0,0 +1,15 @@ +defmodule GroupherServer.Repo.Migrations.AddBodyHtmlToArtilces do + use Ecto.Migration + + def change do + alter(table(:cms_posts), do: modify(:body, :text)) + alter(table(:cms_jobs), do: modify(:body, :text)) + alter(table(:cms_repos), do: modify(:body, :text)) + alter(table(:cms_blogs), do: modify(:body, :text)) + + alter(table(:cms_posts), do: add(:body_html, :text)) + alter(table(:cms_jobs), do: add(:body_html, :text)) + alter(table(:cms_repos), do: add(:body_html, :text)) + alter(table(:cms_blogs), do: add(:body_html, :text)) + end +end From 2bb6c9efd95050d799ea19cc1f3466f559ebb7ae Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 13:10:15 +0800 Subject: [PATCH 05/31] refactor(editor-workflow): adjust body fields to article_comments --- lib/groupher_server/cms/helper/macros.ex | 1 + lib/groupher_server/cms/models/article_comment.ex | 5 +++-- lib/groupher_server_web/schema/cms/cms_types.ex | 1 + .../20210609050608_adjust_body_to_artilce_comments.exs | 8 ++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 priv/repo/migrations/20210609050608_adjust_body_to_artilce_comments.exs diff --git a/lib/groupher_server/cms/helper/macros.ex b/lib/groupher_server/cms/helper/macros.ex index 80e1fd391..9d542d641 100644 --- a/lib/groupher_server/cms/helper/macros.ex +++ b/lib/groupher_server/cms/helper/macros.ex @@ -125,6 +125,7 @@ defmodule GroupherServer.CMS.Helper.Macros do def general_article_fields(:cast) do [ :body, + :body_html, :digest, :original_community_id, :article_comments_count, diff --git a/lib/groupher_server/cms/models/article_comment.ex b/lib/groupher_server/cms/models/article_comment.ex index d75f12380..30bc4b282 100644 --- a/lib/groupher_server/cms/models/article_comment.ex +++ b/lib/groupher_server/cms/models/article_comment.ex @@ -17,8 +17,8 @@ defmodule GroupherServer.CMS.Model.ArticleComment do # alias Helper.HTML @article_threads get_config(:article, :threads) - @required_fields ~w(body_html author_id)a - @optional_fields ~w(reply_to_id replies_count is_folded is_deleted floor is_article_author thread is_for_question is_solution)a + @required_fields ~w(body author_id)a + @optional_fields ~w(body_html reply_to_id replies_count is_folded is_deleted floor is_article_author thread is_for_question is_solution)a @updatable_fields ~w(is_folded is_deleted floor upvotes_count is_pinned is_for_question is_solution)a @article_fields @article_threads |> Enum.map(&:"#{&1}_id") @@ -52,6 +52,7 @@ defmodule GroupherServer.CMS.Model.ArticleComment do belongs_to(:author, User, foreign_key: :author_id) field(:thread, :string) + field(:body, :string) field(:body_html, :string) # 是否被折叠 field(:is_folded, :boolean, default: false) diff --git a/lib/groupher_server_web/schema/cms/cms_types.ex b/lib/groupher_server_web/schema/cms/cms_types.ex index 2ff6bfa30..509a1f1f4 100644 --- a/lib/groupher_server_web/schema/cms/cms_types.ex +++ b/lib/groupher_server_web/schema/cms/cms_types.ex @@ -256,6 +256,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do object :article_comment_reply do field(:id, :id) + field(:body, :string) field(:body_html, :string) field(:author, :user, resolve: dataloader(CMS, :author)) field(:floor, :integer) diff --git a/priv/repo/migrations/20210609050608_adjust_body_to_artilce_comments.exs b/priv/repo/migrations/20210609050608_adjust_body_to_artilce_comments.exs new file mode 100644 index 000000000..2222f24c0 --- /dev/null +++ b/priv/repo/migrations/20210609050608_adjust_body_to_artilce_comments.exs @@ -0,0 +1,8 @@ +defmodule GroupherServer.Repo.Migrations.AdjustBodyToArtilceComments do + use Ecto.Migration + + def change do + alter(table(:articles_comments), do: modify(:body_html, :text)) + alter(table(:articles_comments), do: add(:body, :text)) + end +end From c28990cc5d602300c08b5fd36e367db0a6e051f5 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 13:23:48 +0800 Subject: [PATCH 06/31] refactor(editor-workflow): fix body field when create comment --- .../cms/delegates/article_comment.ex | 21 ++++++++++--------- .../cms/paged_articles/paged_posts_test.exs | 2 +- .../editor_to_html_test/list_test.exs | 1 - 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_comment.ex b/lib/groupher_server/cms/delegates/article_comment.ex index ba1be04c9..089ffe1ef 100644 --- a/lib/groupher_server/cms/delegates/article_comment.ex +++ b/lib/groupher_server/cms/delegates/article_comment.ex @@ -92,13 +92,13 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do @doc """ creates a comment for article like psot, job ... """ - def create_article_comment(thread, article_id, content, %User{} = user) do + def create_article_comment(thread, article_id, body, %User{} = user) do with {:ok, info} <- match(thread), {:ok, article} <- ORM.find(info.model, article_id, preload: [author: :user]), true <- can_comment?(article, user) do Multi.new() |> Multi.run(:create_article_comment, fn _, _ -> - do_create_comment(content, info.foreign_key, article, user) + do_create_comment(body, info.foreign_key, article, user) end) |> Multi.run(:update_article_comments_count, fn _, %{create_article_comment: comment} -> update_article_comments_count(comment, :inc) @@ -133,15 +133,15 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do update a comment for article like psot, job ... """ # 如果是 solution, 那么要更新对应的 post 的 solution_digest - def update_article_comment(%ArticleComment{is_solution: true} = article_comment, content) do + def update_article_comment(%ArticleComment{is_solution: true} = article_comment, body) do with {:ok, post} <- ORM.find(Post, article_comment.post_id) do - post |> ORM.update(%{solution_digest: content}) - article_comment |> ORM.update(%{body_html: content}) + post |> ORM.update(%{solution_digest: body}) + article_comment |> ORM.update(%{body: body, body_html: body}) end end - def update_article_comment(%ArticleComment{} = article_comment, content) do - article_comment |> ORM.update(%{body_html: content}) + def update_article_comment(%ArticleComment{} = article_comment, body) do + article_comment |> ORM.update(%{body: body, body_html: body}) end @doc """ @@ -216,7 +216,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do |> result() end - # add participator to article-like content (Post, Job ...) and update count + # add participator to article-like(Post, Job ...) and update count def add_participator_to_article( %{article_comments_participators: article_comments_participators} = article, %User{} = user @@ -259,7 +259,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do # set floor # TODO: parse editor-json # set default emotions - def do_create_comment(content, foreign_key, article, %User{id: user_id}) do + def do_create_comment(body, foreign_key, article, %User{id: user_id}) do thread = foreign_key |> to_string |> String.split("_id") |> List.first() |> String.upcase() count_query = from(c in ArticleComment, where: field(c, ^foreign_key) == ^article.id) @@ -270,7 +270,8 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do Map.put( %{ author_id: user_id, - body_html: content, + body: body, + body_html: body, emotions: @default_emotions, floor: floor, is_article_author: user_id == article.author.user.id, diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs index 1369c7095..b3cdd125a 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs @@ -315,7 +315,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do } } """ - + @tag :wip test "latest commented post should appear on top", ~m(guest_conn post_last_week user)a do variables = %{filter: %{page: 1, size: 20}} results = guest_conn |> query_result(@query, variables, "pagedPosts") diff --git a/test/helper/converter/editor_to_html_test/list_test.exs b/test/helper/converter/editor_to_html_test/list_test.exs index 5dc6a8ff7..182d163de 100644 --- a/test/helper/converter/editor_to_html_test/list_test.exs +++ b/test/helper/converter/editor_to_html_test/list_test.exs @@ -105,7 +105,6 @@ defmodule GroupherServer.Test.Helper.Converter.EditorToHTML.List do assert Utils.str_occurence(converted, @class["order_list_prefix"]) == 3 end - @tag :wip test "edit exsit block will not change id value" do editor_json = set_items( From afb064ffeb7de0491851e5b4455797d48c0c574e Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 13:36:58 +0800 Subject: [PATCH 07/31] refactor(editor-workflow): fix body field when create comment wip --- lib/groupher_server/cms/models/article_comment.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/groupher_server/cms/models/article_comment.ex b/lib/groupher_server/cms/models/article_comment.ex index 30bc4b282..c0563bb50 100644 --- a/lib/groupher_server/cms/models/article_comment.ex +++ b/lib/groupher_server/cms/models/article_comment.ex @@ -19,7 +19,7 @@ defmodule GroupherServer.CMS.Model.ArticleComment do @required_fields ~w(body author_id)a @optional_fields ~w(body_html reply_to_id replies_count is_folded is_deleted floor is_article_author thread is_for_question is_solution)a - @updatable_fields ~w(is_folded is_deleted floor upvotes_count is_pinned is_for_question is_solution)a + @updatable_fields ~w(body_html is_folded is_deleted floor upvotes_count is_pinned is_for_question is_solution)a @article_fields @article_threads |> Enum.map(&:"#{&1}_id") From 396b251e80dfa153cc6ad6fe2434f703ecf4112f Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 16:16:51 +0800 Subject: [PATCH 08/31] refactor(editor-workflow): wip --- .../cms/delegates/article_curd.ex | 25 +++++---- lib/helper/converter/html_sanitizer.ex | 5 ++ .../cms/articles/post_test.exs | 9 +++ .../cms/paged_articles/paged_posts_test.exs | 1 - test/support/factory.ex | 55 +++++++++++++------ 5 files changed, 64 insertions(+), 31 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index c243c368f..ab858d9fc 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -21,7 +21,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do import Helper.ErrorCode import ShortMaps - alias Helper.{Later, ORM, QueryBuilder} + alias Helper.{Later, ORM, QueryBuilder, Converter} alias GroupherServer.{Accounts, CMS, Delivery, Email, Repo, Statistics} alias Accounts.Model.User @@ -389,17 +389,18 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do # for create artilce step in Multi.new defp do_create_article(target, attrs, %Author{id: aid}, %Community{id: cid}) do - # {:ok, { body: body, body_html: body_html }} = Convert.Article.body_parse - # attrs |> Map.merge(%{body: body, body_html: body_html}) - - target - |> struct() - |> target.changeset(attrs) - |> Ecto.Changeset.put_change(:emotions, @default_emotions) - |> Ecto.Changeset.put_change(:author_id, aid) - |> Ecto.Changeset.put_change(:original_community_id, integerfy(cid)) - |> Ecto.Changeset.put_embed(:meta, @default_article_meta) - |> Repo.insert() + with {:ok, %{body: body, body_html: body_html}} <- Converter.Article.body_parse(attrs.body) do + attrs = attrs |> Map.merge(%{body: body, body_html: body_html}) + + target + |> struct() + |> target.changeset(attrs) + |> Ecto.Changeset.put_change(:emotions, @default_emotions) + |> Ecto.Changeset.put_change(:author_id, aid) + |> Ecto.Changeset.put_change(:original_community_id, integerfy(cid)) + |> Ecto.Changeset.put_embed(:meta, @default_article_meta) + |> Repo.insert() + end end # except Job, other article will just pass, should use set_article_tags function instead diff --git a/lib/helper/converter/html_sanitizer.ex b/lib/helper/converter/html_sanitizer.ex index 9df1640b9..b3996f4ad 100644 --- a/lib/helper/converter/html_sanitizer.ex +++ b/lib/helper/converter/html_sanitizer.ex @@ -103,4 +103,9 @@ defmodule Helper.Converter.HtmlSanitizer do # workarround for https://github.com/rrrene/html_sanitize_ex/issues/48 |> String.replace(" viewbox=\"", " viewBox=\"") end + + @doc """ + strip all html tags + """ + def strip_all_tags(text), do: text |> HtmlSanitizeEx.strip_tags() end diff --git a/test/groupher_server/cms/articles/post_test.exs b/test/groupher_server/cms/articles/post_test.exs index e3668f282..74d22e563 100644 --- a/test/groupher_server/cms/articles/post_test.exs +++ b/test/groupher_server/cms/articles/post_test.exs @@ -4,8 +4,10 @@ defmodule GroupherServer.Test.CMS.Articles.Post do alias Helper.ORM alias GroupherServer.CMS + alias Helper.Converter.EditorToHTML.{Class, Validator} alias CMS.Model.{Author, Community, Post} + @root_class Class.article() @last_year Timex.shift(Timex.beginning_of_year(Timex.now()), days: -3, seconds: -1) setup do @@ -20,12 +22,19 @@ defmodule GroupherServer.Test.CMS.Articles.Post do end describe "[cms post curd]" do + @tag :wip test "can create post with valid attrs", ~m(user community post_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) + IO.inspect(post.body, label: "post created") + IO.inspect(post.body_html, label: "post created2") assert post.title == post_attrs.title + + assert Jason.decode!(post.body) |> Validator.is_valid() + assert post.body_html |> String.contains?(~s(

)) + assert post.body_html |> String.contains?(~s(

query_result(@query, variables, "pagedPosts") diff --git a/test/support/factory.ex b/test/support/factory.ex index b2021d94f..9f604288e 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -28,16 +28,35 @@ defmodule GroupherServer.Support.Factory do @default_article_meta CMS.Model.Embeds.ArticleMeta.default_meta() @default_emotions CMS.Model.Embeds.ArticleCommentEmotion.default_emotions() + # simulate editor.js fmt rich text + defp mock_rich_text() do + content = """ + { + "time": 111, + "blocks": [ + { + "id": "lldjfiek", + "type": "paragraph", + "data": { + "text": "coderplanets is awesome" + } + } + ], + "version": "2.22.0" + } + """ + end + defp mock_meta(:post) do - body = Faker.Lorem.sentence(%Range{first: 80, last: 120}) + text = Faker.Lorem.sentence(%Range{first: 80, last: 120}) %{ meta: @default_article_meta, - title: String.slice(body, 1, 49), - body: body, - digest: String.slice(body, 1, 150), - solution_digest: String.slice(body, 1, 150), - length: String.length(body), + title: String.slice(text, 1, 49), + body: mock_rich_text(), + digest: String.slice(text, 1, 150), + solution_digest: String.slice(text, 1, 150), + length: String.length(text), author: mock(:author), views: Enum.random(0..2000), original_community: mock(:community), @@ -123,16 +142,16 @@ defmodule GroupherServer.Support.Factory do end defp mock_meta(:job) do - body = Faker.Lorem.sentence(%Range{first: 80, last: 120}) + text = Faker.Lorem.sentence(%Range{first: 80, last: 120}) %{ meta: @default_article_meta, - title: String.slice(body, 1, 49), + title: String.slice(text, 1, 49), company: Faker.Company.name(), - body: body, + body: mock_rich_text, desc: "活少, 美女多", - digest: String.slice(body, 1, 150), - length: String.length(body), + digest: String.slice(text, 1, 150), + length: String.length(text), author: mock(:author), views: Enum.random(0..2000), original_community: mock(:community), @@ -145,14 +164,14 @@ defmodule GroupherServer.Support.Factory do end defp mock_meta(:blog) do - body = Faker.Lorem.sentence(%Range{first: 80, last: 120}) + text = Faker.Lorem.sentence(%Range{first: 80, last: 120}) %{ meta: @default_article_meta, - title: String.slice(body, 1, 49), - body: String.slice(body, 1, 49), - digest: String.slice(body, 1, 150), - length: String.length(body), + title: String.slice(text, 1, 49), + body: mock_rich_text, + digest: String.slice(text, 1, 150), + length: String.length(text), author: mock(:author), views: Enum.random(0..2000), original_community: mock(:community), @@ -165,9 +184,9 @@ defmodule GroupherServer.Support.Factory do end defp mock_meta(:comment) do - body = Faker.Lorem.sentence(%Range{first: 30, last: 80}) + # text = Faker.Lorem.sentence(%Range{first: 30, last: 80}) - %{body: body} + %{body: mock_rich_text} end defp mock_meta(:mention) do From 297aa549d614571539444c96c9c152fca19d4417 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 17:20:52 +0800 Subject: [PATCH 09/31] refactor(editor-workflow): post digest workflow --- config/config.exs | 3 +- .../cms/delegates/article_curd.ex | 8 +++-- lib/helper/converter/article.ex | 34 +++++++++++++++---- .../cms/articles/post_test.exs | 14 ++++---- test/helper/converter/article_test.exs | 4 +-- test/support/factory.ex | 8 ++--- 6 files changed, 49 insertions(+), 22 deletions(-) diff --git a/config/config.exs b/config/config.exs index 5eedcd262..f3d93ff86 100644 --- a/config/config.exs +++ b/config/config.exs @@ -96,7 +96,8 @@ config :groupher_server, :article, :confused, :pill, :popcorn - ] + ], + digest_length: 120 config :groupher_server, GroupherServerWeb.Gettext, default_locale: "zh_CN", locales: ~w(en zh_CN) diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index ab858d9fc..77860b7c8 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -389,8 +389,12 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do # for create artilce step in Multi.new defp do_create_article(target, attrs, %Author{id: aid}, %Community{id: cid}) do - with {:ok, %{body: body, body_html: body_html}} <- Converter.Article.body_parse(attrs.body) do - attrs = attrs |> Map.merge(%{body: body, body_html: body_html}) + with {:ok, parsed} <- Converter.Article.parse_body(attrs.body), + {:ok, digest} <- Converter.Article.parse_digest(parsed.body_map) do + attrs = + attrs + |> Map.merge(Map.take(parsed, [:body, :body_html])) + |> Map.merge(%{digest: digest}) target |> struct() diff --git a/lib/helper/converter/article.ex b/lib/helper/converter/article.ex index 87ff9ffa9..c7a47a0eb 100644 --- a/lib/helper/converter/article.ex +++ b/lib/helper/converter/article.ex @@ -2,25 +2,45 @@ defmodule Helper.Converter.Article do @moduledoc """ convert body - {:ok, { body: body, body_html: body_html }} = Converter.Article.body_parse(body) + {:ok, { body: body, body_html: body_html }} = Converter.Article.parse_body(body) """ - import Helper.Utils, only: [done: 1, uid: 0, keys_to_strings: 1] + import Helper.Utils, only: [done: 1, uid: 0, keys_to_strings: 1, get_config: 2] - alias Helper.Converter.EditorToHTML + alias Helper.Converter.{EditorToHTML, HtmlSanitizer} + + @article_digest_length get_config(:article, :digest_length) @doc """ parse article body field """ - @spec body_parse(String.t()) :: {:ok, %{body: Map.t(), body_html: String.t()}} - def body_parse(body) when is_binary(body) do + @spec parse_body(String.t()) :: + {:ok, %{body: String.t(), body_map: Map.t(), body_html: String.t()}} + def parse_body(body) when is_binary(body) do with {:ok, body_map} <- to_editor_map(body), {:ok, body_html} <- EditorToHTML.to_html(body_map), {:ok, body_encode} <- Jason.encode(body_map) do - %{body: body_encode, body_html: body_html} |> done + %{body: body_encode, body_html: body_html, body_map: body_map} |> done end end - def body_parse(_), do: {:error, "wrong body fmt"} + def parse_body(_), do: {:error, "wrong body fmt"} + + @doc """ + parse digest by concat all the paragraph blocks + """ + def parse_digest(%{"blocks" => blocks} = body_map) when is_map(body_map) do + paragraph_blocks = Enum.filter(blocks, &(&1["type"] == "paragraph")) + + Enum.reduce(paragraph_blocks, "", fn block, acc -> + text = block["data"]["text"] |> HtmlSanitizer.strip_all_tags() + acc <> text <> " " + end) + |> String.trim_trailing() + |> String.slice(0, @article_digest_length) + |> done + end + + def parse_digest(_), do: {:ok, "unknow digest"} @doc """ decode article body string to editor map and assign id for each block diff --git a/test/groupher_server/cms/articles/post_test.exs b/test/groupher_server/cms/articles/post_test.exs index 74d22e563..1daae5998 100644 --- a/test/groupher_server/cms/articles/post_test.exs +++ b/test/groupher_server/cms/articles/post_test.exs @@ -3,8 +3,9 @@ defmodule GroupherServer.Test.CMS.Articles.Post do alias Helper.ORM alias GroupherServer.CMS + alias Helper.Converter.{EditorToHTML, HtmlSanitizer} - alias Helper.Converter.EditorToHTML.{Class, Validator} + alias EditorToHTML.{Class, Validator} alias CMS.Model.{Author, Community, Post} @root_class Class.article() @@ -25,16 +26,17 @@ defmodule GroupherServer.Test.CMS.Articles.Post do @tag :wip test "can create post with valid attrs", ~m(user community post_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) - {:ok, post} = CMS.create_article(community, :post, post_attrs, user) - IO.inspect(post.body, label: "post created") - IO.inspect(post.body_html, label: "post created2") - assert post.title == post_attrs.title + body_map = Jason.decode!(post.body) - assert Jason.decode!(post.body) |> Validator.is_valid() + assert post.title == post_attrs.title + assert body_map |> Validator.is_valid() assert post.body_html |> String.contains?(~s(

)) assert post.body_html |> String.contains?(~s(

List.first() |> get_in(["data", "text"]) + assert post.digest == paragraph_text |> HtmlSanitizer.strip_all_tags() end test "created post should have a acitve_at field, same with inserted_at", diff --git a/test/helper/converter/article_test.exs b/test/helper/converter/article_test.exs index ae56e1b5a..9842090c2 100644 --- a/test/helper/converter/article_test.exs +++ b/test/helper/converter/article_test.exs @@ -6,7 +6,7 @@ defmodule GroupherServer.Test.Helper.Converter.Article do alias Helper.Converter.{Article, EditorToHTML} describe "[snaitizer test]" do - test "body_parse should return valid format" do + test "parse_body should return valid format" do body = """ { "time": 11, @@ -23,7 +23,7 @@ defmodule GroupherServer.Test.Helper.Converter.Article do } """ - {:ok, %{body: body, body_html: body_html}} = Article.body_parse(body) + {:ok, %{body: body, body_html: body_html}} = Article.parse_body(body) {:ok, body_map} = Jason.decode(body) assert body_html |> String.contains?("

awesome" } } ], @@ -148,7 +148,7 @@ defmodule GroupherServer.Support.Factory do meta: @default_article_meta, title: String.slice(text, 1, 49), company: Faker.Company.name(), - body: mock_rich_text, + body: mock_rich_text(), desc: "活少, 美女多", digest: String.slice(text, 1, 150), length: String.length(text), @@ -169,7 +169,7 @@ defmodule GroupherServer.Support.Factory do %{ meta: @default_article_meta, title: String.slice(text, 1, 49), - body: mock_rich_text, + body: mock_rich_text(), digest: String.slice(text, 1, 150), length: String.length(text), author: mock(:author), @@ -186,7 +186,7 @@ defmodule GroupherServer.Support.Factory do defp mock_meta(:comment) do # text = Faker.Lorem.sentence(%Range{first: 30, last: 80}) - %{body: mock_rich_text} + %{body: mock_rich_text()} end defp mock_meta(:mention) do From 6b84deec52111f896c3858c2d351b8449a070dc5 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 20:32:48 +0800 Subject: [PATCH 10/31] refactor(editor-workflow): article create workflow --- .../cms/delegates/article_curd.ex | 14 +++++++++++- lib/helper/converter/article.ex | 10 +++++++++ .../cms/articles/blog_test.exs | 21 +++++++++++++----- .../groupher_server/cms/articles/job_test.exs | 22 ++++++++++++++----- .../cms/articles/post_test.exs | 1 - .../cms/articles/repo_test.exs | 11 ++++++++-- 6 files changed, 65 insertions(+), 14 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index 77860b7c8..778937b6c 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -34,6 +34,14 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do @default_emotions Embeds.ArticleEmotion.default_emotions() @default_article_meta Embeds.ArticleMeta.default_meta() + content = """ + { + "time": 2018, + "blocks": [], + "version": "2.22.0" + } + """ + @doc """ read articles for un-logined user """ @@ -389,7 +397,11 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do # for create artilce step in Multi.new defp do_create_article(target, attrs, %Author{id: aid}, %Community{id: cid}) do - with {:ok, parsed} <- Converter.Article.parse_body(attrs.body), + # special article like Repo do not have :body, assign it with default "{}" + default_rich_text = Converter.Article.default_rich_text() + body = Map.get(attrs, :body, default_rich_text) + + with {:ok, parsed} <- Converter.Article.parse_body(body), {:ok, digest} <- Converter.Article.parse_digest(parsed.body_map) do attrs = attrs diff --git a/lib/helper/converter/article.ex b/lib/helper/converter/article.ex index c7a47a0eb..f8651f94d 100644 --- a/lib/helper/converter/article.ex +++ b/lib/helper/converter/article.ex @@ -10,6 +10,16 @@ defmodule Helper.Converter.Article do @article_digest_length get_config(:article, :digest_length) + def default_rich_text() do + """ + { + "time": 2018, + "blocks": [], + "version": "2.22.0" + } + """ + end + @doc """ parse article body field """ diff --git a/test/groupher_server/cms/articles/blog_test.exs b/test/groupher_server/cms/articles/blog_test.exs index 4343c6145..3c02b7400 100644 --- a/test/groupher_server/cms/articles/blog_test.exs +++ b/test/groupher_server/cms/articles/blog_test.exs @@ -2,9 +2,13 @@ defmodule GroupherServer.Test.Articles.Blog do use GroupherServer.TestTools alias GroupherServer.CMS - alias CMS.Model.{Blog, Community} + alias Helper.Converter.{EditorToHTML, HtmlSanitizer} + + alias EditorToHTML.{Class, Validator} + alias CMS.Model.{Author, Blog, Community} alias Helper.ORM + @root_class Class.article() @last_year Timex.shift(Timex.beginning_of_year(Timex.now()), days: -3, seconds: -1) setup do @@ -18,12 +22,19 @@ defmodule GroupherServer.Test.Articles.Blog do end describe "[cms blogs curd]" do - test "can create a blog with valid attrs", ~m(user community blog_attrs)a do + test "can create blog with valid attrs", ~m(user community blog_attrs)a do + assert {:error, _} = ORM.find_by(Author, user_id: user.id) {:ok, blog} = CMS.create_article(community, :blog, blog_attrs, user) - {:ok, found} = ORM.find(Blog, blog.id) - assert found.id == blog.id - assert found.title == blog.title + body_map = Jason.decode!(blog.body) + + assert blog.title == blog_attrs.title + assert body_map |> Validator.is_valid() + assert blog.body_html |> String.contains?(~s(

)) + assert blog.body_html |> String.contains?(~s(

List.first() |> get_in(["data", "text"]) + assert blog.digest == paragraph_text |> HtmlSanitizer.strip_all_tags() end test "created blog should have a acitve_at field, same with inserted_at", diff --git a/test/groupher_server/cms/articles/job_test.exs b/test/groupher_server/cms/articles/job_test.exs index aeac499be..d20c13d8d 100644 --- a/test/groupher_server/cms/articles/job_test.exs +++ b/test/groupher_server/cms/articles/job_test.exs @@ -2,9 +2,14 @@ defmodule GroupherServer.Test.Articles.Job do use GroupherServer.TestTools alias GroupherServer.CMS - alias CMS.Model.{Job, Community} + alias Helper.Converter.{EditorToHTML, HtmlSanitizer} + + alias EditorToHTML.{Class, Validator} + alias CMS.Model.{Author, Job, Community} + alias Helper.ORM + @root_class Class.article() @last_year Timex.shift(Timex.beginning_of_year(Timex.now()), days: -3, seconds: -1) setup do @@ -18,12 +23,19 @@ defmodule GroupherServer.Test.Articles.Job do end describe "[cms jobs curd]" do - test "can create a job with valid attrs", ~m(user community job_attrs)a do + test "can create job with valid attrs", ~m(user community job_attrs)a do + assert {:error, _} = ORM.find_by(Author, user_id: user.id) {:ok, job} = CMS.create_article(community, :job, job_attrs, user) - {:ok, found} = ORM.find(Job, job.id) - assert found.id == job.id - assert found.title == job.title + body_map = Jason.decode!(job.body) + + assert job.title == job_attrs.title + assert body_map |> Validator.is_valid() + assert job.body_html |> String.contains?(~s(

)) + assert job.body_html |> String.contains?(~s(

List.first() |> get_in(["data", "text"]) + assert job.digest == paragraph_text |> HtmlSanitizer.strip_all_tags() end test "created job should have a acitve_at field, same with inserted_at", diff --git a/test/groupher_server/cms/articles/post_test.exs b/test/groupher_server/cms/articles/post_test.exs index 1daae5998..f62ec7dee 100644 --- a/test/groupher_server/cms/articles/post_test.exs +++ b/test/groupher_server/cms/articles/post_test.exs @@ -23,7 +23,6 @@ defmodule GroupherServer.Test.CMS.Articles.Post do end describe "[cms post curd]" do - @tag :wip test "can create post with valid attrs", ~m(user community post_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) diff --git a/test/groupher_server/cms/articles/repo_test.exs b/test/groupher_server/cms/articles/repo_test.exs index 7d07dc3f8..de8f3de3a 100644 --- a/test/groupher_server/cms/articles/repo_test.exs +++ b/test/groupher_server/cms/articles/repo_test.exs @@ -2,10 +2,13 @@ defmodule GroupherServer.Test.Articles.Repo do use GroupherServer.TestTools alias GroupherServer.CMS - alias CMS.Model.{Author, Community, Repo} + alias Helper.Converter.{EditorToHTML} + alias EditorToHTML.{Class, Validator} + alias CMS.Model.{Author, Repo, Community} alias Helper.ORM + @root_class Class.article() @last_year Timex.shift(Timex.beginning_of_year(Timex.now()), days: -3, seconds: -1) setup do @@ -20,12 +23,16 @@ defmodule GroupherServer.Test.Articles.Repo do end describe "[cms repo curd]" do + @tag :wip test "can create repo with valid attrs", ~m(user community repo_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) - {:ok, repo} = CMS.create_article(community, :repo, repo_attrs, user) + body_map = Jason.decode!(repo.body) + assert repo.title == repo_attrs.title + assert body_map |> Validator.is_valid() + assert repo.body_html |> String.contains?(~s(

)) assert repo.contributors |> length !== 0 end From e3d3d8ecc84f84bab211a98a34642d3eaa842fb1 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 21:49:53 +0800 Subject: [PATCH 11/31] refactor(editor-workflow): rich test for comment test wip --- .../cms/delegates/article_comment.ex | 54 ++++---- .../published/published_blogs_test.exs | 2 +- .../published/published_jobs_test.exs | 2 +- .../published/published_posts_test.exs | 2 +- .../published/published_repos_test.exs | 2 +- .../cms/abuse_reports/comment_report_test.exs | 16 +-- .../cms/articles/repo_test.exs | 1 - .../comments/blog_comment_emotions_test.exs | 2 +- .../comments/blog_comment_replies_test.exs | 32 +++-- .../cms/comments/blog_comment_test.exs | 64 +++++----- .../comments/job_comment_emotions_test.exs | 2 +- .../cms/comments/job_comment_replies_test.exs | 22 +++- .../cms/comments/job_comment_test.exs | 118 ++++++++---------- .../comments/post_comment_emotions_test.exs | 4 +- .../comments/post_comment_replies_test.exs | 26 ++-- .../cms/comments/post_comment_test.exs | 109 ++++++++-------- .../comments/repo_comment_emotions_test.exs | 23 ++-- .../comments/repo_comment_replies_test.exs | 32 +++-- .../cms/comments/repo_comment_test.exs | 50 ++++---- .../cms/comments/blog_comment_test.exs | 2 +- .../cms/comments/job_comment_test.exs | 2 +- .../cms/comments/post_comment_test.exs | 14 +-- .../cms/comments/repo_comment_test.exs | 2 +- .../published/published_jobs_test.exs | 2 +- .../published/published_posts_test.exs | 2 +- .../cms/abuse_reports/job_report_test.exs | 4 +- .../cms/abuse_reports/post_report_test.exs | 4 +- .../cms/abuse_reports/repo_report_test.exs | 2 +- .../query/cms/comments/job_comment_test.exs | 38 +++--- .../query/cms/comments/post_comment_test.exs | 38 +++--- .../query/cms/comments/repo_comment_test.exs | 34 +++-- test/support/factory.ex | 20 ++- 32 files changed, 397 insertions(+), 330 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_comment.ex b/lib/groupher_server/cms/delegates/article_comment.ex index 089ffe1ef..408ff04a0 100644 --- a/lib/groupher_server/cms/delegates/article_comment.ex +++ b/lib/groupher_server/cms/delegates/article_comment.ex @@ -11,7 +11,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do import ShortMaps alias Helper.Types, as: T - alias Helper.{ORM, QueryBuilder} + alias Helper.{ORM, QueryBuilder, Converter} alias GroupherServer.{Accounts, CMS, Repo} alias CMS.Model.Post @@ -255,33 +255,27 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do end end - # creat article comment for parent or reply - # set floor - # TODO: parse editor-json - # set default emotions + @doc """ + create article comment for parent or reply + """ def do_create_comment(body, foreign_key, article, %User{id: user_id}) do - thread = foreign_key |> to_string |> String.split("_id") |> List.first() |> String.upcase() - - count_query = from(c in ArticleComment, where: field(c, ^foreign_key) == ^article.id) - floor = Repo.aggregate(count_query, :count) + 1 - - ArticleComment - |> ORM.create( - Map.put( - %{ - author_id: user_id, - body: body, - body_html: body, - emotions: @default_emotions, - floor: floor, - is_article_author: user_id == article.author.user.id, - thread: thread, - meta: @default_comment_meta - }, - foreign_key, - article.id - ) - ) + with {:ok, %{body: body, body_html: body_html}} <- Converter.Article.parse_body(body) do + # e.g: :post_id -> "POST", :job_id -> "JOB" + thread = foreign_key |> to_string |> String.slice(0..-4) |> String.upcase() + + attrs = %{ + author_id: user_id, + body: body, + body_html: body_html, + emotions: @default_emotions, + floor: get_comment_floor(article, foreign_key), + is_article_author: user_id == article.author.user.id, + thread: thread, + meta: @default_comment_meta + } + + ArticleComment |> ORM.create(Map.put(attrs, foreign_key, article.id)) + end end defp do_paged_article_comment(thread, article_id, filters, where_query, user) do @@ -399,6 +393,12 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do {:ok, :pass} end + # get next floor under an article's comments list + defp get_comment_floor(article, foreign_key) do + count_query = from(c in ArticleComment, where: field(c, ^foreign_key) == ^article.id) + Repo.aggregate(count_query, :count) + 1 + end + defp result({:ok, %{set_question_flag_ifneed: result}}), do: {:ok, result} defp result({:ok, %{delete_article_comment: result}}), do: {:ok, result} defp result({:ok, %{mark_solution: result}}), do: {:ok, result} diff --git a/test/groupher_server/accounts/published/published_blogs_test.exs b/test/groupher_server/accounts/published/published_blogs_test.exs index 2ac2b7aed..092a7579b 100644 --- a/test/groupher_server/accounts/published/published_blogs_test.exs +++ b/test/groupher_server/accounts/published/published_blogs_test.exs @@ -76,7 +76,7 @@ defmodule GroupherServer.Test.Accounts.Published.Blog do total_count = 10 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) acc ++ [comment] end) diff --git a/test/groupher_server/accounts/published/published_jobs_test.exs b/test/groupher_server/accounts/published/published_jobs_test.exs index 115c73cf2..770679371 100644 --- a/test/groupher_server/accounts/published/published_jobs_test.exs +++ b/test/groupher_server/accounts/published/published_jobs_test.exs @@ -76,7 +76,7 @@ defmodule GroupherServer.Test.Accounts.Published.Job do total_count = 10 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) acc ++ [comment] end) diff --git a/test/groupher_server/accounts/published/published_posts_test.exs b/test/groupher_server/accounts/published/published_posts_test.exs index 71a899069..2579d0aa4 100644 --- a/test/groupher_server/accounts/published/published_posts_test.exs +++ b/test/groupher_server/accounts/published/published_posts_test.exs @@ -76,7 +76,7 @@ defmodule GroupherServer.Test.Accounts.Published.Post do total_count = 10 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) acc ++ [comment] end) diff --git a/test/groupher_server/accounts/published/published_repos_test.exs b/test/groupher_server/accounts/published/published_repos_test.exs index e72fe3b28..869618fe6 100644 --- a/test/groupher_server/accounts/published/published_repos_test.exs +++ b/test/groupher_server/accounts/published/published_repos_test.exs @@ -76,7 +76,7 @@ defmodule GroupherServer.Test.Accounts.Published.Repo do total_count = 10 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) acc ++ [comment] end) diff --git a/test/groupher_server/cms/abuse_reports/comment_report_test.exs b/test/groupher_server/cms/abuse_reports/comment_report_test.exs index 6ce9610b7..c88ac0e9b 100644 --- a/test/groupher_server/cms/abuse_reports/comment_report_test.exs +++ b/test/groupher_server/cms/abuse_reports/comment_report_test.exs @@ -16,8 +16,8 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do describe "[article comment report/unreport]" do test "report a comment should have a abuse report record", ~m(user post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} {:ok, all_reports} = CMS.paged_reports(filter) @@ -33,9 +33,9 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do test "different user report a comment should have same report with different report cases", ~m(user user2 post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) - {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) - {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user2) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) + {:ok, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user2) filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} {:ok, all_reports} = CMS.paged_reports(filter) @@ -52,9 +52,9 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do end test "same user can not report a comment twice", ~m(user post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) - {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) - assert {:error, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) + assert {:error, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) end end end diff --git a/test/groupher_server/cms/articles/repo_test.exs b/test/groupher_server/cms/articles/repo_test.exs index de8f3de3a..14c9c14e6 100644 --- a/test/groupher_server/cms/articles/repo_test.exs +++ b/test/groupher_server/cms/articles/repo_test.exs @@ -23,7 +23,6 @@ defmodule GroupherServer.Test.Articles.Repo do end describe "[cms repo curd]" do - @tag :wip test "can create repo with valid attrs", ~m(user community repo_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) {:ok, repo} = CMS.create_article(community, :repo, repo_attrs, user) diff --git a/test/groupher_server/cms/comments/blog_comment_emotions_test.exs b/test/groupher_server/cms/comments/blog_comment_emotions_test.exs index 2e2771c84..3eacf1493 100644 --- a/test/groupher_server/cms/comments/blog_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_emotions_test.exs @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentEmotions do all_comment = Enum.reduce(0..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) acc ++ [comment] end) diff --git a/test/groupher_server/cms/comments/blog_comment_replies_test.exs b/test/groupher_server/cms/comments/blog_comment_replies_test.exs index 84a0299c4..4f25d3d82 100644 --- a/test/groupher_server/cms/comments/blog_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_replies_test.exs @@ -65,9 +65,14 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do ~m(blog user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, "parent comment", user) - {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(replyed_comment_1.id, "reply 2", user2) - {:ok, replyed_comment_3} = CMS.reply_article_comment(replyed_comment_2.id, "reply 3", user) + {:ok, replyed_comment_1} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(replyed_comment_1.id, mock_comment(), user2) + + {:ok, replyed_comment_3} = + CMS.reply_article_comment(replyed_comment_2.id, mock_comment(), user) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) @@ -90,9 +95,14 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do ~m(blog user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, "parent comment", user) - {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(replyed_comment_1.id, "reply 2", user2) - {:ok, replyed_comment_3} = CMS.reply_article_comment(replyed_comment_2.id, "reply 3", user) + {:ok, replyed_comment_1} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(replyed_comment_1.id, mock_comment(), user2) + + {:ok, replyed_comment_3} = + CMS.reply_article_comment(replyed_comment_2.id, mock_comment(), user) {:ok, _parent_comment} = ORM.find(ArticleComment, parent_comment.id) @@ -108,7 +118,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do test "comment replies only contains @max_parent_replies_count replies", ~m(blog user)a do total_reply_count = @max_parent_replies_count + 1 - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) reply_comment_list = Enum.reduce(1..total_reply_count, [], fn n, acc -> @@ -128,7 +138,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do end test "replyed user should appear in article comment participators", ~m(blog user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) {:ok, article} = ORM.find(Blog, blog.id) @@ -138,7 +148,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do end test "replies count should inc by 1 after got replyed", ~m(blog user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) assert parent_comment.replies_count === 0 {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) @@ -153,7 +163,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do describe "[paged article comment replies]" do test "can get paged replies of a parent comment", ~m(blog user)a do - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, paged_replies} = CMS.paged_comment_replies(parent_comment.id, %{page: 1, size: 20}) assert is_valid_pagination?(paged_replies, :raw, :empty) @@ -182,7 +192,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do page_number = 1 page_size = 10 - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, "reply_content_1", user) diff --git a/test/groupher_server/cms/comments/blog_comment_test.exs b/test/groupher_server/cms/comments/blog_comment_test.exs index 8ec588d73..1082d883a 100644 --- a/test/groupher_server/cms/comments/blog_comment_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_test.exs @@ -245,7 +245,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do describe "[article comment fold/unfold]" do test "user can fold a comment", ~m(user blog)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert not comment.is_folded @@ -256,7 +256,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "user can unfold a comment", ~m(user blog)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _comment} = CMS.fold_article_comment(comment.id, user) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -270,7 +270,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do describe "[article comment pin/unpin]" do test "user can pin a comment", ~m(user blog)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert not comment.is_pinned @@ -285,7 +285,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "user can unpin a comment", ~m(user blog)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _comment} = CMS.pin_article_comment(comment.id) {:ok, comment} = CMS.undo_pin_article_comment(comment.id) @@ -295,7 +295,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "pinned comments has a limit for each article", ~m(user blog)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) Enum.reduce(0..(@pinned_comment_limit - 1), [], fn _, _acc -> {:ok, _comment} = CMS.pin_article_comment(comment.id) @@ -308,17 +308,17 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do describe "[article comment report/unreport]" do # # test "user can report a comment", ~m(user blog)a do - # {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + # {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) - # {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + # {:ok, comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) # end # # test "user can unreport a comment", ~m(user blog)a do - # {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) - # {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + # {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) + # {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) # {:ok, _comment} = CMS.undo_report_article_comment(comment.id, user) @@ -326,10 +326,10 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do # end test "can undo a report with other user report it too", ~m(user user2 blog)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user2) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user2) filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} {:ok, all_reports} = CMS.paged_reports(filter) @@ -353,13 +353,13 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "report user < @report_threshold_for_fold will not fold comment", ~m(user blog)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) assert not comment.is_folded Enum.reduce(1..(@report_threshold_for_fold - 1), [], fn _, _acc -> {:ok, user} = db_insert(:user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) end) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -367,13 +367,13 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "report user > @report_threshold_for_fold will cause comment fold", ~m(user blog)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) assert not comment.is_folded Enum.reduce(1..(@report_threshold_for_fold + 1), [], fn _, _acc -> {:ok, user} = db_insert(:user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) end) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -394,8 +394,8 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do acc ++ [comment] end) - {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, results} = CMS.paged_article_comments_participators(thread, blog.id, %{page: 1, size: page_size}) @@ -411,7 +411,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) acc ++ [comment] end) @@ -440,7 +440,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do page_size = 5 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) acc ++ [comment] end) @@ -472,7 +472,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do page_size = 5 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) acc ++ [comment] end) @@ -505,7 +505,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) acc ++ [comment] end) @@ -542,7 +542,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do all_folded_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) CMS.fold_article_comment(comment.id, user) acc ++ [comment] @@ -573,7 +573,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) acc ++ [comment] end) @@ -596,11 +596,11 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "delete comment still update article's comments_count field", ~m(user blog)a do - {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, blog} = ORM.find(Blog, blog.id) @@ -617,7 +617,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) acc ++ [comment] end) @@ -634,7 +634,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do describe "[article comment info]" do test "author of the article comment a comment should have flag", ~m(user blog)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) assert not comment.is_article_author author_user = blog.author.user @@ -656,7 +656,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "locked blog can not by reply", ~m(user blog)a do - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) {:ok, _} = CMS.lock_article_comment(:blog, blog.id) diff --git a/test/groupher_server/cms/comments/job_comment_emotions_test.exs b/test/groupher_server/cms/comments/job_comment_emotions_test.exs index 53c674d4f..1fec325ea 100644 --- a/test/groupher_server/cms/comments/job_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/job_comment_emotions_test.exs @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do all_comment = Enum.reduce(0..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) acc ++ [comment] end) diff --git a/test/groupher_server/cms/comments/job_comment_replies_test.exs b/test/groupher_server/cms/comments/job_comment_replies_test.exs index 72c6b55ca..662dad537 100644 --- a/test/groupher_server/cms/comments/job_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/job_comment_replies_test.exs @@ -65,9 +65,14 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do ~m(job user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) - {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(replyed_comment_1.id, "reply 2", user2) - {:ok, replyed_comment_3} = CMS.reply_article_comment(replyed_comment_2.id, "reply 3", user) + {:ok, replyed_comment_1} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(replyed_comment_1.id, mock_comment(), user2) + + {:ok, replyed_comment_3} = + CMS.reply_article_comment(replyed_comment_2.id, mock_comment(), user) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) @@ -90,9 +95,14 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do ~m(job user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) - {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(replyed_comment_1.id, "reply 2", user2) - {:ok, replyed_comment_3} = CMS.reply_article_comment(replyed_comment_2.id, "reply 3", user) + {:ok, replyed_comment_1} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(replyed_comment_1.id, mock_comment(), user2) + + {:ok, replyed_comment_3} = + CMS.reply_article_comment(replyed_comment_2.id, mock_comment(), user) {:ok, _parent_comment} = ORM.find(ArticleComment, parent_comment.id) diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index 0be65e808..ad17e82cc 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -101,7 +101,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do describe "[article comment floor]" do test "comment will have a floor number after created", ~m(user job)a do - {:ok, job_comment} = CMS.create_article_comment(:job, job.id, "comment", user) + {:ok, job_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, job_comment2} = CMS.create_article_comment(:job, job.id, "comment2", user) {:ok, job_comment} = ORM.find(ArticleComment, job_comment.id) @@ -114,9 +114,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do describe "[article comment participator for job]" do test "job will have participator after comment created", ~m(user job)a do - job_comment_1 = "job_comment 1" - - {:ok, _} = CMS.create_article_comment(:job, job.id, job_comment_1, user) + {:ok, _} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, job} = ORM.find(Job, job.id) @@ -125,10 +123,8 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "psot participator will not contains same user", ~m(user job)a do - job_comment_1 = "job_comment 1" - - {:ok, _} = CMS.create_article_comment(:job, job.id, job_comment_1, user) - {:ok, _} = CMS.create_article_comment(:job, job.id, job_comment_1, user) + {:ok, _} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, _} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, job} = ORM.find(Job, job.id) @@ -137,10 +133,8 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do test "recent comment user should appear at first of the psot participators", ~m(user user2 job)a do - job_comment_1 = "job_comment 1" - - {:ok, _} = CMS.create_article_comment(:job, job.id, job_comment_1, user) - {:ok, _} = CMS.create_article_comment(:job, job.id, job_comment_1, user2) + {:ok, _} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, _} = CMS.create_article_comment(:job, job.id, mock_comment(), user2) {:ok, job} = ORM.find(Job, job.id) @@ -152,8 +146,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do describe "[article comment upvotes]" do test "user can upvote a job comment", ~m(user job)a do - comment = "job_comment" - {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) @@ -164,8 +157,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "article author upvote job comment will have flag", ~m(job user)a do - comment = "job_comment" - {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, author_user} = ORM.find(User, job.author.user.id) CMS.upvote_article_comment(comment.id, author_user) @@ -175,8 +167,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "user upvote job comment will add id to upvoted_user_ids", ~m(job user)a do - comment = "job_comment" - {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, comment} = CMS.upvote_article_comment(comment.id, user) assert user.id in comment.meta.upvoted_user_ids @@ -184,8 +175,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do test "user undo upvote job comment will remove id from upvoted_user_ids", ~m(job user user2)a do - comment = "job_comment" - {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, _comment} = CMS.upvote_article_comment(comment.id, user) {:ok, comment} = CMS.upvote_article_comment(comment.id, user2) @@ -199,16 +189,14 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "user upvote a already-upvoted comment fails", ~m(user job)a do - comment = "job_comment" - {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) {:error, _} = CMS.upvote_article_comment(comment.id, user) end test "upvote comment should inc the comment's upvotes_count", ~m(user user2 job)a do - comment = "job_comment" - {:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert comment.upvotes_count == 0 @@ -220,8 +208,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "user can undo upvote a job comment", ~m(user job)a do - content = "job_comment" - {:ok, comment} = CMS.create_article_comment(:job, job.id, content, user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) {:ok, comment} = ORM.find(ArticleComment, comment.id, preload: :upvotes) @@ -232,8 +219,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "user can undo upvote a job comment with no upvote", ~m(user job)a do - content = "job_comment" - {:ok, comment} = CMS.create_article_comment(:job, job.id, content, user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, comment} = CMS.undo_upvote_article_comment(comment.id, user) assert 0 == comment.upvotes_count @@ -244,7 +230,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do describe "[article comment fold/unfold]" do test "user can fold a comment", ~m(user job)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert not comment.is_folded @@ -255,7 +241,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "user can unfold a comment", ~m(user job)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, _comment} = CMS.fold_article_comment(comment.id, user) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -269,7 +255,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do describe "[article comment pin/unpin]" do test "user can pin a comment", ~m(user job)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert not comment.is_pinned @@ -284,7 +270,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "user can unpin a comment", ~m(user job)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, _comment} = CMS.pin_article_comment(comment.id) {:ok, comment} = CMS.undo_pin_article_comment(comment.id) @@ -294,7 +280,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "pinned comments has a limit for each article", ~m(user job)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) Enum.reduce(0..(@pinned_comment_limit - 1), [], fn _, _acc -> {:ok, _comment} = CMS.pin_article_comment(comment.id) @@ -307,17 +293,17 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do describe "[article comment report/unreport]" do # # test "user can report a comment", ~m(user job)a do - # {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + # {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) - # {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + # {:ok, comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) # end # # test "user can unreport a comment", ~m(user job)a do - # {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) - # {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + # {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + # {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) # {:ok, _comment} = CMS.undo_report_article_comment(comment.id, user) @@ -325,10 +311,10 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do # end test "can undo a report with other user report it too", ~m(user user2 job)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user2) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user2) filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} {:ok, all_reports} = CMS.paged_reports(filter) @@ -352,13 +338,13 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "report user < @report_threshold_for_fold will not fold comment", ~m(user job)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) assert not comment.is_folded Enum.reduce(1..(@report_threshold_for_fold - 1), [], fn _, _acc -> {:ok, user} = db_insert(:user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) end) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -366,13 +352,13 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "report user > @report_threshold_for_fold will cause comment fold", ~m(user job)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) assert not comment.is_folded Enum.reduce(1..(@report_threshold_for_fold + 1), [], fn _, _acc -> {:ok, user} = db_insert(:user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) end) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -393,8 +379,8 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do acc ++ [comment] end) - {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, results} = CMS.paged_article_comments_participators(thread, job.id, %{page: 1, size: page_size}) @@ -410,7 +396,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) acc ++ [comment] end) @@ -439,7 +425,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do page_size = 5 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) acc ++ [comment] end) @@ -471,7 +457,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do page_size = 5 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) acc ++ [comment] end) @@ -504,7 +490,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) acc ++ [comment] end) @@ -541,7 +527,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do all_folded_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) CMS.fold_article_comment(comment.id, user) acc ++ [comment] @@ -572,7 +558,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) acc ++ [comment] end) @@ -595,11 +581,11 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "delete comment still update article's comments_count field", ~m(user job)a do - {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, job} = ORM.find(Job, job.id) @@ -616,7 +602,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) acc ++ [comment] end) @@ -633,7 +619,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do describe "[article comment info]" do test "author of the article comment a comment should have flag", ~m(user job)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) assert not comment.is_article_author author_user = job.author.user @@ -644,27 +630,27 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do describe "[lock/unlock job comment]" do test "locked job can not be comment", ~m(user job)a do - {:ok, _} = CMS.create_article_comment(:job, job.id, "comment", user) + {:ok, _} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, _} = CMS.lock_article_comment(:job, job.id) - {:error, reason} = CMS.create_article_comment(:job, job.id, "comment", user) + {:error, reason} = CMS.create_article_comment(:job, job.id, mock_comment(), user) assert reason |> is_error?(:article_comment_locked) {:ok, _} = CMS.undo_lock_article_comment(:job, job.id) - {:ok, _} = CMS.create_article_comment(:job, job.id, "comment", user) + {:ok, _} = CMS.create_article_comment(:job, job.id, mock_comment(), user) end test "locked job can not by reply", ~m(user job)a do - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent_conent", user) - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, _} = CMS.lock_article_comment(:job, job.id) - {:error, reason} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) + {:error, reason} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) assert reason |> is_error?(:article_comment_locked) {:ok, _} = CMS.undo_lock_article_comment(:job, job.id) - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) end end end diff --git a/test/groupher_server/cms/comments/post_comment_emotions_test.exs b/test/groupher_server/cms/comments/post_comment_emotions_test.exs index a4aa2cfb7..6ca936842 100644 --- a/test/groupher_server/cms/comments/post_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/post_comment_emotions_test.exs @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do all_comment = Enum.reduce(0..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) acc ++ [comment] end) @@ -147,7 +147,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do end test "different user can make same emotions on same comment", ~m(post user user2 user3)a do - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :beer, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :beer, user2) diff --git a/test/groupher_server/cms/comments/post_comment_replies_test.exs b/test/groupher_server/cms/comments/post_comment_replies_test.exs index 25dedd971..76d9651a0 100644 --- a/test/groupher_server/cms/comments/post_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/post_comment_replies_test.exs @@ -63,11 +63,16 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do test "reply to reply inside a comment should belong same parent comment", ~m(post user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) - {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(replyed_comment_1.id, "reply 2", user2) - {:ok, replyed_comment_3} = CMS.reply_article_comment(replyed_comment_2.id, "reply 3", user) + {:ok, replyed_comment_1} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(replyed_comment_1.id, mock_comment(), user2) + + {:ok, replyed_comment_3} = + CMS.reply_article_comment(replyed_comment_2.id, mock_comment(), user) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) @@ -88,11 +93,16 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do test "reply to reply inside a comment should have is_reply_to_others flag in meta", ~m(post user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent comment", user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + + {:ok, replyed_comment_1} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(replyed_comment_1.id, mock_comment(), user2) - {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(replyed_comment_1.id, "reply 2", user2) - {:ok, replyed_comment_3} = CMS.reply_article_comment(replyed_comment_2.id, "reply 3", user) + {:ok, replyed_comment_3} = + CMS.reply_article_comment(replyed_comment_2.id, mock_comment(), user) {:ok, _parent_comment} = ORM.find(ArticleComment, parent_comment.id) diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 3f68d7931..771f80cf1 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -26,9 +26,10 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "[basic article comment]" do + @tag :wip test "post are supported by article comment.", ~m(user post)a do - {:ok, post_comment_1} = CMS.create_article_comment(:post, post.id, "post_comment 1", user) - {:ok, post_comment_2} = CMS.create_article_comment(:post, post.id, "post_comment 2", user) + {:ok, post_comment_1} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, post_comment_2} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, post} = ORM.find(Post, post.id, preload: :article_comments) @@ -37,13 +38,13 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "comment should have default meta after create", ~m(user post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta end test "create comment should update active timestamp of post", ~m(user post)a do Process.sleep(1000) - {:ok, _comment} = CMS.create_article_comment(:post, post.id, "post comment", user) + {:ok, _comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, post} = ORM.find(Post, post.id, preload: :article_comments) assert not is_nil(post.active_at) @@ -74,7 +75,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, post} = db_insert(:post, %{inserted_at: inserted_at}) Process.sleep(1000) - {:ok, _comment} = CMS.create_article_comment(:post, post.id, "post comment", user) + {:ok, _comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, post} = ORM.find(Post, post.id) assert post.active_at |> DateTime.to_date() == DateTime.utc_now() |> DateTime.to_date() @@ -85,14 +86,14 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, post} = db_insert(:post, %{inserted_at: inserted_at}) Process.sleep(3000) - {:ok, _comment} = CMS.create_article_comment(:post, post.id, "post comment", user) + {:ok, _comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, post} = ORM.find(Post, post.id) assert post.active_at |> DateTime.to_unix() !== DateTime.utc_now() |> DateTime.to_unix() end test "comment can be updated", ~m(post user)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, updated_comment} = CMS.update_article_comment(comment, "updated content") @@ -102,8 +103,8 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do describe "[article comment floor]" do test "comment will have a floor number after created", ~m(user post)a do - {:ok, post_comment} = CMS.create_article_comment(:post, post.id, "comment", user) - {:ok, post_comment2} = CMS.create_article_comment(:post, post.id, "comment2", user) + {:ok, post_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, post_comment2} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, post_comment} = ORM.find(ArticleComment, post_comment.id) {:ok, post_comment2} = ORM.find(ArticleComment, post_comment2.id) @@ -245,7 +246,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do describe "[article comment fold/unfold]" do test "user can fold a comment", ~m(user post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert not comment.is_folded @@ -256,7 +257,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "user can unfold a comment", ~m(user post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _comment} = CMS.fold_article_comment(comment.id, user) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -270,7 +271,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do describe "[article comment pin/unpin]" do test "user can pin a comment", ~m(user post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert not comment.is_pinned @@ -285,7 +286,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "user can unpin a comment", ~m(user post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _comment} = CMS.pin_article_comment(comment.id) {:ok, comment} = CMS.undo_pin_article_comment(comment.id) @@ -295,7 +296,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "pinned comments has a limit for each article", ~m(user post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) Enum.reduce(0..(@pinned_comment_limit - 1), [], fn _, _acc -> {:ok, _comment} = CMS.pin_article_comment(comment.id) @@ -308,17 +309,17 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do describe "[article comment report/unreport]" do # # test "user can report a comment", ~m(user post)a do - # {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + # {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) - # {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + # {:ok, comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) # end # # test "user can unreport a comment", ~m(user post)a do - # {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) - # {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + # {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + # {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) # {:ok, _comment} = CMS.undo_report_article_comment(comment.id, user) @@ -326,10 +327,10 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do # end test "can undo a report with other user report it too", ~m(user user2 post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user2) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user2) filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} {:ok, all_reports} = CMS.paged_reports(filter) @@ -353,13 +354,13 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "report user < @report_threshold_for_fold will not fold comment", ~m(user post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) assert not comment.is_folded Enum.reduce(1..(@report_threshold_for_fold - 1), [], fn _, _acc -> {:ok, user} = db_insert(:user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) end) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -367,13 +368,13 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "report user > @report_threshold_for_fold will cause comment fold", ~m(user post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) assert not comment.is_folded Enum.reduce(1..(@report_threshold_for_fold + 1), [], fn _, _acc -> {:ok, user} = db_insert(:user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) end) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -394,8 +395,8 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do acc ++ [comment] end) - {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, results} = CMS.paged_article_comments_participators(thread, post.id, %{page: 1, size: page_size}) @@ -411,7 +412,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) acc ++ [comment] end) @@ -440,7 +441,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do page_size = 5 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) acc ++ [comment] end) @@ -472,7 +473,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do page_size = 5 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) acc ++ [comment] end) @@ -505,7 +506,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) acc ++ [comment] end) @@ -542,7 +543,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do all_folded_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) CMS.fold_article_comment(comment.id, user) acc ++ [comment] @@ -573,7 +574,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) acc ++ [comment] end) @@ -596,11 +597,11 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "delete comment still update article's comments_count field", ~m(user post)a do - {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, post} = ORM.find(Post, post.id) @@ -617,7 +618,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) acc ++ [comment] end) @@ -634,7 +635,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do describe "[article comment info]" do test "author of the article comment a comment should have flag", ~m(user post)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) assert not comment.is_article_author author_user = post.author.user @@ -645,14 +646,14 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do describe "[lock/unlock post comment]" do test "locked post can not be comment", ~m(user post)a do - {:ok, _} = CMS.create_article_comment(:post, post.id, "comment", user) + {:ok, _} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.lock_article_comment(:post, post.id) - {:error, reason} = CMS.create_article_comment(:post, post.id, "comment", user) + {:error, reason} = CMS.create_article_comment(:post, post.id, mock_comment(), user) assert reason |> is_error?(:article_comment_locked) {:ok, _} = CMS.undo_lock_article_comment(:post, post.id) - {:ok, _} = CMS.create_article_comment(:post, post.id, "comment", user) + {:ok, _} = CMS.create_article_comment(:post, post.id, mock_comment(), user) end test "locked post can not by reply", ~m(user post)a do @@ -673,7 +674,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do test "create comment for normal post should have default qa flags", ~m(user community)a do post_attrs = mock_attrs(:post, %{community_id: community.id}) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) - {:ok, post_comment} = CMS.create_article_comment(:post, post.id, "comment", user) + {:ok, post_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) assert not post_comment.is_for_question assert not post_comment.is_solution @@ -683,7 +684,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true}) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) - {:ok, post_comment} = CMS.create_article_comment(:post, post.id, "comment", user) + {:ok, post_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) assert post_comment.is_for_question end @@ -692,9 +693,9 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do ~m(user community)a do post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true}) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) - {:ok, comment1} = CMS.create_article_comment(:post, post.id, "comment", user) - {:ok, comment2} = CMS.create_article_comment(:post, post.id, "comment", user) - {:ok, comment3} = CMS.create_article_comment(:post, post.id, "comment", user) + {:ok, comment1} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, comment2} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, comment3} = CMS.create_article_comment(:post, post.id, mock_comment(), user) assert comment1.is_for_question assert comment2.is_for_question @@ -718,7 +719,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) post_author = post.author.user - {:ok, comment} = CMS.create_article_comment(:post, post.id, "comment", post_author) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), post_author) {:ok, comment} = CMS.mark_comment_solution(comment.id, post_author) assert comment.is_solution @@ -736,7 +737,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do post_author = post.author.user {:ok, random_user} = db_insert(:user) - {:ok, comment} = CMS.create_article_comment(:post, post.id, "comment", post_author) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), post_author) {:error, reason} = CMS.mark_comment_solution(comment.id, random_user) reason |> is_error?(:require_questioner) @@ -748,7 +749,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) post_author = post.author.user - {:ok, comment} = CMS.create_article_comment(:post, post.id, "comment", post_author) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), post_author) {:ok, comment} = CMS.mark_comment_solution(comment.id, post_author) {:ok, comment} = CMS.undo_mark_comment_solution(comment.id, post_author) @@ -767,7 +768,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do post_author = post.author.user {:ok, random_user} = db_insert(:user) - {:ok, comment} = CMS.create_article_comment(:post, post.id, "comment", post_author) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), post_author) {:error, reason} = CMS.undo_mark_comment_solution(comment.id, random_user) reason |> is_error?(:require_questioner) @@ -780,8 +781,8 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) post_author = post.author.user - {:ok, comment1} = CMS.create_article_comment(:post, post.id, "comment", post_author) - {:ok, comment2} = CMS.create_article_comment(:post, post.id, "comment", post_author) + {:ok, comment1} = CMS.create_article_comment(:post, post.id, mock_comment(), post_author) + {:ok, comment2} = CMS.create_article_comment(:post, post.id, mock_comment(), post_author) {:ok, _comment} = CMS.mark_comment_solution(comment1.id, post_author) {:ok, comment2} = CMS.mark_comment_solution(comment2.id, post_author) diff --git a/test/groupher_server/cms/comments/repo_comment_emotions_test.exs b/test/groupher_server/cms/comments/repo_comment_emotions_test.exs index b15ac96a5..763db442d 100644 --- a/test/groupher_server/cms/comments/repo_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_emotions_test.exs @@ -28,7 +28,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentEmotions do all_comment = Enum.reduce(0..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) acc ++ [comment] end) @@ -65,9 +65,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentEmotions do describe "[basic article comment emotion]" do test "comment has default emotions after created", ~m(repo user)a do - parent_content = "parent comment" - - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) emotions = parent_comment.emotions |> Map.from_struct() |> Map.delete(:id) @@ -75,8 +73,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentEmotions do end test "can make emotion to comment", ~m(repo user user2)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user2) @@ -89,8 +86,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentEmotions do end test "can undo emotion to comment", ~m(repo user user2)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user2) @@ -111,8 +107,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentEmotions do end test "same user make same emotion to same comment.", ~m(repo user)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) @@ -125,8 +120,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentEmotions do test "same user same emotion to same comment only have one user_emotion record", ~m(repo user)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :heart, user) @@ -147,7 +141,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentEmotions do end test "different user can make same emotions on same comment", ~m(repo user user2 user3)a do - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, "parent comment", user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :beer, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :beer, user2) @@ -163,8 +157,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentEmotions do end test "same user can make differcent emotions on same comment", ~m(repo user)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) diff --git a/test/groupher_server/cms/comments/repo_comment_replies_test.exs b/test/groupher_server/cms/comments/repo_comment_replies_test.exs index 478502970..94a53671c 100644 --- a/test/groupher_server/cms/comments/repo_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_replies_test.exs @@ -23,7 +23,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do parent_content = "parent comment" reply_content = "reply comment" - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, replyed_comment} = CMS.reply_article_comment(parent_comment.id, reply_content, user2) assert replyed_comment.reply_to.id == parent_comment.id @@ -36,7 +36,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do parent_content = "parent comment" reply_content = "reply comment" - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.delete_article_comment(parent_comment) {:error, _} = CMS.reply_article_comment(parent_comment.id, reply_content, user2) @@ -47,7 +47,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do reply_content_1 = "reply comment 1" reply_content_2 = "reply comment 2" - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, reply_content_1, user2) @@ -63,11 +63,16 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do test "reply to reply inside a comment should belong same parent comment", ~m(repo user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, "parent comment", user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(replyed_comment_1.id, "reply 2", user2) - {:ok, replyed_comment_3} = CMS.reply_article_comment(replyed_comment_2.id, "reply 3", user) + {:ok, replyed_comment_1} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(replyed_comment_1.id, mock_comment(), user2) + + {:ok, replyed_comment_3} = + CMS.reply_article_comment(replyed_comment_2.id, mock_comment(), user) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) @@ -88,11 +93,16 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do test "reply to reply inside a comment should have is_reply_to_others flag in meta", ~m(repo user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, "parent comment", user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) + + {:ok, replyed_comment_1} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(replyed_comment_1.id, mock_comment(), user2) - {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(replyed_comment_1.id, "reply 2", user2) - {:ok, replyed_comment_3} = CMS.reply_article_comment(replyed_comment_2.id, "reply 3", user) + {:ok, replyed_comment_3} = + CMS.reply_article_comment(replyed_comment_2.id, mock_comment(), user) {:ok, _parent_comment} = ORM.find(ArticleComment, parent_comment.id) diff --git a/test/groupher_server/cms/comments/repo_comment_test.exs b/test/groupher_server/cms/comments/repo_comment_test.exs index 573b633b7..9210e716a 100644 --- a/test/groupher_server/cms/comments/repo_comment_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_test.exs @@ -245,7 +245,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do describe "[article comment fold/unfold]" do test "user can fold a comment", ~m(user repo)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert not comment.is_folded @@ -256,7 +256,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "user can unfold a comment", ~m(user repo)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _comment} = CMS.fold_article_comment(comment.id, user) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -270,7 +270,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do describe "[article comment pin/unpin]" do test "user can pin a comment", ~m(user repo)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert not comment.is_pinned @@ -285,7 +285,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "user can unpin a comment", ~m(user repo)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _comment} = CMS.pin_article_comment(comment.id) {:ok, comment} = CMS.undo_pin_article_comment(comment.id) @@ -295,7 +295,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "pinned comments has a limit for each article", ~m(user repo)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) Enum.reduce(0..(@pinned_comment_limit - 1), [], fn _, _acc -> {:ok, _comment} = CMS.pin_article_comment(comment.id) @@ -308,17 +308,17 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do describe "[article comment report/unreport]" do # # test "user can report a comment", ~m(user repo)a do - # {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + # {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) - # {:ok, comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + # {:ok, comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) # end # # test "user can unreport a comment", ~m(user repo)a do - # {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) - # {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + # {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) + # {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) # {:ok, comment} = ORM.find(ArticleComment, comment.id) # {:ok, _comment} = CMS.undo_report_article_comment(comment.id, user) @@ -326,10 +326,10 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do # end test "can undo a report with other user report it too", ~m(user user2 repo)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user2) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user2) filter = %{content_type: :article_comment, content_id: comment.id, page: 1, size: 20} {:ok, all_reports} = CMS.paged_reports(filter) @@ -353,13 +353,13 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "report user < @report_threshold_for_fold will not fold comment", ~m(user repo)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) assert not comment.is_folded Enum.reduce(1..(@report_threshold_for_fold - 1), [], fn _, _acc -> {:ok, user} = db_insert(:user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) end) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -367,13 +367,13 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "report user > @report_threshold_for_fold will cause comment fold", ~m(user repo)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) assert not comment.is_folded Enum.reduce(1..(@report_threshold_for_fold + 1), [], fn _, _acc -> {:ok, user} = db_insert(:user) - {:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, _comment} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) end) {:ok, comment} = ORM.find(ArticleComment, comment.id) @@ -411,7 +411,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) acc ++ [comment] end) @@ -440,7 +440,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do page_size = 5 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) acc ++ [comment] end) @@ -472,7 +472,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do page_size = 5 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) acc ++ [comment] end) @@ -505,7 +505,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) acc ++ [comment] end) @@ -542,7 +542,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do all_folded_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) CMS.fold_article_comment(comment.id, user) acc ++ [comment] @@ -573,7 +573,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) acc ++ [comment] end) @@ -598,7 +598,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do test "delete comment still update article's comments_count field", ~m(user repo)a do {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) @@ -617,7 +617,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do all_comments = Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) acc ++ [comment] end) @@ -634,7 +634,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do describe "[article comment info]" do test "author of the article comment a comment should have flag", ~m(user repo)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) assert not comment.is_article_author author_user = repo.author.user diff --git a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs index 94f63e5e6..70244675b 100644 --- a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs @@ -46,7 +46,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do } """ test "login user can reply to a comment", ~m(blog user user_conn)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) variables = %{id: comment.id, content: "reply content"} result = diff --git a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs index 7e581e5d9..7b03eca13 100644 --- a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs @@ -46,7 +46,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } """ test "login user can reply to a comment", ~m(job user user_conn)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) variables = %{id: comment.id, content: "reply content"} result = diff --git a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs index ae12d58b8..f509550ad 100644 --- a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs @@ -46,7 +46,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } """ test "login user can reply to a comment", ~m(post user user_conn)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) variables = %{id: comment.id, content: "reply content"} result = @@ -66,7 +66,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do """ test "only owner can update a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) variables = %{id: comment.id, content: "updated comment"} assert user_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:passport)) @@ -90,7 +90,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do """ test "only owner can delete a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) variables = %{id: comment.id} assert user_conn |> mutation_get_error?(@delete_comment_query, variables, ecode(:passport)) @@ -118,7 +118,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do """ test "login user can upvote a exsit post comment", ~m(post user guest_conn user_conn)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) variables = %{id: comment.id} assert guest_conn @@ -143,7 +143,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do """ test "login user can undo upvote a exsit post comment", ~m(post user guest_conn user_conn)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) variables = %{id: comment.id} user_conn |> mutation_result(@upvote_comment_query, variables, "upvoteArticleComment") @@ -176,7 +176,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } """ test "login user can emotion to a comment", ~m(post user user_conn)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) variables = %{id: comment.id, emotion: "BEER"} comment = @@ -202,7 +202,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } """ test "login user can undo emotion to a comment", ~m(post user owner_conn)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "post comment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) variables = %{id: comment.id, emotion: "BEER"} diff --git a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs index 18d12dcab..0bdfe171b 100644 --- a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs @@ -46,7 +46,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do } """ test "login user can reply to a comment", ~m(repo user user_conn)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) variables = %{id: comment.id, content: "reply content"} result = diff --git a/test/groupher_server_web/query/accounts/published/published_jobs_test.exs b/test/groupher_server_web/query/accounts/published/published_jobs_test.exs index 7da20bf96..3e3f36634 100644 --- a/test/groupher_server_web/query/accounts/published/published_jobs_test.exs +++ b/test/groupher_server_web/query/accounts/published/published_jobs_test.exs @@ -79,7 +79,7 @@ defmodule GroupherServer.Test.Query.Accounts.Published.Jobs do test "user can get paged published comments on job", ~m(guest_conn user job)a do pub_comments = Enum.reduce(1..@publish_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:job, job.id, "comment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) acc ++ [comment] end) diff --git a/test/groupher_server_web/query/accounts/published/published_posts_test.exs b/test/groupher_server_web/query/accounts/published/published_posts_test.exs index 7bf490ad5..3ee2a0557 100644 --- a/test/groupher_server_web/query/accounts/published/published_posts_test.exs +++ b/test/groupher_server_web/query/accounts/published/published_posts_test.exs @@ -79,7 +79,7 @@ defmodule GroupherServer.Test.Query.Accounts.Published.Posts do test "user can get paged published comments on post", ~m(guest_conn user post)a do pub_comments = Enum.reduce(1..@publish_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:post, post.id, "comment", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) acc ++ [comment] end) diff --git a/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs index 794f9c77a..ef3ccb38d 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs @@ -92,8 +92,8 @@ defmodule GroupherServer.Test.Query.AbuseReports.JobReport do end test "support article_comment", ~m(guest_conn job user)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "comment", user) - {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) variables = %{filter: %{content_type: "ARTICLE_COMMENT", page: 1, size: 10}} results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") diff --git a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs index 49cd0a058..8ef2e2a40 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs @@ -92,8 +92,8 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostReport do end test "support article_comment", ~m(guest_conn post user)a do - {:ok, comment} = CMS.create_article_comment(:post, post.id, "comment", user) - {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) variables = %{filter: %{content_type: "ARTICLE_COMMENT", page: 1, size: 10}} results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") diff --git a/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs index 5788c1c17..f03c35c48 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs @@ -93,7 +93,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.RepoReport do test "support article_comment", ~m(guest_conn repo user)a do {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "comment", user) - {:ok, _} = CMS.report_article_comment(comment.id, "reason", "attr", user) + {:ok, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) variables = %{filter: %{content_type: "ARTICLE_COMMENT", page: 1, size: 10}} results = guest_conn |> query_result(@query, variables, "pagedAbuseReports") diff --git a/test/groupher_server_web/query/cms/comments/job_comment_test.exs b/test/groupher_server_web/query/cms/comments/job_comment_test.exs index b4d763d86..d0025dd8e 100644 --- a/test/groupher_server_web/query/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/job_comment_test.exs @@ -133,8 +133,12 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do end) random_comment = all_comments |> Enum.at(Enum.random(0..(total_count - 1))) - {:ok, replyed_comment_1} = CMS.reply_article_comment(random_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(random_comment.id, "reply 2", user2) + + {:ok, replyed_comment_1} = + CMS.reply_article_comment(random_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(random_comment.id, mock_comment(), user2) variables = %{id: job.id, thread: "JOB", filter: %{page: 1, size: page_size}} results = guest_conn |> query_result(@query, variables, "pagedArticleComments") @@ -167,8 +171,11 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do random_comment = all_comments |> Enum.at(Enum.random(0..(total_count - 1))) - {:ok, replyed_comment_1} = CMS.reply_article_comment(random_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(random_comment.id, "reply 2", user2) + {:ok, replyed_comment_1} = + CMS.reply_article_comment(random_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(random_comment.id, mock_comment(), user2) variables = %{ id: job.id, @@ -199,8 +206,11 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent_content", user) - {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(parent_comment.id, "reply 2", user2) + {:ok, replyed_comment_1} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) variables = %{id: job.id, thread: "JOB", filter: %{page: 1, size: 10}, mode: "TIMELINE"} results = guest_conn |> query_result(@query, variables, "pagedArticleComments") @@ -338,16 +348,16 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do thread = :job {:ok, comment} = CMS.create_article_comment(thread, job.id, "parent comment 1", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, "reply 1", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, "reply 2", user2) + {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user2) Process.sleep(1000) {:ok, comment2} = CMS.create_article_comment(thread, job.id, "test comment 2", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, "reply 1", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, "reply 2", user2) + {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, mock_comment(), user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, mock_comment(), user2) Process.sleep(1000) {:ok, comment3} = CMS.create_article_comment(thread, job.id, "test comment 3", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, "reply 1", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, "reply 2", user2) + {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, mock_comment(), user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, mock_comment(), user2) variables = %{ id: job.id, @@ -554,8 +564,8 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do acc ++ [comment] end) - {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) variables = %{id: job.id, thread: thread, filter: %{page: 1, size: page_size}} diff --git a/test/groupher_server_web/query/cms/comments/post_comment_test.exs b/test/groupher_server_web/query/cms/comments/post_comment_test.exs index 941b7bd7c..6b2235d01 100644 --- a/test/groupher_server_web/query/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/post_comment_test.exs @@ -136,8 +136,12 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do end) random_comment = all_comments |> Enum.at(Enum.random(0..(total_count - 1))) - {:ok, replyed_comment_1} = CMS.reply_article_comment(random_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(random_comment.id, "reply 2", user2) + + {:ok, replyed_comment_1} = + CMS.reply_article_comment(random_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(random_comment.id, mock_comment(), user2) variables = %{id: post.id, thread: "POST", filter: %{page: 1, size: page_size}} results = guest_conn |> query_result(@query, variables, "pagedArticleComments") @@ -170,8 +174,11 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do random_comment = all_comments |> Enum.at(Enum.random(0..(total_count - 1))) - {:ok, replyed_comment_1} = CMS.reply_article_comment(random_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(random_comment.id, "reply 2", user2) + {:ok, replyed_comment_1} = + CMS.reply_article_comment(random_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(random_comment.id, mock_comment(), user2) variables = %{ id: post.id, @@ -202,8 +209,11 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_content", user) - {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(parent_comment.id, "reply 2", user2) + {:ok, replyed_comment_1} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) variables = %{id: post.id, thread: "POST", filter: %{page: 1, size: 10}, mode: "TIMELINE"} results = guest_conn |> query_result(@query, variables, "pagedArticleComments") @@ -379,16 +389,16 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do thread = :post {:ok, comment} = CMS.create_article_comment(thread, post.id, "parent comment 1", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, "reply 1", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, "reply 2", user2) + {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user2) Process.sleep(1000) {:ok, comment2} = CMS.create_article_comment(thread, post.id, "test comment 2", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, "reply 1", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, "reply 2", user2) + {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, mock_comment(), user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, mock_comment(), user2) Process.sleep(1000) {:ok, comment3} = CMS.create_article_comment(thread, post.id, "test comment 3", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, "reply 1", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, "reply 2", user2) + {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, mock_comment(), user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, mock_comment(), user2) variables = %{ id: post.id, @@ -595,8 +605,8 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do acc ++ [comment] end) - {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:post, post.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) variables = %{id: post.id, thread: thread, filter: %{page: 1, size: page_size}} diff --git a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs index 83e6abf4d..c911d1dff 100644 --- a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs @@ -131,8 +131,12 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do end) random_comment = all_comments |> Enum.at(Enum.random(0..(total_count - 1))) - {:ok, replyed_comment_1} = CMS.reply_article_comment(random_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(random_comment.id, "reply 2", user2) + + {:ok, replyed_comment_1} = + CMS.reply_article_comment(random_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(random_comment.id, mock_comment(), user2) variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: page_size}} results = guest_conn |> query_result(@query, variables, "pagedArticleComments") @@ -165,8 +169,11 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do random_comment = all_comments |> Enum.at(Enum.random(0..(total_count - 1))) - {:ok, replyed_comment_1} = CMS.reply_article_comment(random_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(random_comment.id, "reply 2", user2) + {:ok, replyed_comment_1} = + CMS.reply_article_comment(random_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(random_comment.id, mock_comment(), user2) variables = %{ id: repo.id, @@ -197,8 +204,11 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, "parent_content", user) - {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, "reply 1", user2) - {:ok, replyed_comment_2} = CMS.reply_article_comment(parent_comment.id, "reply 2", user2) + {:ok, replyed_comment_1} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) + + {:ok, replyed_comment_2} = + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: 10}, mode: "TIMELINE"} results = guest_conn |> query_result(@query, variables, "pagedArticleComments") @@ -336,16 +346,16 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do thread = :repo {:ok, comment} = CMS.create_article_comment(thread, repo.id, "parent comment 1", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, "reply 1", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, "reply 2", user2) + {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user2) Process.sleep(1000) {:ok, comment2} = CMS.create_article_comment(thread, repo.id, "test comment 2", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, "reply 1", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, "reply 2", user2) + {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, mock_comment(), user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, mock_comment(), user2) Process.sleep(1000) {:ok, comment3} = CMS.create_article_comment(thread, repo.id, "test comment 3", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, "reply 1", user) - {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, "reply 2", user2) + {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, mock_comment(), user) + {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, mock_comment(), user2) variables = %{ id: repo.id, diff --git a/test/support/factory.ex b/test/support/factory.ex index 6036cd6e7..f03f14db2 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -28,9 +28,27 @@ defmodule GroupherServer.Support.Factory do @default_article_meta CMS.Model.Embeds.ArticleMeta.default_meta() @default_emotions CMS.Model.Embeds.ArticleCommentEmotion.default_emotions() + def mock_comment(text \\ "comment") do + """ + { + "time": 111, + "blocks": [ + { + "id": "lldjfiek", + "type": "paragraph", + "data": { + "text": "#{text}" + } + } + ], + "version": "2.22.0" + } + """ + end + # simulate editor.js fmt rich text defp mock_rich_text() do - content = """ + """ { "time": 111, "blocks": [ From a6e21f218561fbf45dd634bbfc396f0241f2a6bf Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 21:58:22 +0800 Subject: [PATCH 12/31] refactor(editor-workflow): rich test for comment test wip --- .../comments/blog_comment_replies_test.exs | 8 ++-- .../cms/comments/blog_comment_test.exs | 16 +++---- .../cms/comments/job_comment_replies_test.exs | 18 ++++---- .../cms/comments/job_comment_test.exs | 18 ++++---- .../comments/post_comment_replies_test.exs | 8 ++-- .../cms/comments/post_comment_test.exs | 10 ++--- .../comments/repo_comment_replies_test.exs | 18 ++++---- .../cms/comments/repo_comment_test.exs | 44 +++++++++---------- .../cms/comments/job_comment_test.exs | 12 ++--- .../cms/comments/post_comment_test.exs | 8 ++-- .../cms/comments/repo_comment_test.exs | 12 ++--- .../published/published_blogs_test.exs | 2 +- .../published/published_repos_test.exs | 2 +- .../cms/abuse_reports/repo_report_test.exs | 2 +- .../query/cms/comments/job_comment_test.exs | 24 +++++----- .../query/cms/comments/post_comment_test.exs | 30 ++++++------- .../query/cms/comments/repo_comment_test.exs | 28 ++++++------ .../cms/paged_articles/paged_jobs_test.exs | 4 +- .../cms/paged_articles/paged_posts_test.exs | 4 +- .../cms/paged_articles/paged_repos_test.exs | 4 +- 20 files changed, 136 insertions(+), 136 deletions(-) diff --git a/test/groupher_server/cms/comments/blog_comment_replies_test.exs b/test/groupher_server/cms/comments/blog_comment_replies_test.exs index 4f25d3d82..8b880c93f 100644 --- a/test/groupher_server/cms/comments/blog_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_replies_test.exs @@ -139,7 +139,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do test "replyed user should appear in article comment participators", ~m(blog user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, article} = ORM.find(Blog, blog.id) @@ -151,11 +151,11 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) assert parent_comment.replies_count === 0 - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) assert parent_comment.replies_count === 1 - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) assert parent_comment.replies_count === 2 end @@ -194,7 +194,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) - {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, "reply_content_1", user) + {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, reply_comment2} = CMS.reply_article_comment(parent_comment.id, "reply_content_2", user) diff --git a/test/groupher_server/cms/comments/blog_comment_test.exs b/test/groupher_server/cms/comments/blog_comment_test.exs index 1082d883a..3cbf56e96 100644 --- a/test/groupher_server/cms/comments/blog_comment_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_test.exs @@ -102,7 +102,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do describe "[article comment floor]" do test "comment will have a floor number after created", ~m(user blog)a do - {:ok, blog_comment} = CMS.create_article_comment(:blog, blog.id, "comment", user) + {:ok, blog_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, blog_comment2} = CMS.create_article_comment(:blog, blog.id, "comment2", user) {:ok, blog_comment} = ORM.find(ArticleComment, blog_comment.id) @@ -445,8 +445,8 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do acc ++ [comment] end) - {:ok, random_comment_1} = CMS.create_article_comment(:blog, blog.id, "pin commment", user) - {:ok, random_comment_2} = CMS.create_article_comment(:blog, blog.id, "pin commment2", user) + {:ok, random_comment_1} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) + {:ok, random_comment_2} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, pined_comment_1} = CMS.pin_article_comment(random_comment_1.id) {:ok, pined_comment_2} = CMS.pin_article_comment(random_comment_2.id) @@ -477,8 +477,8 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do acc ++ [comment] end) - {:ok, random_comment_1} = CMS.create_article_comment(:blog, blog.id, "pin commment", user) - {:ok, random_comment_2} = CMS.create_article_comment(:blog, blog.id, "pin commment2", user) + {:ok, random_comment_1} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) + {:ok, random_comment_2} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, pined_comment_1} = CMS.pin_article_comment(random_comment_1.id) {:ok, pined_comment_2} = CMS.pin_article_comment(random_comment_2.id) @@ -645,14 +645,14 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do describe "[lock/unlock blog comment]" do test "locked blog can not be comment", ~m(user blog)a do - {:ok, _} = CMS.create_article_comment(:blog, blog.id, "comment", user) + {:ok, _} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _} = CMS.lock_article_comment(:blog, blog.id) - {:error, reason} = CMS.create_article_comment(:blog, blog.id, "comment", user) + {:error, reason} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) assert reason |> is_error?(:article_comment_locked) {:ok, _} = CMS.undo_lock_article_comment(:blog, blog.id) - {:ok, _} = CMS.create_article_comment(:blog, blog.id, "comment", user) + {:ok, _} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) end test "locked blog can not by reply", ~m(user blog)a do diff --git a/test/groupher_server/cms/comments/job_comment_replies_test.exs b/test/groupher_server/cms/comments/job_comment_replies_test.exs index 662dad537..337aa9877 100644 --- a/test/groupher_server/cms/comments/job_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/job_comment_replies_test.exs @@ -118,7 +118,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do test "comment replies only contains @max_parent_replies_count replies", ~m(job user)a do total_reply_count = @max_parent_replies_count + 1 - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) reply_comment_list = Enum.reduce(1..total_reply_count, [], fn n, acc -> @@ -138,8 +138,8 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do end test "replyed user should appear in article comment participators", ~m(job user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent_conent", user) - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, article} = ORM.find(Job, job.id) @@ -148,14 +148,14 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do end test "replies count should inc by 1 after got replyed", ~m(job user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) assert parent_comment.replies_count === 0 - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) assert parent_comment.replies_count === 1 - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) assert parent_comment.replies_count === 2 end @@ -163,7 +163,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do describe "[paged article comment replies]" do test "can get paged replies of a parent comment", ~m(job user)a do - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, paged_replies} = CMS.paged_comment_replies(parent_comment.id, %{page: 1, size: 20}) assert is_valid_pagination?(paged_replies, :raw, :empty) @@ -192,9 +192,9 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do page_number = 1 page_size = 10 - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) - {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, "reply_content_1", user) + {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, reply_comment2} = CMS.reply_article_comment(parent_comment.id, "reply_content_2", user) diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index ad17e82cc..548358435 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -37,13 +37,13 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do end test "comment should have default meta after create", ~m(user job)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta end test "create comment should update active timestamp of job", ~m(user job)a do Process.sleep(1000) - {:ok, _comment} = CMS.create_article_comment(:job, job.id, "job comment", user) + {:ok, _comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, job} = ORM.find(Job, job.id, preload: :article_comments) assert not is_nil(job.active_at) @@ -73,7 +73,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do {:ok, job} = db_insert(:job, %{inserted_at: inserted_at}) Process.sleep(1000) - {:ok, _comment} = CMS.create_article_comment(:job, job.id, "job comment", user) + {:ok, _comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, job} = ORM.find(Job, job.id) assert job.active_at |> DateTime.to_date() == DateTime.utc_now() |> DateTime.to_date() @@ -84,14 +84,14 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do {:ok, job} = db_insert(:job, %{inserted_at: inserted_at}) Process.sleep(3000) - {:ok, _comment} = CMS.create_article_comment(:job, job.id, "job comment", user) + {:ok, _comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, job} = ORM.find(Job, job.id) assert job.active_at |> DateTime.to_unix() !== DateTime.utc_now() |> DateTime.to_unix() end test "comment can be updated", ~m(job user)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, updated_comment} = CMS.update_article_comment(comment, "updated content") @@ -430,8 +430,8 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do acc ++ [comment] end) - {:ok, random_comment_1} = CMS.create_article_comment(:job, job.id, "pin commment", user) - {:ok, random_comment_2} = CMS.create_article_comment(:job, job.id, "pin commment2", user) + {:ok, random_comment_1} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, random_comment_2} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, pined_comment_1} = CMS.pin_article_comment(random_comment_1.id) {:ok, pined_comment_2} = CMS.pin_article_comment(random_comment_2.id) @@ -462,8 +462,8 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do acc ++ [comment] end) - {:ok, random_comment_1} = CMS.create_article_comment(:job, job.id, "pin commment", user) - {:ok, random_comment_2} = CMS.create_article_comment(:job, job.id, "pin commment2", user) + {:ok, random_comment_1} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, random_comment_2} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, pined_comment_1} = CMS.pin_article_comment(random_comment_1.id) {:ok, pined_comment_2} = CMS.pin_article_comment(random_comment_2.id) diff --git a/test/groupher_server/cms/comments/post_comment_replies_test.exs b/test/groupher_server/cms/comments/post_comment_replies_test.exs index 76d9651a0..f02ecdacf 100644 --- a/test/groupher_server/cms/comments/post_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/post_comment_replies_test.exs @@ -139,7 +139,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do test "replyed user should appear in article comment participators", ~m(post user user2)a do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, article} = ORM.find(Post, post.id) @@ -151,11 +151,11 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) assert parent_comment.replies_count === 0 - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) assert parent_comment.replies_count === 1 - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) assert parent_comment.replies_count === 2 end @@ -194,7 +194,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) - {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, "reply_content_1", user) + {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, reply_comment2} = CMS.reply_article_comment(parent_comment.id, "reply_content_2", user) diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 771f80cf1..ae81009c9 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -446,8 +446,8 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do acc ++ [comment] end) - {:ok, random_comment_1} = CMS.create_article_comment(:post, post.id, "pin commment", user) - {:ok, random_comment_2} = CMS.create_article_comment(:post, post.id, "pin commment2", user) + {:ok, random_comment_1} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, random_comment_2} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, pined_comment_1} = CMS.pin_article_comment(random_comment_1.id) {:ok, pined_comment_2} = CMS.pin_article_comment(random_comment_2.id) @@ -478,8 +478,8 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do acc ++ [comment] end) - {:ok, random_comment_1} = CMS.create_article_comment(:post, post.id, "pin commment", user) - {:ok, random_comment_2} = CMS.create_article_comment(:post, post.id, "pin commment2", user) + {:ok, random_comment_1} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, random_comment_2} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, pined_comment_1} = CMS.pin_article_comment(random_comment_1.id) {:ok, pined_comment_2} = CMS.pin_article_comment(random_comment_2.id) @@ -802,7 +802,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) post_author = post.author.user - {:ok, comment} = CMS.create_article_comment(:post, post.id, "solution", post_author) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), post_author) {:ok, comment} = CMS.mark_comment_solution(comment.id, post_author) {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) diff --git a/test/groupher_server/cms/comments/repo_comment_replies_test.exs b/test/groupher_server/cms/comments/repo_comment_replies_test.exs index 94a53671c..a24281fe5 100644 --- a/test/groupher_server/cms/comments/repo_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_replies_test.exs @@ -118,7 +118,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do test "comment replies only contains @max_parent_replies_count replies", ~m(repo user)a do total_reply_count = @max_parent_replies_count + 1 - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) reply_comment_list = Enum.reduce(1..total_reply_count, [], fn n, acc -> @@ -138,8 +138,8 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do end test "replyed user should appear in article comment participators", ~m(repo user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, "parent_conent", user) - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, article} = ORM.find(Repo, repo.id) @@ -148,14 +148,14 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do end test "replies count should inc by 1 after got replyed", ~m(repo user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) assert parent_comment.replies_count === 0 - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) assert parent_comment.replies_count === 1 - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user2) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) assert parent_comment.replies_count === 2 end @@ -163,7 +163,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do describe "[paged article comment replies]" do test "can get paged replies of a parent comment", ~m(repo user)a do - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, paged_replies} = CMS.paged_comment_replies(parent_comment.id, %{page: 1, size: 20}) assert is_valid_pagination?(paged_replies, :raw, :empty) @@ -192,9 +192,9 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do page_number = 1 page_size = 10 - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, "reply_content_1", user) + {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, reply_comment2} = CMS.reply_article_comment(parent_comment.id, "reply_content_2", user) diff --git a/test/groupher_server/cms/comments/repo_comment_test.exs b/test/groupher_server/cms/comments/repo_comment_test.exs index 9210e716a..8ce9068e9 100644 --- a/test/groupher_server/cms/comments/repo_comment_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_test.exs @@ -27,8 +27,8 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do describe "[basic article comment]" do test "repo are supported by article comment.", ~m(user repo)a do - {:ok, repo_comment_1} = CMS.create_article_comment(:repo, repo.id, "repo_comment 1", user) - {:ok, repo_comment_2} = CMS.create_article_comment(:repo, repo.id, "repo_comment 2", user) + {:ok, repo_comment_1} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) + {:ok, repo_comment_2} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, repo} = ORM.find(Repo, repo.id, preload: :article_comments) @@ -37,13 +37,13 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "comment should have default meta after create", ~m(user repo)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta end test "create comment should update active timestamp of repo", ~m(user repo)a do Process.sleep(1000) - {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, repo} = ORM.find(Repo, repo.id, preload: :article_comments) assert not is_nil(repo.active_at) @@ -74,7 +74,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do {:ok, repo} = db_insert(:repo, %{inserted_at: inserted_at}) Process.sleep(1000) - {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, repo} = ORM.find(Repo, repo.id) assert repo.active_at |> DateTime.to_date() == DateTime.utc_now() |> DateTime.to_date() @@ -85,14 +85,14 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do {:ok, repo} = db_insert(:repo, %{inserted_at: inserted_at}) Process.sleep(3000) - {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, repo} = ORM.find(Repo, repo.id) assert repo.active_at |> DateTime.to_unix() !== DateTime.utc_now() |> DateTime.to_unix() end test "comment can be updated", ~m(repo user)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, updated_comment} = CMS.update_article_comment(comment, "updated content") @@ -102,7 +102,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do describe "[article comment floor]" do test "comment will have a floor number after created", ~m(user repo)a do - {:ok, repo_comment} = CMS.create_article_comment(:repo, repo.id, "comment", user) + {:ok, repo_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, repo_comment2} = CMS.create_article_comment(:repo, repo.id, "comment2", user) {:ok, repo_comment} = ORM.find(ArticleComment, repo_comment.id) @@ -394,8 +394,8 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do acc ++ [comment] end) - {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, results} = CMS.paged_article_comments_participators(thread, repo.id, %{page: 1, size: page_size}) @@ -445,8 +445,8 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do acc ++ [comment] end) - {:ok, random_comment_1} = CMS.create_article_comment(:repo, repo.id, "pin commment", user) - {:ok, random_comment_2} = CMS.create_article_comment(:repo, repo.id, "pin commment2", user) + {:ok, random_comment_1} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) + {:ok, random_comment_2} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, pined_comment_1} = CMS.pin_article_comment(random_comment_1.id) {:ok, pined_comment_2} = CMS.pin_article_comment(random_comment_2.id) @@ -477,8 +477,8 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do acc ++ [comment] end) - {:ok, random_comment_1} = CMS.create_article_comment(:repo, repo.id, "pin commment", user) - {:ok, random_comment_2} = CMS.create_article_comment(:repo, repo.id, "pin commment2", user) + {:ok, random_comment_1} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) + {:ok, random_comment_2} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, pined_comment_1} = CMS.pin_article_comment(random_comment_1.id) {:ok, pined_comment_2} = CMS.pin_article_comment(random_comment_2.id) @@ -596,11 +596,11 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "delete comment still update article's comments_count field", ~m(user repo)a do - {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, repo} = ORM.find(Repo, repo.id) @@ -645,18 +645,18 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do describe "[lock/unlock repo comment]" do test "locked repo can not be comment", ~m(user repo)a do - {:ok, _} = CMS.create_article_comment(:repo, repo.id, "comment", user) + {:ok, _} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.lock_article_comment(:repo, repo.id) - {:error, reason} = CMS.create_article_comment(:repo, repo.id, "comment", user) + {:error, reason} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) assert reason |> is_error?(:article_comment_locked) {:ok, _} = CMS.undo_lock_article_comment(:repo, repo.id) - {:ok, _} = CMS.create_article_comment(:repo, repo.id, "comment", user) + {:ok, _} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) end test "locked repo can not by reply", ~m(user repo)a do - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) {:ok, _} = CMS.lock_article_comment(:repo, repo.id) diff --git a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs index 7b03eca13..de4e66019 100644 --- a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs @@ -66,7 +66,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do """ test "only owner can update a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) variables = %{id: comment.id, content: "updated comment"} assert user_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:passport)) @@ -90,7 +90,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do """ test "only owner can delete a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) variables = %{id: comment.id} assert user_conn |> mutation_get_error?(@delete_comment_query, variables, ecode(:passport)) @@ -118,7 +118,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do """ test "login user can upvote a exsit job comment", ~m(job user guest_conn user_conn)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) variables = %{id: comment.id} assert guest_conn @@ -143,7 +143,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do """ test "login user can undo upvote a exsit job comment", ~m(job user guest_conn user_conn)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) variables = %{id: comment.id} user_conn |> mutation_result(@upvote_comment_query, variables, "upvoteArticleComment") @@ -176,7 +176,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } """ test "login user can emotion to a comment", ~m(job user user_conn)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) variables = %{id: comment.id, emotion: "BEER"} comment = @@ -202,7 +202,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } """ test "login user can undo emotion to a comment", ~m(job user owner_conn)a do - {:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) variables = %{id: comment.id, emotion: "BEER"} diff --git a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs index f509550ad..5a0ad64ec 100644 --- a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs @@ -288,7 +288,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do test "questioner can mark a post comment as solution", ~m(post)a do {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) post_author = post.author.user - {:ok, comment} = CMS.create_article_comment(:post, post.id, "solution", post_author) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), post_author) questioner_conn = simu_conn(:user, post_author) @@ -303,7 +303,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do test "other user can not mark a post comment as solution", ~m(guest_conn user_conn post)a do {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) post_author = post.author.user - {:ok, comment} = CMS.create_article_comment(:post, post.id, "solution", post_author) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), post_author) variables = %{id: comment.id} assert user_conn |> mutation_get_error?(@query, variables, ecode(:require_questioner)) @@ -323,7 +323,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do test "questioner can undo mark a post comment as solution", ~m(post)a do {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) post_author = post.author.user - {:ok, comment} = CMS.create_article_comment(:post, post.id, "solution", post_author) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), post_author) {:ok, comment} = CMS.mark_comment_solution(comment.id, post_author) questioner_conn = simu_conn(:user, post_author) @@ -339,7 +339,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do ~m(guest_conn user_conn post)a do {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) post_author = post.author.user - {:ok, comment} = CMS.create_article_comment(:post, post.id, "solution", post_author) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), post_author) variables = %{id: comment.id} assert user_conn |> mutation_get_error?(@query, variables, ecode(:require_questioner)) diff --git a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs index 0bdfe171b..db14fbf22 100644 --- a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs @@ -66,7 +66,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do """ test "only owner can update a exsit comment", ~m(repo user guest_conn user_conn owner_conn)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) variables = %{id: comment.id, content: "updated comment"} assert user_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:passport)) @@ -90,7 +90,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do """ test "only owner can delete a exsit comment", ~m(repo user guest_conn user_conn owner_conn)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) variables = %{id: comment.id} assert user_conn |> mutation_get_error?(@delete_comment_query, variables, ecode(:passport)) @@ -118,7 +118,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do """ test "login user can upvote a exsit repo comment", ~m(repo user guest_conn user_conn)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) variables = %{id: comment.id} assert guest_conn @@ -143,7 +143,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do """ test "login user can undo upvote a exsit repo comment", ~m(repo user guest_conn user_conn)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) variables = %{id: comment.id} user_conn |> mutation_result(@upvote_comment_query, variables, "upvoteArticleComment") @@ -176,7 +176,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do } """ test "login user can emotion to a comment", ~m(repo user user_conn)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) variables = %{id: comment.id, emotion: "BEER"} comment = @@ -202,7 +202,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do } """ test "login user can undo emotion to a comment", ~m(repo user owner_conn)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "repo comment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) variables = %{id: comment.id, emotion: "BEER"} diff --git a/test/groupher_server_web/query/accounts/published/published_blogs_test.exs b/test/groupher_server_web/query/accounts/published/published_blogs_test.exs index 4e66fa87e..3fbf1bbde 100644 --- a/test/groupher_server_web/query/accounts/published/published_blogs_test.exs +++ b/test/groupher_server_web/query/accounts/published/published_blogs_test.exs @@ -78,7 +78,7 @@ defmodule GroupherServer.Test.Query.Accounts.Published.Blogs do test "user can get paged published comments on blog", ~m(guest_conn user blog)a do pub_comments = Enum.reduce(1..@publish_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "comment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) acc ++ [comment] end) diff --git a/test/groupher_server_web/query/accounts/published/published_repos_test.exs b/test/groupher_server_web/query/accounts/published/published_repos_test.exs index 19227f564..72e43b730 100644 --- a/test/groupher_server_web/query/accounts/published/published_repos_test.exs +++ b/test/groupher_server_web/query/accounts/published/published_repos_test.exs @@ -79,7 +79,7 @@ defmodule GroupherServer.Test.Query.Accounts.Published.Repos do test "user can get paged published comments on repo", ~m(guest_conn user repo)a do pub_comments = Enum.reduce(1..@publish_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "comment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) acc ++ [comment] end) diff --git a/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs index f03c35c48..c36ad9d9d 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs @@ -92,7 +92,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.RepoReport do end test "support article_comment", ~m(guest_conn repo user)a do - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "comment", user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) variables = %{filter: %{content_type: "ARTICLE_COMMENT", page: 1, size: 10}} diff --git a/test/groupher_server_web/query/cms/comments/job_comment_test.exs b/test/groupher_server_web/query/cms/comments/job_comment_test.exs index d0025dd8e..84d9fa8c9 100644 --- a/test/groupher_server_web/query/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/job_comment_test.exs @@ -256,17 +256,17 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do thread = :job Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(thread, job.id, "test comment", user) + {:ok, comment} = CMS.create_article_comment(thread, job.id, mock_comment(), user) acc ++ [comment] end) - {:ok, comment} = CMS.create_article_comment(thread, job.id, "pinned comment", user) + {:ok, comment} = CMS.create_article_comment(thread, job.id, mock_comment(), user) {:ok, pinned_comment} = CMS.pin_article_comment(comment.id) Process.sleep(1000) - {:ok, comment} = CMS.create_article_comment(thread, job.id, "pinned comment 2", user) + {:ok, comment} = CMS.create_article_comment(thread, job.id, mock_comment(), user) {:ok, pinned_comment2} = CMS.pin_article_comment(comment.id) variables = %{id: job.id, thread: "JOB", filter: %{page: 1, size: 10}} @@ -284,7 +284,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do page_size = 10 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(thread, job.id, "test comment", user) + {:ok, comment} = CMS.create_article_comment(thread, job.id, mock_comment(), user) Process.sleep(1000) acc ++ [comment] end) @@ -300,11 +300,11 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do page_size = 10 thread = :job - {:ok, comment} = CMS.create_article_comment(thread, job.id, "test comment 1", user) + {:ok, comment} = CMS.create_article_comment(thread, job.id, mock_comment(), user) Process.sleep(1000) - {:ok, _comment2} = CMS.create_article_comment(thread, job.id, "test comment 2", user) + {:ok, _comment2} = CMS.create_article_comment(thread, job.id, mock_comment(), user) Process.sleep(1000) - {:ok, comment3} = CMS.create_article_comment(thread, job.id, "test comment 3", user) + {:ok, comment3} = CMS.create_article_comment(thread, job.id, mock_comment(), user) variables = %{ id: job.id, @@ -323,11 +323,11 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do page_size = 10 thread = :job - {:ok, comment} = CMS.create_article_comment(thread, job.id, "test comment 1", user) + {:ok, comment} = CMS.create_article_comment(thread, job.id, mock_comment(), user) Process.sleep(1000) - {:ok, _comment2} = CMS.create_article_comment(thread, job.id, "test comment 2", user) + {:ok, _comment2} = CMS.create_article_comment(thread, job.id, mock_comment(), user) Process.sleep(1000) - {:ok, comment3} = CMS.create_article_comment(thread, job.id, "test comment 3", user) + {:ok, comment3} = CMS.create_article_comment(thread, job.id, mock_comment(), user) variables = %{ id: job.id, @@ -351,11 +351,11 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user2) Process.sleep(1000) - {:ok, comment2} = CMS.create_article_comment(thread, job.id, "test comment 2", user) + {:ok, comment2} = CMS.create_article_comment(thread, job.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, mock_comment(), user2) Process.sleep(1000) - {:ok, comment3} = CMS.create_article_comment(thread, job.id, "test comment 3", user) + {:ok, comment3} = CMS.create_article_comment(thread, job.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, mock_comment(), user2) diff --git a/test/groupher_server_web/query/cms/comments/post_comment_test.exs b/test/groupher_server_web/query/cms/comments/post_comment_test.exs index 6b2235d01..8813c9844 100644 --- a/test/groupher_server_web/query/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/post_comment_test.exs @@ -259,17 +259,17 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do thread = :post Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(thread, post.id, "test comment", user) + {:ok, comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) acc ++ [comment] end) - {:ok, comment} = CMS.create_article_comment(thread, post.id, "pinned comment", user) + {:ok, comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) {:ok, pinned_comment} = CMS.pin_article_comment(comment.id) Process.sleep(1000) - {:ok, comment} = CMS.create_article_comment(thread, post.id, "pinned comment 2", user) + {:ok, comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) {:ok, pinned_comment2} = CMS.pin_article_comment(comment.id) variables = %{id: post.id, thread: "POST", filter: %{page: 1, size: 10}} @@ -292,7 +292,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do thread = :post Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(thread, post.id, "test comment", user) + {:ok, comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) acc ++ [comment] end) @@ -300,7 +300,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) post_author = post.author.user - {:ok, comment} = CMS.create_article_comment(thread, post.id, "pinned comment", user) + {:ok, comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) {:ok, _pinned_comment} = CMS.pin_article_comment(comment.id) Process.sleep(1000) @@ -309,7 +309,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do {:ok, solution_comment} = CMS.mark_comment_solution(comment.id, post_author) Process.sleep(1000) - {:ok, comment} = CMS.create_article_comment(thread, post.id, "pinned comment 2", user) + {:ok, comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) {:ok, _pinned_comment2} = CMS.pin_article_comment(comment.id) variables = %{id: post.id, thread: "POST", filter: %{page: 1, size: 10}} @@ -325,7 +325,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do page_size = 10 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(thread, post.id, "test comment", user) + {:ok, comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) Process.sleep(1000) acc ++ [comment] end) @@ -341,11 +341,11 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do page_size = 10 thread = :post - {:ok, comment} = CMS.create_article_comment(thread, post.id, "test comment 1", user) + {:ok, comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) Process.sleep(1000) - {:ok, _comment2} = CMS.create_article_comment(thread, post.id, "test comment 2", user) + {:ok, _comment2} = CMS.create_article_comment(thread, post.id, mock_comment(), user) Process.sleep(1000) - {:ok, comment3} = CMS.create_article_comment(thread, post.id, "test comment 3", user) + {:ok, comment3} = CMS.create_article_comment(thread, post.id, mock_comment(), user) variables = %{ id: post.id, @@ -364,11 +364,11 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do page_size = 10 thread = :post - {:ok, comment} = CMS.create_article_comment(thread, post.id, "test comment 1", user) + {:ok, comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) Process.sleep(1000) - {:ok, _comment2} = CMS.create_article_comment(thread, post.id, "test comment 2", user) + {:ok, _comment2} = CMS.create_article_comment(thread, post.id, mock_comment(), user) Process.sleep(1000) - {:ok, comment3} = CMS.create_article_comment(thread, post.id, "test comment 3", user) + {:ok, comment3} = CMS.create_article_comment(thread, post.id, mock_comment(), user) variables = %{ id: post.id, @@ -392,11 +392,11 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user2) Process.sleep(1000) - {:ok, comment2} = CMS.create_article_comment(thread, post.id, "test comment 2", user) + {:ok, comment2} = CMS.create_article_comment(thread, post.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, mock_comment(), user2) Process.sleep(1000) - {:ok, comment3} = CMS.create_article_comment(thread, post.id, "test comment 3", user) + {:ok, comment3} = CMS.create_article_comment(thread, post.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, mock_comment(), user2) diff --git a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs index c911d1dff..e4fcae921 100644 --- a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs @@ -254,17 +254,17 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do thread = :repo Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment", user) + {:ok, comment} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) acc ++ [comment] end) - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "pinned comment", user) + {:ok, comment} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) {:ok, pinned_comment} = CMS.pin_article_comment(comment.id) Process.sleep(1000) - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "pinned comment 2", user) + {:ok, comment} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) {:ok, pinned_comment2} = CMS.pin_article_comment(comment.id) variables = %{id: repo.id, thread: "REPO", filter: %{page: 1, size: 10}} @@ -282,7 +282,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do page_size = 10 Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment", user) + {:ok, comment} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) Process.sleep(1000) acc ++ [comment] end) @@ -298,11 +298,11 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do page_size = 10 thread = :repo - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment 1", user) + {:ok, comment} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) Process.sleep(1000) - {:ok, _comment2} = CMS.create_article_comment(thread, repo.id, "test comment 2", user) + {:ok, _comment2} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) Process.sleep(1000) - {:ok, comment3} = CMS.create_article_comment(thread, repo.id, "test comment 3", user) + {:ok, comment3} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) variables = %{ id: repo.id, @@ -321,11 +321,11 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do page_size = 10 thread = :repo - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment 1", user) + {:ok, comment} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) Process.sleep(1000) - {:ok, _comment2} = CMS.create_article_comment(thread, repo.id, "test comment 2", user) + {:ok, _comment2} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) Process.sleep(1000) - {:ok, comment3} = CMS.create_article_comment(thread, repo.id, "test comment 3", user) + {:ok, comment3} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) variables = %{ id: repo.id, @@ -349,11 +349,11 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user2) Process.sleep(1000) - {:ok, comment2} = CMS.create_article_comment(thread, repo.id, "test comment 2", user) + {:ok, comment2} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment2.id, mock_comment(), user2) Process.sleep(1000) - {:ok, comment3} = CMS.create_article_comment(thread, repo.id, "test comment 3", user) + {:ok, comment3} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment3.id, mock_comment(), user2) @@ -562,8 +562,8 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do acc ++ [comment] end) - {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) - {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, "commment", user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) variables = %{id: repo.id, thread: thread, filter: %{page: 1, size: page_size}} diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs index e01927370..b666b1bfd 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs @@ -416,7 +416,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedJobs do assert first_job["id"] !== to_string(job_last_week.id) Process.sleep(1500) - {:ok, _comment} = CMS.create_article_comment(:job, job_last_week.id, "comment", user) + {:ok, _comment} = CMS.create_article_comment(:job, job_last_week.id, mock_comment(), user) results = guest_conn |> query_result(@query, variables, "pagedJobs") entries = results["entries"] @@ -428,7 +428,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedJobs do test "comment on very old job have no effect", ~m(guest_conn job_last_year user)a do variables = %{filter: %{page: 1, size: 20}} - {:ok, _comment} = CMS.create_article_comment(:job, job_last_year.id, "comment", user) + {:ok, _comment} = CMS.create_article_comment(:job, job_last_year.id, mock_comment(), user) results = guest_conn |> query_result(@query, variables, "pagedJobs") entries = results["entries"] diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs index b5d268cc7..f1e78d297 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs @@ -323,7 +323,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do assert first_post["id"] !== to_string(post_last_week.id) Process.sleep(1500) - {:ok, _comment} = CMS.create_article_comment(:post, post_last_week.id, "comment", user) + {:ok, _comment} = CMS.create_article_comment(:post, post_last_week.id, mock_comment(), user) results = guest_conn |> query_result(@query, variables, "pagedPosts") entries = results["entries"] @@ -335,7 +335,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do test "comment on very old post have no effect", ~m(guest_conn post_last_year user)a do variables = %{filter: %{page: 1, size: 20}} - {:ok, _comment} = CMS.create_article_comment(:post, post_last_year.id, "comment", user) + {:ok, _comment} = CMS.create_article_comment(:post, post_last_year.id, mock_comment(), user) results = guest_conn |> query_result(@query, variables, "pagedPosts") entries = results["entries"] diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs index 798c50a50..8401485b2 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs @@ -361,7 +361,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedRepos do assert first_repo["id"] !== to_string(repo_last_week.id) Process.sleep(1500) - {:ok, _comment} = CMS.create_article_comment(:repo, repo_last_week.id, "comment", user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo_last_week.id, mock_comment(), user) results = guest_conn |> query_result(@query, variables, "pagedRepos") entries = results["entries"] @@ -373,7 +373,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedRepos do test "comment on very old repo have no effect", ~m(guest_conn repo_last_year user)a do variables = %{filter: %{page: 1, size: 20}} - {:ok, _comment} = CMS.create_article_comment(:repo, repo_last_year.id, "comment", user) + {:ok, _comment} = CMS.create_article_comment(:repo, repo_last_year.id, mock_comment(), user) results = guest_conn |> query_result(@query, variables, "pagedRepos") entries = results["entries"] From d7be2dc3278e63619d1eb3359060749c7bb82c4c Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 22:19:35 +0800 Subject: [PATCH 13/31] refactor(editor-workflow): rich test for comment test wip --- .../schema/cms/mutations/comment.ex | 6 +-- .../comments/blog_comment_emotions_test.exs | 21 +++------ .../comments/blog_comment_replies_test.exs | 28 ++++------- .../cms/comments/blog_comment_test.exs | 40 +++++++--------- .../comments/job_comment_emotions_test.exs | 21 +++------ .../cms/comments/job_comment_replies_test.exs | 28 ++++------- .../cms/comments/job_comment_test.exs | 12 ++--- .../comments/post_comment_emotions_test.exs | 19 +++----- .../comments/post_comment_replies_test.exs | 34 +++++--------- .../cms/comments/post_comment_test.exs | 44 +++++++----------- .../comments/repo_comment_replies_test.exs | 18 ++------ .../cms/comments/repo_comment_test.exs | 26 ++++------- .../cms/comments/blog_comment_test.exs | 29 ++++++------ .../cms/comments/job_comment_test.exs | 16 +++---- .../cms/comments/post_comment_test.exs | 16 +++---- .../cms/comments/repo_comment_test.exs | 16 +++---- .../mutation/statistics/statistics_test.exs | 2 +- .../query/cms/comments/job_comment_test.exs | 40 +++++++++++----- .../query/cms/comments/post_comment_test.exs | 46 +++++++++++++------ .../query/cms/comments/repo_comment_test.exs | 40 +++++++++++----- 20 files changed, 232 insertions(+), 270 deletions(-) diff --git a/lib/groupher_server_web/schema/cms/mutations/comment.ex b/lib/groupher_server_web/schema/cms/mutations/comment.ex index 3ef9ecc1f..26da702f6 100644 --- a/lib/groupher_server_web/schema/cms/mutations/comment.ex +++ b/lib/groupher_server_web/schema/cms/mutations/comment.ex @@ -10,7 +10,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Comment do # TODO use thread and force community pass-in arg(:thread, :thread, default_value: :post) arg(:id, non_null(:id)) - arg(:content, non_null(:string)) + arg(:body, non_null(:string)) # arg(:mention_users, list_of(:ids)) # TDOO: use a comment resolver @@ -23,7 +23,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Comment do @desc "update a comment" field :update_article_comment, :article_comment do arg(:id, non_null(:id)) - arg(:content, non_null(:string)) + arg(:body, non_null(:string)) # arg(:mention_users, list_of(:ids)) middleware(M.Authorize, :login) @@ -47,7 +47,7 @@ defmodule GroupherServerWeb.Schema.CMS.Mutations.Comment do @desc "reply to a comment" field :reply_article_comment, :article_comment do arg(:id, non_null(:id)) - arg(:content, non_null(:string)) + arg(:body, non_null(:string)) middleware(M.Authorize, :login) # TODO: 文章作者可以删除评论,文章可以设置禁止评论 diff --git a/test/groupher_server/cms/comments/blog_comment_emotions_test.exs b/test/groupher_server/cms/comments/blog_comment_emotions_test.exs index 3eacf1493..10654a2b9 100644 --- a/test/groupher_server/cms/comments/blog_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_emotions_test.exs @@ -65,9 +65,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentEmotions do describe "[basic article comment emotion]" do test "comment has default emotions after created", ~m(blog user)a do - parent_content = "parent comment" - - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) emotions = parent_comment.emotions |> Map.from_struct() |> Map.delete(:id) @@ -75,8 +73,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentEmotions do end test "can make emotion to comment", ~m(blog user user2)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user2) @@ -89,8 +86,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentEmotions do end test "can undo emotion to comment", ~m(blog user user2)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user2) @@ -111,8 +107,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentEmotions do end test "same user make same emotion to same comment.", ~m(blog user)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) @@ -125,8 +120,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentEmotions do test "same user same emotion to same comment only have one user_emotion record", ~m(blog user)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :heart, user) @@ -147,7 +141,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentEmotions do end test "different user can make same emotions on same comment", ~m(blog user user2 user3)a do - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, "parent comment", user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :beer, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :beer, user2) @@ -163,8 +157,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentEmotions do end test "same user can make differcent emotions on same comment", ~m(blog user)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) diff --git a/test/groupher_server/cms/comments/blog_comment_replies_test.exs b/test/groupher_server/cms/comments/blog_comment_replies_test.exs index 8b880c93f..8cc00a61f 100644 --- a/test/groupher_server/cms/comments/blog_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_replies_test.exs @@ -20,11 +20,8 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do describe "[basic article comment replies]" do test "exsit comment can be reply", ~m(blog user user2)a do - parent_content = "parent comment" - reply_content = "reply comment" - - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, parent_content, user) - {:ok, replyed_comment} = CMS.reply_article_comment(parent_comment.id, reply_content, user2) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) + {:ok, replyed_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) assert replyed_comment.reply_to.id == parent_comment.id {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) @@ -33,27 +30,20 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do end test "deleted comment can not be reply", ~m(blog user user2)a do - parent_content = "parent comment" - reply_content = "reply comment" - - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _} = CMS.delete_article_comment(parent_comment) - {:error, _} = CMS.reply_article_comment(parent_comment.id, reply_content, user2) + {:error, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) end test "multi reply should belong to one parent comment", ~m(blog user user2)a do - parent_content = "parent comment" - reply_content_1 = "reply comment 1" - reply_content_2 = "reply comment 2" - - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, replyed_comment_1} = - CMS.reply_article_comment(parent_comment.id, reply_content_1, user2) + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, replyed_comment_2} = - CMS.reply_article_comment(parent_comment.id, reply_content_2, user2) + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) @@ -63,7 +53,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do test "reply to reply inside a comment should belong same parent comment", ~m(blog user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, "parent comment", user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) @@ -93,7 +83,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do test "reply to reply inside a comment should have is_reply_to_others flag in meta", ~m(blog user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, "parent comment", user) + {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) diff --git a/test/groupher_server/cms/comments/blog_comment_test.exs b/test/groupher_server/cms/comments/blog_comment_test.exs index 3cbf56e96..6d552bc3a 100644 --- a/test/groupher_server/cms/comments/blog_comment_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_test.exs @@ -27,8 +27,8 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do describe "[basic article comment]" do test "blog are supported by article comment.", ~m(user blog)a do - {:ok, blog_comment_1} = CMS.create_article_comment(:blog, blog.id, "blog_comment 1", user) - {:ok, blog_comment_2} = CMS.create_article_comment(:blog, blog.id, "blog_comment 2", user) + {:ok, blog_comment_1} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) + {:ok, blog_comment_2} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, blog} = ORM.find(Blog, blog.id, preload: :article_comments) @@ -37,13 +37,13 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "comment should have default meta after create", ~m(user blog)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta end test "create comment should update active timestamp of blog", ~m(user blog)a do Process.sleep(1000) - {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user) + {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, blog} = ORM.find(Blog, blog.id, preload: :article_comments) assert not is_nil(blog.active_at) @@ -74,7 +74,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do {:ok, blog} = db_insert(:blog, %{inserted_at: inserted_at}) Process.sleep(1000) - {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user) + {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, blog} = ORM.find(Blog, blog.id) assert blog.active_at |> DateTime.to_date() == DateTime.utc_now() |> DateTime.to_date() @@ -85,14 +85,14 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do {:ok, blog} = db_insert(:blog, %{inserted_at: inserted_at}) Process.sleep(3000) - {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user) + {:ok, _comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, blog} = ORM.find(Blog, blog.id) assert blog.active_at |> DateTime.to_unix() !== DateTime.utc_now() |> DateTime.to_unix() end test "comment can be updated", ~m(blog user)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, updated_comment} = CMS.update_article_comment(comment, "updated content") @@ -103,7 +103,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do describe "[article comment floor]" do test "comment will have a floor number after created", ~m(user blog)a do {:ok, blog_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) - {:ok, blog_comment2} = CMS.create_article_comment(:blog, blog.id, "comment2", user) + {:ok, blog_comment2} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, blog_comment} = ORM.find(ArticleComment, blog_comment.id) {:ok, blog_comment2} = ORM.find(ArticleComment, blog_comment2.id) @@ -115,9 +115,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do describe "[article comment participator for blog]" do test "blog will have participator after comment created", ~m(user blog)a do - blog_comment_1 = "blog_comment 1" - - {:ok, _} = CMS.create_article_comment(:blog, blog.id, blog_comment_1, user) + {:ok, _} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, blog} = ORM.find(Blog, blog.id) @@ -126,10 +124,8 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "psot participator will not contains same user", ~m(user blog)a do - blog_comment_1 = "blog_comment 1" - - {:ok, _} = CMS.create_article_comment(:blog, blog.id, blog_comment_1, user) - {:ok, _} = CMS.create_article_comment(:blog, blog.id, blog_comment_1, user) + {:ok, _} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) + {:ok, _} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, blog} = ORM.find(Blog, blog.id) @@ -138,9 +134,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do test "recent comment user should appear at first of the psot participators", ~m(user user2 blog)a do - blog_comment_1 = "blog_comment 1" - - {:ok, _} = CMS.create_article_comment(:blog, blog.id, blog_comment_1, user) + {:ok, _} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _} = CMS.create_article_comment(:blog, blog.id, blog_comment_1, user2) {:ok, blog} = ORM.find(Blog, blog.id) @@ -389,7 +383,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do Enum.reduce(1..total_count, [], fn _, acc -> {:ok, new_user} = db_insert(:user) - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", new_user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), new_user) acc ++ [comment] end) @@ -638,7 +632,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do assert not comment.is_article_author author_user = blog.author.user - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "commment", author_user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), author_user) assert comment.is_article_author end end @@ -657,15 +651,15 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do test "locked blog can not by reply", ~m(user blog)a do {:ok, parent_comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, _} = CMS.lock_article_comment(:blog, blog.id) - {:error, reason} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) + {:error, reason} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) assert reason |> is_error?(:article_comment_locked) {:ok, _} = CMS.undo_lock_article_comment(:blog, blog.id) - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) end end end diff --git a/test/groupher_server/cms/comments/job_comment_emotions_test.exs b/test/groupher_server/cms/comments/job_comment_emotions_test.exs index 1fec325ea..0d4086f27 100644 --- a/test/groupher_server/cms/comments/job_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/job_comment_emotions_test.exs @@ -65,9 +65,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do describe "[basic article comment emotion]" do test "comment has default emotions after created", ~m(job user)a do - parent_content = "parent comment" - - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) emotions = parent_comment.emotions |> Map.from_struct() |> Map.delete(:id) @@ -75,8 +73,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do end test "can make emotion to comment", ~m(job user user2)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user2) @@ -89,8 +86,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do end test "can undo emotion to comment", ~m(job user user2)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user2) @@ -111,8 +107,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do end test "same user make same emotion to same comment.", ~m(job user)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) @@ -125,8 +120,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do test "same user same emotion to same comment only have one user_emotion record", ~m(job user)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :heart, user) @@ -147,7 +141,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do end test "different user can make same emotions on same comment", ~m(job user user2 user3)a do - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :beer, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :beer, user2) @@ -163,8 +157,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do end test "same user can make differcent emotions on same comment", ~m(job user)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) diff --git a/test/groupher_server/cms/comments/job_comment_replies_test.exs b/test/groupher_server/cms/comments/job_comment_replies_test.exs index 337aa9877..08f49e47e 100644 --- a/test/groupher_server/cms/comments/job_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/job_comment_replies_test.exs @@ -20,11 +20,8 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do describe "[basic article comment replies]" do test "exsit comment can be reply", ~m(job user user2)a do - parent_content = "parent comment" - reply_content = "reply comment" - - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) - {:ok, replyed_comment} = CMS.reply_article_comment(parent_comment.id, reply_content, user2) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, replyed_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) assert replyed_comment.reply_to.id == parent_comment.id {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) @@ -33,27 +30,20 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do end test "deleted comment can not be reply", ~m(job user user2)a do - parent_content = "parent comment" - reply_content = "reply comment" - - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, _} = CMS.delete_article_comment(parent_comment) - {:error, _} = CMS.reply_article_comment(parent_comment.id, reply_content, user2) + {:error, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) end test "multi reply should belong to one parent comment", ~m(job user user2)a do - parent_content = "parent comment" - reply_content_1 = "reply comment 1" - reply_content_2 = "reply comment 2" - - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, replyed_comment_1} = - CMS.reply_article_comment(parent_comment.id, reply_content_1, user2) + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, replyed_comment_2} = - CMS.reply_article_comment(parent_comment.id, reply_content_2, user2) + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) @@ -63,7 +53,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do test "reply to reply inside a comment should belong same parent comment", ~m(job user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) @@ -93,7 +83,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do test "reply to reply inside a comment should have is_reply_to_others flag in meta", ~m(job user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user) + {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index 548358435..2f8e7435d 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -27,8 +27,8 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do describe "[basic article comment]" do test "job are supported by article comment.", ~m(user job)a do - {:ok, job_comment_1} = CMS.create_article_comment(:job, job.id, "job_comment 1", user) - {:ok, job_comment_2} = CMS.create_article_comment(:job, job.id, "job_comment 2", user) + {:ok, job_comment_1} = CMS.create_article_comment(:job, job.id, mock_comment(), user) + {:ok, job_comment_2} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, job} = ORM.find(Job, job.id, preload: :article_comments) @@ -57,7 +57,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do Process.sleep(1000) - {:ok, _comment} = CMS.create_article_comment(:job, job.id, "job comment", job.author.user) + {:ok, _comment} = CMS.create_article_comment(:job, job.id, mock_comment(), job.author.user) {:ok, job} = ORM.find(Job, job.id, preload: :article_comments) @@ -102,7 +102,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do describe "[article comment floor]" do test "comment will have a floor number after created", ~m(user job)a do {:ok, job_comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) - {:ok, job_comment2} = CMS.create_article_comment(:job, job.id, "comment2", user) + {:ok, job_comment2} = CMS.create_article_comment(:job, job.id, mock_comment(), user) {:ok, job_comment} = ORM.find(ArticleComment, job_comment.id) {:ok, job_comment2} = ORM.find(ArticleComment, job_comment2.id) @@ -374,7 +374,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do Enum.reduce(1..total_count, [], fn _, acc -> {:ok, new_user} = db_insert(:user) - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", new_user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), new_user) acc ++ [comment] end) @@ -623,7 +623,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do assert not comment.is_article_author author_user = job.author.user - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", author_user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), author_user) assert comment.is_article_author end end diff --git a/test/groupher_server/cms/comments/post_comment_emotions_test.exs b/test/groupher_server/cms/comments/post_comment_emotions_test.exs index 6ca936842..fd0d0a4a0 100644 --- a/test/groupher_server/cms/comments/post_comment_emotions_test.exs +++ b/test/groupher_server/cms/comments/post_comment_emotions_test.exs @@ -65,9 +65,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do describe "[basic article comment emotion]" do test "comment has default emotions after created", ~m(post user)a do - parent_content = "parent comment" - - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) emotions = parent_comment.emotions |> Map.from_struct() |> Map.delete(:id) @@ -75,8 +73,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do end test "can make emotion to comment", ~m(post user user2)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user2) @@ -89,8 +86,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do end test "can undo emotion to comment", ~m(post user user2)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user2) @@ -111,8 +107,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do end test "same user make same emotion to same comment.", ~m(post user)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) @@ -125,8 +120,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do test "same user same emotion to same comment only have one user_emotion record", ~m(post user)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :heart, user) @@ -163,8 +157,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentEmotions do end test "same user can make differcent emotions on same comment", ~m(post user)a do - parent_content = "parent comment" - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) {:ok, _} = CMS.emotion_to_comment(parent_comment.id, :downvote, user) diff --git a/test/groupher_server/cms/comments/post_comment_replies_test.exs b/test/groupher_server/cms/comments/post_comment_replies_test.exs index f02ecdacf..9c8909d2d 100644 --- a/test/groupher_server/cms/comments/post_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/post_comment_replies_test.exs @@ -20,11 +20,8 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do describe "[basic article comment replies]" do test "exsit comment can be reply", ~m(post user user2)a do - parent_content = "parent comment" - reply_content = "reply comment" - - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) - {:ok, replyed_comment} = CMS.reply_article_comment(parent_comment.id, reply_content, user2) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, replyed_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) assert replyed_comment.reply_to.id == parent_comment.id {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) @@ -33,27 +30,20 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do end test "deleted comment can not be reply", ~m(post user user2)a do - parent_content = "parent comment" - reply_content = "reply comment" - - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.delete_article_comment(parent_comment) - {:error, _} = CMS.reply_article_comment(parent_comment.id, reply_content, user2) + {:error, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) end test "multi reply should belong to one parent comment", ~m(post user user2)a do - parent_content = "parent comment" - reply_content_1 = "reply comment 1" - reply_content_2 = "reply comment 2" - - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, parent_content, user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, replyed_comment_1} = - CMS.reply_article_comment(parent_comment.id, reply_content_1, user2) + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, replyed_comment_2} = - CMS.reply_article_comment(parent_comment.id, reply_content_2, user2) + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) @@ -118,7 +108,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do test "comment replies only contains @max_parent_replies_count replies", ~m(post user)a do total_reply_count = @max_parent_replies_count + 1 - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) reply_comment_list = Enum.reduce(1..total_reply_count, [], fn n, acc -> @@ -138,7 +128,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do end test "replyed user should appear in article comment participators", ~m(post user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, article} = ORM.find(Post, post.id) @@ -148,7 +138,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do end test "replies count should inc by 1 after got replyed", ~m(post user user2)a do - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) assert parent_comment.replies_count === 0 {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) @@ -163,7 +153,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do describe "[paged article comment replies]" do test "can get paged replies of a parent comment", ~m(post user)a do - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, paged_replies} = CMS.paged_comment_replies(parent_comment.id, %{page: 1, size: 20}) assert is_valid_pagination?(paged_replies, :raw, :empty) @@ -192,7 +182,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do page_number = 1 page_size = 10 - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index ae81009c9..b868a7e46 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -116,9 +116,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do describe "[article comment participator for post]" do test "post will have participator after comment created", ~m(user post)a do - post_comment_1 = "post_comment 1" - - {:ok, _} = CMS.create_article_comment(:post, post.id, post_comment_1, user) + {:ok, _} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, post} = ORM.find(Post, post.id) @@ -127,10 +125,8 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "psot participator will not contains same user", ~m(user post)a do - post_comment_1 = "post_comment 1" - - {:ok, _} = CMS.create_article_comment(:post, post.id, post_comment_1, user) - {:ok, _} = CMS.create_article_comment(:post, post.id, post_comment_1, user) + {:ok, _} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, _} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, post} = ORM.find(Post, post.id) @@ -139,9 +135,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do test "recent comment user should appear at first of the psot participators", ~m(user user2 post)a do - post_comment_1 = "post_comment 1" - - {:ok, _} = CMS.create_article_comment(:post, post.id, post_comment_1, user) + {:ok, _} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.create_article_comment(:post, post.id, post_comment_1, user2) {:ok, post} = ORM.find(Post, post.id) @@ -154,8 +148,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do describe "[article comment upvotes]" do test "user can upvote a post comment", ~m(user post)a do - comment = "post_comment" - {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) @@ -166,8 +159,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "article author upvote post comment will have flag", ~m(post user)a do - comment = "post_comment" - {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, author_user} = ORM.find(User, post.author.user.id) CMS.upvote_article_comment(comment.id, author_user) @@ -177,8 +169,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "user upvote post comment will add id to upvoted_user_ids", ~m(post user)a do - comment = "post_comment" - {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, comment} = CMS.upvote_article_comment(comment.id, user) assert user.id in comment.meta.upvoted_user_ids @@ -186,8 +177,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do test "user undo upvote post comment will remove id from upvoted_user_ids", ~m(post user user2)a do - comment = "post_comment" - {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _comment} = CMS.upvote_article_comment(comment.id, user) {:ok, comment} = CMS.upvote_article_comment(comment.id, user2) @@ -201,16 +191,14 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "user upvote a already-upvoted comment fails", ~m(user post)a do - comment = "post_comment" - {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) {:error, _} = CMS.upvote_article_comment(comment.id, user) end test "upvote comment should inc the comment's upvotes_count", ~m(user user2 post)a do - comment = "post_comment" - {:ok, comment} = CMS.create_article_comment(:post, post.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert comment.upvotes_count == 0 @@ -390,7 +378,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do Enum.reduce(1..total_count, [], fn _, acc -> {:ok, new_user} = db_insert(:user) - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", new_user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), new_user) acc ++ [comment] end) @@ -639,7 +627,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert not comment.is_article_author author_user = post.author.user - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", author_user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), author_user) assert comment.is_article_author end end @@ -657,16 +645,16 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "locked post can not by reply", ~m(user post)a do - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_conent", user) - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) + {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, _} = CMS.lock_article_comment(:post, post.id) - {:error, reason} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) + {:error, reason} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) assert reason |> is_error?(:article_comment_locked) {:ok, _} = CMS.undo_lock_article_comment(:post, post.id) - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) end end diff --git a/test/groupher_server/cms/comments/repo_comment_replies_test.exs b/test/groupher_server/cms/comments/repo_comment_replies_test.exs index a24281fe5..45560830b 100644 --- a/test/groupher_server/cms/comments/repo_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_replies_test.exs @@ -20,11 +20,8 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do describe "[basic article comment replies]" do test "exsit comment can be reply", ~m(repo user user2)a do - parent_content = "parent comment" - reply_content = "reply comment" - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - {:ok, replyed_comment} = CMS.reply_article_comment(parent_comment.id, reply_content, user2) + {:ok, replyed_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) assert replyed_comment.reply_to.id == parent_comment.id {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) @@ -33,27 +30,20 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do end test "deleted comment can not be reply", ~m(repo user user2)a do - parent_content = "parent comment" - reply_content = "reply comment" - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.delete_article_comment(parent_comment) - {:error, _} = CMS.reply_article_comment(parent_comment.id, reply_content, user2) + {:error, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) end test "multi reply should belong to one parent comment", ~m(repo user user2)a do - parent_content = "parent comment" - reply_content_1 = "reply comment 1" - reply_content_2 = "reply comment 2" - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, replyed_comment_1} = - CMS.reply_article_comment(parent_comment.id, reply_content_1, user2) + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, replyed_comment_2} = - CMS.reply_article_comment(parent_comment.id, reply_content_2, user2) + CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) {:ok, parent_comment} = ORM.find(ArticleComment, parent_comment.id) diff --git a/test/groupher_server/cms/comments/repo_comment_test.exs b/test/groupher_server/cms/comments/repo_comment_test.exs index 8ce9068e9..3a0a73fb5 100644 --- a/test/groupher_server/cms/comments/repo_comment_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_test.exs @@ -103,7 +103,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do describe "[article comment floor]" do test "comment will have a floor number after created", ~m(user repo)a do {:ok, repo_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - {:ok, repo_comment2} = CMS.create_article_comment(:repo, repo.id, "comment2", user) + {:ok, repo_comment2} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, repo_comment} = ORM.find(ArticleComment, repo_comment.id) {:ok, repo_comment2} = ORM.find(ArticleComment, repo_comment2.id) @@ -115,9 +115,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do describe "[article comment participator for repo]" do test "repo will have participator after comment created", ~m(user repo)a do - repo_comment_1 = "repo_comment 1" - - {:ok, _} = CMS.create_article_comment(:repo, repo.id, repo_comment_1, user) + {:ok, _} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, repo} = ORM.find(Repo, repo.id) @@ -126,10 +124,8 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "psot participator will not contains same user", ~m(user repo)a do - repo_comment_1 = "repo_comment 1" - - {:ok, _} = CMS.create_article_comment(:repo, repo.id, repo_comment_1, user) - {:ok, _} = CMS.create_article_comment(:repo, repo.id, repo_comment_1, user) + {:ok, _} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) + {:ok, _} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, repo} = ORM.find(Repo, repo.id) @@ -138,9 +134,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do test "recent comment user should appear at first of the psot participators", ~m(user user2 repo)a do - repo_comment_1 = "repo_comment 1" - - {:ok, _} = CMS.create_article_comment(:repo, repo.id, repo_comment_1, user) + {:ok, _} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.create_article_comment(:repo, repo.id, repo_comment_1, user2) {:ok, repo} = ORM.find(Repo, repo.id) @@ -389,7 +383,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do Enum.reduce(1..total_count, [], fn _, acc -> {:ok, new_user} = db_insert(:user) - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", new_user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), new_user) acc ++ [comment] end) @@ -638,7 +632,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do assert not comment.is_article_author author_user = repo.author.user - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", author_user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), author_user) assert comment.is_article_author end end @@ -657,15 +651,15 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do test "locked repo can not by reply", ~m(user repo)a do {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, _} = CMS.lock_article_comment(:repo, repo.id) - {:error, reason} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) + {:error, reason} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) assert reason |> is_error?(:article_comment_locked) {:ok, _} = CMS.undo_lock_article_comment(:repo, repo.id) - {:ok, _} = CMS.reply_article_comment(parent_comment.id, "reply_content", user) + {:ok, _} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) end end end diff --git a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs index 70244675b..5e985c59b 100644 --- a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs @@ -20,16 +20,15 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do describe "[article comment CURD]" do @write_comment_query """ - mutation($thread: Thread!, $id: ID!, $content: String!) { - createArticleComment(thread: $thread,id: $id, content: $content) { + mutation($thread: Thread!, $id: ID!, $body: String!) { + createArticleComment(thread: $thread,id: $id, body: $body) { id bodyHtml } } """ test "write article comment to a exsit blog", ~m(blog user_conn)a do - comment = "a test comment" - variables = %{thread: "BLOG", id: blog.id, content: comment} + variables = %{thread: "BLOG", id: blog.id, body: mock_comment()} result = user_conn |> mutation_result(@write_comment_query, variables, "createArticleComment") @@ -38,8 +37,8 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do end @reply_comment_query """ - mutation($id: ID!, $content: String!) { - replyArticleComment(id: $id, content: $content) { + mutation($id: ID!, $body: String!) { + replyArticleComment(id: $id, body: $body) { id bodyHtml } @@ -47,7 +46,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do """ test "login user can reply to a comment", ~m(blog user user_conn)a do {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) - variables = %{id: comment.id, content: "reply content"} + variables = %{id: comment.id, body: mock_comment()} result = user_conn @@ -57,7 +56,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do end @update_comment_query """ - mutation($id: ID!, $content: String!) { + mutation($id: ID!, $body: String!) { updateArticleComment(id: $id, content: $content) { id bodyHtml @@ -66,8 +65,8 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do """ test "only owner can update a exsit comment", ~m(blog user guest_conn user_conn owner_conn)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user) - variables = %{id: comment.id, content: "updated comment"} + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) + variables = %{id: comment.id, content: mock_comment("updated comment")} assert user_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:passport)) @@ -90,7 +89,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do """ test "only owner can delete a exsit comment", ~m(blog user guest_conn user_conn owner_conn)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) variables = %{id: comment.id} assert user_conn |> mutation_get_error?(@delete_comment_query, variables, ecode(:passport)) @@ -118,7 +117,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do """ test "login user can upvote a exsit blog comment", ~m(blog user guest_conn user_conn)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) variables = %{id: comment.id} assert guest_conn @@ -143,7 +142,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do """ test "login user can undo upvote a exsit blog comment", ~m(blog user guest_conn user_conn)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) variables = %{id: comment.id} user_conn |> mutation_result(@upvote_comment_query, variables, "upvoteArticleComment") @@ -176,7 +175,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do } """ test "login user can emotion to a comment", ~m(blog user user_conn)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) variables = %{id: comment.id, emotion: "BEER"} comment = @@ -202,7 +201,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do } """ test "login user can undo emotion to a comment", ~m(blog user owner_conn)a do - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, "blog comment", user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _} = CMS.emotion_to_comment(comment.id, :beer, user) variables = %{id: comment.id, emotion: "BEER"} diff --git a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs index de4e66019..4ee0a9e2c 100644 --- a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs @@ -20,8 +20,8 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do describe "[article comment CURD]" do @write_comment_query """ - mutation($thread: Thread!, $id: ID!, $content: String!) { - createArticleComment(thread: $thread,id: $id, content: $content) { + mutation($thread: Thread!, $id: ID!, $body: String!) { + createArticleComment(thread: $thread,id: $id, body: $body) { id bodyHtml } @@ -38,8 +38,8 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do end @reply_comment_query """ - mutation($id: ID!, $content: String!) { - replyArticleComment(id: $id, content: $content) { + mutation($id: ID!, $body: String!) { + replyArticleComment(id: $id, body: $body) { id bodyHtml } @@ -47,7 +47,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do """ test "login user can reply to a comment", ~m(job user user_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) - variables = %{id: comment.id, content: "reply content"} + variables = %{id: comment.id, body: mock_comment()} result = user_conn @@ -57,8 +57,8 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do end @update_comment_query """ - mutation($id: ID!, $content: String!) { - updateArticleComment(id: $id, content: $content) { + mutation($id: ID!, $body: String!) { + updateArticleComment(id: $id, body: $body) { id bodyHtml } @@ -67,7 +67,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do test "only owner can update a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) - variables = %{id: comment.id, content: "updated comment"} + variables = %{id: comment.id, content: mock_comment("updated comment")} assert user_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:passport)) diff --git a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs index 5a0ad64ec..17c75a69c 100644 --- a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs @@ -20,8 +20,8 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do describe "[article comment CURD]" do @write_comment_query """ - mutation($thread: Thread!, $id: ID!, $content: String!) { - createArticleComment(thread: $thread,id: $id, content: $content) { + mutation($thread: Thread!, $id: ID!, $body: String!) { + createArticleComment(thread: $thread,id: $id, body: $body) { id bodyHtml } @@ -38,8 +38,8 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do end @reply_comment_query """ - mutation($id: ID!, $content: String!) { - replyArticleComment(id: $id, content: $content) { + mutation($id: ID!, $body: String!) { + replyArticleComment(id: $id, body: $body) { id bodyHtml } @@ -47,7 +47,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do """ test "login user can reply to a comment", ~m(post user user_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) - variables = %{id: comment.id, content: "reply content"} + variables = %{id: comment.id, body: mock_comment()} result = user_conn @@ -57,8 +57,8 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do end @update_comment_query """ - mutation($id: ID!, $content: String!) { - updateArticleComment(id: $id, content: $content) { + mutation($id: ID!, $body: String!) { + updateArticleComment(id: $id, body: $body) { id bodyHtml } @@ -67,7 +67,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do test "only owner can update a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) - variables = %{id: comment.id, content: "updated comment"} + variables = %{id: comment.id, content: mock_comment("updated comment")} assert user_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:passport)) diff --git a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs index db14fbf22..5eed0f5ec 100644 --- a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs @@ -20,8 +20,8 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do describe "[article comment CURD]" do @write_comment_query """ - mutation($thread: Thread!, $id: ID!, $content: String!) { - createArticleComment(thread: $thread,id: $id, content: $content) { + mutation($thread: Thread!, $id: ID!, $body: String!) { + createArticleComment(thread: $thread,id: $id, body: $body) { id bodyHtml } @@ -38,8 +38,8 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do end @reply_comment_query """ - mutation($id: ID!, $content: String!) { - replyArticleComment(id: $id, content: $content) { + mutation($id: ID!, $body: String!) { + replyArticleComment(id: $id, body: $body) { id bodyHtml } @@ -47,7 +47,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do """ test "login user can reply to a comment", ~m(repo user user_conn)a do {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - variables = %{id: comment.id, content: "reply content"} + variables = %{id: comment.id, body: mock_comment()} result = user_conn @@ -57,8 +57,8 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do end @update_comment_query """ - mutation($id: ID!, $content: String!) { - updateArticleComment(id: $id, content: $content) { + mutation($id: ID!, $body: String!) { + updateArticleComment(id: $id, body: $body) { id bodyHtml } @@ -67,7 +67,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do test "only owner can update a exsit comment", ~m(repo user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - variables = %{id: comment.id, content: "updated comment"} + variables = %{id: comment.id, content: mock_comment("updated comment")} assert user_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:passport)) diff --git a/test/groupher_server_web/mutation/statistics/statistics_test.exs b/test/groupher_server_web/mutation/statistics/statistics_test.exs index 060235f87..dad163ff3 100644 --- a/test/groupher_server_web/mutation/statistics/statistics_test.exs +++ b/test/groupher_server_web/mutation/statistics/statistics_test.exs @@ -189,7 +189,7 @@ defmodule GroupherServer.Test.Mutation.Statistics do end @write_comment_query """ - mutation($thread: Thread!, $id: ID!, $content: String!) { + mutation($thread: Thread!, $id: ID!, $body: String!) { createArticleComment(thread: $thread, id: $id, content: $content) { id bodyHtml diff --git a/test/groupher_server_web/query/cms/comments/job_comment_test.exs b/test/groupher_server_web/query/cms/comments/job_comment_test.exs index 84d9fa8c9..e11dd398a 100644 --- a/test/groupher_server_web/query/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/job_comment_test.exs @@ -44,7 +44,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do acc ++ [comment] end) - {:ok, _} = CMS.create_article_comment(thread, job.id, comment, user2) + {:ok, _} = CMS.create_article_comment(thread, job.id, mock_comment(), user2) variables = %{id: job.id} results = guest_conn |> query_result(@query, variables, "job") @@ -128,7 +128,9 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do all_comments = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, job.id, "comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, job.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -165,7 +167,9 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do all_comments = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, job.id, "comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, job.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -200,7 +204,9 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do thread = :job Enum.reduce(0..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, job.id, "comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, job.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -347,7 +353,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do page_size = 10 thread = :job - {:ok, comment} = CMS.create_article_comment(thread, job.id, "parent comment 1", user) + {:ok, comment} = CMS.create_article_comment(thread, job.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user2) Process.sleep(1000) @@ -378,7 +384,9 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do all_comment = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, job.id, "test comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, job.id, mock_comment("comment #{i}"), user) + Process.sleep(1000) acc ++ [comment] end) @@ -408,7 +416,9 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do all_comments = Enum.reduce(0..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, job.id, "test comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, job.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -416,7 +426,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do {:ok, _} = CMS.upvote_article_comment(random_comment.id, author_user) {:ok, author_comment} = - CMS.create_article_comment(thread, job.id, "test comment", author_user) + CMS.create_article_comment(thread, job.id, mock_comment(), author_user) {:ok, _} = CMS.upvote_article_comment(author_comment.id, author_user) @@ -444,7 +454,9 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do all_comment = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, job.id, "test comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, job.id, mock_comment("comment #{i}"), user) + Process.sleep(1000) acc ++ [comment] end) @@ -494,7 +506,9 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do all_comment = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, job.id, "test comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, job.id, mock_comment("comment #{i}"), user) + Process.sleep(1000) acc ++ [comment] end) @@ -519,7 +533,9 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do all_comments = Enum.reduce(0..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, job.id, "comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, job.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -559,7 +575,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do Enum.reduce(1..total_count, [], fn _, acc -> {:ok, new_user} = db_insert(:user) - {:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", new_user) + {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), new_user) acc ++ [comment] end) diff --git a/test/groupher_server_web/query/cms/comments/post_comment_test.exs b/test/groupher_server_web/query/cms/comments/post_comment_test.exs index 8813c9844..b145d4b5e 100644 --- a/test/groupher_server_web/query/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/post_comment_test.exs @@ -42,12 +42,12 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do thread = :post Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(thread, post.id, comment, user) + {:ok, comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) acc ++ [comment] end) - {:ok, _} = CMS.create_article_comment(thread, post.id, comment, user2) + {:ok, _} = CMS.create_article_comment(thread, post.id, mock_comment(), user2) variables = %{id: post.id} results = guest_conn |> query_result(@query, variables, "post") @@ -131,7 +131,9 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do all_comments = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, post.id, "comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, post.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -168,7 +170,9 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do all_comments = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, post.id, "comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, post.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -203,7 +207,9 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do thread = :post Enum.reduce(0..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, post.id, "comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, post.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -241,7 +247,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do thread = :post Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, value} = CMS.create_article_comment(thread, post.id, comment, user) + {:ok, value} = CMS.create_article_comment(thread, post.id, mock_comment(), user) acc ++ [value] end) @@ -388,7 +394,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do page_size = 10 thread = :post - {:ok, comment} = CMS.create_article_comment(thread, post.id, "parent comment 1", user) + {:ok, comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user2) Process.sleep(1000) @@ -419,7 +425,9 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do all_comment = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, post.id, "test comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, post.id, mock_comment("comment #{i}"), user) + Process.sleep(1000) acc ++ [comment] end) @@ -449,7 +457,9 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do all_comments = Enum.reduce(0..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, post.id, "test comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, post.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -457,7 +467,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do {:ok, _} = CMS.upvote_article_comment(random_comment.id, author_user) {:ok, author_comment} = - CMS.create_article_comment(thread, post.id, "test comment", author_user) + CMS.create_article_comment(thread, post.id, mock_comment(), author_user) {:ok, _} = CMS.upvote_article_comment(author_comment.id, author_user) @@ -485,7 +495,9 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do all_comment = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, post.id, "test comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, post.id, mock_comment("comment #{i}"), user) + Process.sleep(1000) acc ++ [comment] end) @@ -535,7 +547,9 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do all_comment = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, post.id, "test comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, post.id, mock_comment("comment #{i}"), user) + Process.sleep(1000) acc ++ [comment] end) @@ -560,7 +574,9 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do all_comments = Enum.reduce(0..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, post.id, "comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, post.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -600,7 +616,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do Enum.reduce(1..total_count, [], fn _, acc -> {:ok, new_user} = db_insert(:user) - {:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", new_user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), new_user) acc ++ [comment] end) @@ -675,7 +691,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do thread = :post author_user = post.author.user - {:ok, parent_comment} = CMS.create_article_comment(thread, post.id, comment, user) + {:ok, parent_comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) Enum.reduce(1..total_count, [], fn i, acc -> {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, "reply #{i}", user2) diff --git a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs index e4fcae921..77b1f67a4 100644 --- a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs @@ -42,7 +42,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do acc ++ [comment] end) - {:ok, _} = CMS.create_article_comment(thread, repo.id, comment, user2) + {:ok, _} = CMS.create_article_comment(thread, repo.id, mock_comment(), user2) variables = %{id: repo.id} results = guest_conn |> query_result(@query, variables, "repo") @@ -126,7 +126,9 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do all_comments = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, repo.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -163,7 +165,9 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do all_comments = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, repo.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -198,7 +202,9 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do thread = :repo Enum.reduce(0..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, repo.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -345,7 +351,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do page_size = 10 thread = :repo - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "parent comment 1", user) + {:ok, comment} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user) {:ok, _reply_comment} = CMS.reply_article_comment(comment.id, mock_comment(), user2) Process.sleep(1000) @@ -376,7 +382,9 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do all_comment = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, repo.id, mock_comment("comment #{i}"), user) + Process.sleep(1000) acc ++ [comment] end) @@ -406,7 +414,9 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do all_comments = Enum.reduce(0..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, repo.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -414,7 +424,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do {:ok, _} = CMS.upvote_article_comment(random_comment.id, author_user) {:ok, author_comment} = - CMS.create_article_comment(thread, repo.id, "test comment", author_user) + CMS.create_article_comment(thread, repo.id, mock_comment(), author_user) {:ok, _} = CMS.upvote_article_comment(author_comment.id, author_user) @@ -442,7 +452,9 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do all_comment = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, repo.id, mock_comment("comment #{i}"), user) + Process.sleep(1000) acc ++ [comment] end) @@ -492,7 +504,9 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do all_comment = Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "test comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, repo.id, mock_comment("comment #{i}"), user) + Process.sleep(1000) acc ++ [comment] end) @@ -517,7 +531,9 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do all_comments = Enum.reduce(0..total_count, [], fn i, acc -> - {:ok, comment} = CMS.create_article_comment(thread, repo.id, "comment #{i}", user) + {:ok, comment} = + CMS.create_article_comment(thread, repo.id, mock_comment("comment #{i}"), user) + acc ++ [comment] end) @@ -557,7 +573,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do Enum.reduce(1..total_count, [], fn _, acc -> {:ok, new_user} = db_insert(:user) - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, "commment", new_user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), new_user) acc ++ [comment] end) From 01a79daaa98b3181877fe1090a2ee87616b17354 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 22:27:58 +0800 Subject: [PATCH 14/31] refactor(editor-workflow): rich test for comment test wip --- test/groupher_server/cms/comments/blog_comment_test.exs | 2 +- test/groupher_server/cms/comments/repo_comment_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/groupher_server/cms/comments/blog_comment_test.exs b/test/groupher_server/cms/comments/blog_comment_test.exs index 6d552bc3a..3ca462e6b 100644 --- a/test/groupher_server/cms/comments/blog_comment_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_test.exs @@ -135,7 +135,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do test "recent comment user should appear at first of the psot participators", ~m(user user2 blog)a do {:ok, _} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) - {:ok, _} = CMS.create_article_comment(:blog, blog.id, blog_comment_1, user2) + {:ok, _} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user2) {:ok, blog} = ORM.find(Blog, blog.id) diff --git a/test/groupher_server/cms/comments/repo_comment_test.exs b/test/groupher_server/cms/comments/repo_comment_test.exs index 3a0a73fb5..324cea380 100644 --- a/test/groupher_server/cms/comments/repo_comment_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_test.exs @@ -135,7 +135,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do test "recent comment user should appear at first of the psot participators", ~m(user user2 repo)a do {:ok, _} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - {:ok, _} = CMS.create_article_comment(:repo, repo.id, repo_comment_1, user2) + {:ok, _} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user2) {:ok, repo} = ORM.find(Repo, repo.id) From e6b5c0e49577cdbd6df23ece7409d6189d3d4d4e Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 22:35:18 +0800 Subject: [PATCH 15/31] refactor(editor-workflow): rich test for comment test wip --- .../groupher_server/cms/comments/blog_comment_replies_test.exs | 2 +- test/groupher_server/cms/comments/job_comment_replies_test.exs | 3 +-- .../groupher_server/cms/comments/post_comment_replies_test.exs | 3 +-- test/groupher_server/cms/comments/post_comment_test.exs | 2 +- .../groupher_server/cms/comments/repo_comment_replies_test.exs | 3 +-- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/test/groupher_server/cms/comments/blog_comment_replies_test.exs b/test/groupher_server/cms/comments/blog_comment_replies_test.exs index 8cc00a61f..33aeb1ba0 100644 --- a/test/groupher_server/cms/comments/blog_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_replies_test.exs @@ -187,7 +187,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, reply_comment2} = - CMS.reply_article_comment(parent_comment.id, "reply_content_2", user) + CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, paged_comments} = CMS.paged_article_comments( diff --git a/test/groupher_server/cms/comments/job_comment_replies_test.exs b/test/groupher_server/cms/comments/job_comment_replies_test.exs index 08f49e47e..5b82a984e 100644 --- a/test/groupher_server/cms/comments/job_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/job_comment_replies_test.exs @@ -186,8 +186,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) - {:ok, reply_comment2} = - CMS.reply_article_comment(parent_comment.id, "reply_content_2", user) + {:ok, reply_comment2} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, paged_comments} = CMS.paged_article_comments( diff --git a/test/groupher_server/cms/comments/post_comment_replies_test.exs b/test/groupher_server/cms/comments/post_comment_replies_test.exs index 9c8909d2d..3d08b2693 100644 --- a/test/groupher_server/cms/comments/post_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/post_comment_replies_test.exs @@ -186,8 +186,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) - {:ok, reply_comment2} = - CMS.reply_article_comment(parent_comment.id, "reply_content_2", user) + {:ok, reply_comment2} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, paged_comments} = CMS.paged_article_comments( diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index b868a7e46..2a3175d70 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -136,7 +136,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do test "recent comment user should appear at first of the psot participators", ~m(user user2 post)a do {:ok, _} = CMS.create_article_comment(:post, post.id, mock_comment(), user) - {:ok, _} = CMS.create_article_comment(:post, post.id, post_comment_1, user2) + {:ok, _} = CMS.create_article_comment(:post, post.id, mock_comment(), user2) {:ok, post} = ORM.find(Post, post.id) diff --git a/test/groupher_server/cms/comments/repo_comment_replies_test.exs b/test/groupher_server/cms/comments/repo_comment_replies_test.exs index 45560830b..a5afceb19 100644 --- a/test/groupher_server/cms/comments/repo_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_replies_test.exs @@ -186,8 +186,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) - {:ok, reply_comment2} = - CMS.reply_article_comment(parent_comment.id, "reply_content_2", user) + {:ok, reply_comment2} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, paged_comments} = CMS.paged_article_comments( From 6a1883dde139294a05e791f7da30549232b62c09 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 22:37:06 +0800 Subject: [PATCH 16/31] refactor(editor-workflow): rich test for comment test wip --- .../comments/blog_comment_replies_test.exs | 3 +-- .../cms/comments/blog_comment_test.exs | 20 +++++++------------ .../cms/comments/repo_comment_test.exs | 12 +++++------ .../query/cms/comments/job_comment_test.exs | 6 +++--- .../query/cms/comments/repo_comment_test.exs | 6 +++--- 5 files changed, 20 insertions(+), 27 deletions(-) diff --git a/test/groupher_server/cms/comments/blog_comment_replies_test.exs b/test/groupher_server/cms/comments/blog_comment_replies_test.exs index 33aeb1ba0..d96b9dce6 100644 --- a/test/groupher_server/cms/comments/blog_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_replies_test.exs @@ -186,8 +186,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) - {:ok, reply_comment2} = - CMS.reply_article_comment(parent_comment.id, mock_comment(), user) + {:ok, reply_comment2} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user) {:ok, paged_comments} = CMS.paged_article_comments( diff --git a/test/groupher_server/cms/comments/blog_comment_test.exs b/test/groupher_server/cms/comments/blog_comment_test.exs index 3ca462e6b..67e083490 100644 --- a/test/groupher_server/cms/comments/blog_comment_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_test.exs @@ -58,7 +58,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do Process.sleep(1000) {:ok, _comment} = - CMS.create_article_comment(:blog, blog.id, "blog comment", blog.author.user) + CMS.create_article_comment(:blog, blog.id, mock_comment(), blog.author.user) {:ok, blog} = ORM.find(Blog, blog.id, preload: :article_comments) @@ -147,8 +147,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do describe "[article comment upvotes]" do test "user can upvote a blog comment", ~m(user blog)a do - comment = "blog_comment" - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) @@ -159,8 +158,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "article author upvote blog comment will have flag", ~m(blog user)a do - comment = "blog_comment" - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, author_user} = ORM.find(User, blog.author.user.id) CMS.upvote_article_comment(comment.id, author_user) @@ -170,8 +168,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "user upvote blog comment will add id to upvoted_user_ids", ~m(blog user)a do - comment = "blog_comment" - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, comment} = CMS.upvote_article_comment(comment.id, user) assert user.id in comment.meta.upvoted_user_ids @@ -179,8 +176,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do test "user undo upvote blog comment will remove id from upvoted_user_ids", ~m(blog user user2)a do - comment = "blog_comment" - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, _comment} = CMS.upvote_article_comment(comment.id, user) {:ok, comment} = CMS.upvote_article_comment(comment.id, user2) @@ -194,16 +190,14 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "user upvote a already-upvoted comment fails", ~m(user blog)a do - comment = "blog_comment" - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) {:error, _} = CMS.upvote_article_comment(comment.id, user) end test "upvote comment should inc the comment's upvotes_count", ~m(user user2 blog)a do - comment = "blog_comment" - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert comment.upvotes_count == 0 diff --git a/test/groupher_server/cms/comments/repo_comment_test.exs b/test/groupher_server/cms/comments/repo_comment_test.exs index 324cea380..00b9c010c 100644 --- a/test/groupher_server/cms/comments/repo_comment_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_test.exs @@ -148,7 +148,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do describe "[article comment upvotes]" do test "user can upvote a repo comment", ~m(user repo)a do comment = "repo_comment" - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) @@ -160,7 +160,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do test "article author upvote repo comment will have flag", ~m(repo user)a do comment = "repo_comment" - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, author_user} = ORM.find(User, repo.author.user.id) CMS.upvote_article_comment(comment.id, author_user) @@ -171,7 +171,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do test "user upvote repo comment will add id to upvoted_user_ids", ~m(repo user)a do comment = "repo_comment" - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, comment} = CMS.upvote_article_comment(comment.id, user) assert user.id in comment.meta.upvoted_user_ids @@ -180,7 +180,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do test "user undo upvote repo comment will remove id from upvoted_user_ids", ~m(repo user user2)a do comment = "repo_comment" - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _comment} = CMS.upvote_article_comment(comment.id, user) {:ok, comment} = CMS.upvote_article_comment(comment.id, user2) @@ -195,7 +195,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do test "user upvote a already-upvoted comment fails", ~m(user repo)a do comment = "repo_comment" - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) {:error, _} = CMS.upvote_article_comment(comment.id, user) @@ -203,7 +203,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do test "upvote comment should inc the comment's upvotes_count", ~m(user user2 repo)a do comment = "repo_comment" - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, comment, user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert comment.upvotes_count == 0 diff --git a/test/groupher_server_web/query/cms/comments/job_comment_test.exs b/test/groupher_server_web/query/cms/comments/job_comment_test.exs index e11dd398a..136255176 100644 --- a/test/groupher_server_web/query/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/job_comment_test.exs @@ -39,7 +39,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do thread = :job Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(thread, job.id, comment, user) + {:ok, comment} = CMS.create_article_comment(thread, job.id, mock_comment(), user) acc ++ [comment] end) @@ -244,7 +244,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do thread = :job Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, value} = CMS.create_article_comment(thread, job.id, comment, user) + {:ok, value} = CMS.create_article_comment(thread, job.id, mock_comment(), user) acc ++ [value] end) @@ -650,7 +650,7 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do thread = :job author_user = job.author.user - {:ok, parent_comment} = CMS.create_article_comment(thread, job.id, comment, user) + {:ok, parent_comment} = CMS.create_article_comment(thread, job.id, mock_comment(), user) Enum.reduce(1..total_count, [], fn i, acc -> {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, "reply #{i}", user2) diff --git a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs index 77b1f67a4..af38895ed 100644 --- a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs @@ -37,7 +37,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do thread = :repo Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, comment} = CMS.create_article_comment(thread, repo.id, comment, user) + {:ok, comment} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) acc ++ [comment] end) @@ -242,7 +242,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do thread = :repo Enum.reduce(1..total_count, [], fn _, acc -> - {:ok, value} = CMS.create_article_comment(thread, repo.id, comment, user) + {:ok, value} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) acc ++ [value] end) @@ -648,7 +648,7 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do thread = :repo author_user = repo.author.user - {:ok, parent_comment} = CMS.create_article_comment(thread, repo.id, comment, user) + {:ok, parent_comment} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) Enum.reduce(1..total_count, [], fn i, acc -> {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, "reply #{i}", user2) From 66c3dd81e1925cd8922bac07c47b3b1b8c8d5984 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 23:07:14 +0800 Subject: [PATCH 17/31] refactor(editor-workflow): rich test for comment test wip --- lib/groupher_server_web/resolvers/cms_resolver.ex | 12 ++++++------ .../cms/comments/repo_comment_test.exs | 6 ------ .../mutation/cms/comments/blog_comment_test.exs | 12 ++++++++---- .../mutation/cms/comments/job_comment_test.exs | 14 ++++++++------ .../mutation/cms/comments/post_comment_test.exs | 14 ++++++++------ .../mutation/cms/comments/repo_comment_test.exs | 14 ++++++++------ .../query/cms/comments/job_comment_test.exs | 3 --- .../query/cms/comments/post_comment_test.exs | 4 ---- .../query/cms/comments/repo_comment_test.exs | 3 --- 9 files changed, 38 insertions(+), 44 deletions(-) diff --git a/lib/groupher_server_web/resolvers/cms_resolver.ex b/lib/groupher_server_web/resolvers/cms_resolver.ex index df7f0f7f7..05875392e 100644 --- a/lib/groupher_server_web/resolvers/cms_resolver.ex +++ b/lib/groupher_server_web/resolvers/cms_resolver.ex @@ -294,13 +294,13 @@ defmodule GroupherServerWeb.Resolvers.CMS do CMS.paged_article_comments_participators(thread, id, filter) end - def create_article_comment(_root, ~m(thread id content)a, %{context: %{cur_user: user}}) do - CMS.create_article_comment(thread, id, content, user) + def create_article_comment(_root, ~m(thread id body)a, %{context: %{cur_user: user}}) do + CMS.create_article_comment(thread, id, body, user) end - def update_article_comment(_root, ~m(content passport_source)a, _info) do + def update_article_comment(_root, ~m(body passport_source)a, _info) do comment = passport_source - CMS.update_article_comment(comment, content) + CMS.update_article_comment(comment, body) end def delete_article_comment(_root, ~m(passport_source)a, _info) do @@ -308,8 +308,8 @@ defmodule GroupherServerWeb.Resolvers.CMS do CMS.delete_article_comment(comment) end - def reply_article_comment(_root, ~m(id content)a, %{context: %{cur_user: user}}) do - CMS.reply_article_comment(id, content, user) + def reply_article_comment(_root, ~m(id body)a, %{context: %{cur_user: user}}) do + CMS.reply_article_comment(id, body, user) end def upvote_article_comment(_root, ~m(id)a, %{context: %{cur_user: user}}) do diff --git a/test/groupher_server/cms/comments/repo_comment_test.exs b/test/groupher_server/cms/comments/repo_comment_test.exs index 00b9c010c..acf64231b 100644 --- a/test/groupher_server/cms/comments/repo_comment_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_test.exs @@ -147,7 +147,6 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do describe "[article comment upvotes]" do test "user can upvote a repo comment", ~m(user repo)a do - comment = "repo_comment" {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) @@ -159,7 +158,6 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "article author upvote repo comment will have flag", ~m(repo user)a do - comment = "repo_comment" {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, author_user} = ORM.find(User, repo.author.user.id) @@ -170,7 +168,6 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "user upvote repo comment will add id to upvoted_user_ids", ~m(repo user)a do - comment = "repo_comment" {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, comment} = CMS.upvote_article_comment(comment.id, user) @@ -179,7 +176,6 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do test "user undo upvote repo comment will remove id from upvoted_user_ids", ~m(repo user user2)a do - comment = "repo_comment" {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _comment} = CMS.upvote_article_comment(comment.id, user) {:ok, comment} = CMS.upvote_article_comment(comment.id, user2) @@ -194,7 +190,6 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "user upvote a already-upvoted comment fails", ~m(user repo)a do - comment = "repo_comment" {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) @@ -202,7 +197,6 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "upvote comment should inc the comment's upvotes_count", ~m(user user2 repo)a do - comment = "repo_comment" {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, comment} = ORM.find(ArticleComment, comment.id) assert comment.upvotes_count == 0 diff --git a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs index 5e985c59b..22bc804c8 100644 --- a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs @@ -27,13 +27,15 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do } } """ + @tag :wip test "write article comment to a exsit blog", ~m(blog user_conn)a do variables = %{thread: "BLOG", id: blog.id, body: mock_comment()} result = user_conn |> mutation_result(@write_comment_query, variables, "createArticleComment") - assert result["bodyHtml"] == comment + assert result["bodyHtml"] |> String.contains?(~s(

String.contains?(~s(comment

)) end @reply_comment_query """ @@ -46,13 +48,14 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do """ test "login user can reply to a comment", ~m(blog user user_conn)a do {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) - variables = %{id: comment.id, body: mock_comment()} + variables = %{id: comment.id, body: mock_comment("reply comment")} result = user_conn |> mutation_result(@reply_comment_query, variables, "replyArticleComment") - assert result["bodyHtml"] == "reply content" + assert result["bodyHtml"] |> String.contains?(~s(

String.contains?(~s(reply comment

)) end @update_comment_query """ @@ -76,7 +79,8 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do updated = owner_conn |> mutation_result(@update_comment_query, variables, "updateArticleComment") - assert updated["bodyHtml"] == "updated comment" + assert result["bodyHtml"] |> String.contains?(~s(

String.contains?(~s(updated comment

)) end @delete_comment_query """ diff --git a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs index 4ee0a9e2c..04a1fa6a4 100644 --- a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs @@ -28,13 +28,13 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } """ test "write article comment to a exsit job", ~m(job user_conn)a do - comment = "a test comment" - variables = %{thread: "JOB", id: job.id, content: comment} + variables = %{thread: "JOB", id: job.id, body: mock_comment()} result = user_conn |> mutation_result(@write_comment_query, variables, "createArticleComment") - assert result["bodyHtml"] == comment + assert result["bodyHtml"] |> String.contains?(~s(

String.contains?(~s(comment

)) end @reply_comment_query """ @@ -47,13 +47,14 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do """ test "login user can reply to a comment", ~m(job user user_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) - variables = %{id: comment.id, body: mock_comment()} + variables = %{id: comment.id, body: mock_comment("reply comment")} result = user_conn |> mutation_result(@reply_comment_query, variables, "replyArticleComment") - assert result["bodyHtml"] == "reply content" + assert result["bodyHtml"] |> String.contains?(~s(

String.contains?(~s(reply comment

)) end @update_comment_query """ @@ -77,7 +78,8 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do updated = owner_conn |> mutation_result(@update_comment_query, variables, "updateArticleComment") - assert updated["bodyHtml"] == "updated comment" + assert result["bodyHtml"] |> String.contains?(~s(

String.contains?(~s(updated comment

)) end @delete_comment_query """ diff --git a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs index 17c75a69c..a1773d980 100644 --- a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs @@ -28,13 +28,13 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } """ test "write article comment to a exsit post", ~m(post user_conn)a do - comment = "a test comment" - variables = %{thread: "POST", id: post.id, content: comment} + variables = %{thread: "POST", id: post.id, body: mock_comment()} result = user_conn |> mutation_result(@write_comment_query, variables, "createArticleComment") - assert result["bodyHtml"] == comment + assert result["bodyHtml"] |> String.contains?(~s(

String.contains?(~s(comment

)) end @reply_comment_query """ @@ -47,13 +47,14 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do """ test "login user can reply to a comment", ~m(post user user_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) - variables = %{id: comment.id, body: mock_comment()} + variables = %{id: comment.id, body: mock_comment("reply comment")} result = user_conn |> mutation_result(@reply_comment_query, variables, "replyArticleComment") - assert result["bodyHtml"] == "reply content" + assert result["bodyHtml"] |> String.contains?(~s(

String.contains?(~s(reply comment

)) end @update_comment_query """ @@ -77,7 +78,8 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do updated = owner_conn |> mutation_result(@update_comment_query, variables, "updateArticleComment") - assert updated["bodyHtml"] == "updated comment" + assert result["bodyHtml"] |> String.contains?(~s(

String.contains?(~s(updated comment

)) end @delete_comment_query """ diff --git a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs index 5eed0f5ec..b3249b66d 100644 --- a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs @@ -28,13 +28,13 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do } """ test "write article comment to a exsit repo", ~m(repo user_conn)a do - comment = "a test comment" - variables = %{thread: "REPO", id: repo.id, content: comment} + variables = %{thread: "REPO", id: repo.id, body: mock_comment()} result = user_conn |> mutation_result(@write_comment_query, variables, "createArticleComment") - assert result["bodyHtml"] == comment + assert result["bodyHtml"] |> String.contains?(~s(

String.contains?(~s(comment

)) end @reply_comment_query """ @@ -47,13 +47,14 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do """ test "login user can reply to a comment", ~m(repo user user_conn)a do {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - variables = %{id: comment.id, body: mock_comment()} + variables = %{id: comment.id, body: mock_comment("reply comment")} result = user_conn |> mutation_result(@reply_comment_query, variables, "replyArticleComment") - assert result["bodyHtml"] == "reply content" + assert result["bodyHtml"] |> String.contains?(~s(

String.contains?(~s(reply comment

)) end @update_comment_query """ @@ -77,7 +78,8 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do updated = owner_conn |> mutation_result(@update_comment_query, variables, "updateArticleComment") - assert updated["bodyHtml"] == "updated comment" + assert result["bodyHtml"] |> String.contains?(~s(

String.contains?(~s(updated comment

)) end @delete_comment_query """ diff --git a/test/groupher_server_web/query/cms/comments/job_comment_test.exs b/test/groupher_server_web/query/cms/comments/job_comment_test.exs index 136255176..0c9de33fc 100644 --- a/test/groupher_server_web/query/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/job_comment_test.exs @@ -34,7 +34,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do test "guest user can get comment participators after comment created", ~m(guest_conn job user user2)a do - comment = "test comment" total_count = 5 thread = :job @@ -239,7 +238,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do end test "guest user can get paged comment for job", ~m(guest_conn job user)a do - comment = "test comment" total_count = 30 thread = :job @@ -644,7 +642,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do """ test "guest user can get paged replies", ~m(guest_conn job user user2)a do - comment = "test comment" total_count = 2 page_size = 10 thread = :job diff --git a/test/groupher_server_web/query/cms/comments/post_comment_test.exs b/test/groupher_server_web/query/cms/comments/post_comment_test.exs index b145d4b5e..12c173437 100644 --- a/test/groupher_server_web/query/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/post_comment_test.exs @@ -34,10 +34,8 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do } } """ - test "guest user can get comment participators after comment created", ~m(guest_conn post user user2)a do - comment = "test comment" total_count = 5 thread = :post @@ -242,7 +240,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do end test "guest user can get paged comment for post", ~m(guest_conn post user)a do - comment = "test comment" total_count = 30 thread = :post @@ -685,7 +682,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do """ test "guest user can get paged replies", ~m(guest_conn post user user2)a do - comment = "test comment" total_count = 2 page_size = 10 thread = :post diff --git a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs index af38895ed..c086296ed 100644 --- a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs @@ -32,7 +32,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do """ test "guest user can get comment participators after comment created", ~m(guest_conn repo user user2)a do - comment = "test comment" total_count = 5 thread = :repo @@ -237,7 +236,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do end test "guest user can get paged comment for repo", ~m(guest_conn repo user)a do - comment = "test comment" total_count = 30 thread = :repo @@ -642,7 +640,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do """ test "guest user can get paged replies", ~m(guest_conn repo user user2)a do - comment = "test comment" total_count = 2 page_size = 10 thread = :repo From 43e926a410f54bb57cb01d5e9210f3066f819375 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Wed, 9 Jun 2021 23:13:21 +0800 Subject: [PATCH 18/31] refactor(editor-workflow): rich test for comment test wip --- .../mutation/cms/comments/blog_comment_test.exs | 2 +- .../mutation/cms/comments/job_comment_test.exs | 2 +- .../mutation/cms/comments/post_comment_test.exs | 2 +- .../mutation/cms/comments/repo_comment_test.exs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs index 22bc804c8..b3804542d 100644 --- a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs @@ -76,7 +76,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do assert guest_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:account_login)) - updated = + result = owner_conn |> mutation_result(@update_comment_query, variables, "updateArticleComment") assert result["bodyHtml"] |> String.contains?(~s(

mutation_get_error?(@update_comment_query, variables, ecode(:account_login)) - updated = + result = owner_conn |> mutation_result(@update_comment_query, variables, "updateArticleComment") assert result["bodyHtml"] |> String.contains?(~s(

mutation_get_error?(@update_comment_query, variables, ecode(:account_login)) - updated = + result = owner_conn |> mutation_result(@update_comment_query, variables, "updateArticleComment") assert result["bodyHtml"] |> String.contains?(~s(

mutation_get_error?(@update_comment_query, variables, ecode(:account_login)) - updated = + result = owner_conn |> mutation_result(@update_comment_query, variables, "updateArticleComment") assert result["bodyHtml"] |> String.contains?(~s(

Date: Wed, 9 Jun 2021 23:27:16 +0800 Subject: [PATCH 19/31] refactor(editor-workflow): fix comment test --- test/groupher_server/cms/comments/post_comment_test.exs | 8 +++++--- .../mutation/cms/articles/blog_test.exs | 1 + .../query/cms/comments/job_comment_test.exs | 8 +++++--- .../query/cms/comments/post_comment_test.exs | 8 +++++--- .../query/cms/comments/repo_comment_test.exs | 8 +++++--- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 2a3175d70..31d8f9242 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -26,7 +26,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end describe "[basic article comment]" do - @tag :wip test "post are supported by article comment.", ~m(user post)a do {:ok, post_comment_1} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, post_comment_2} = CMS.create_article_comment(:post, post.id, mock_comment(), user) @@ -783,6 +782,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert answers |> List.first() |> Map.get(:id) == comment2.id end + @tag :wip test "update a solution should also update post's solution digest", ~m(user community)a do post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true}) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) @@ -790,13 +790,15 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) post_author = post.author.user - {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), post_author) + {:ok, comment} = + CMS.create_article_comment(:post, post.id, mock_comment("solution"), post_author) + {:ok, comment} = CMS.mark_comment_solution(comment.id, post_author) {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) assert post.solution_digest == "solution" - {:ok, _comment} = CMS.update_article_comment(comment, "new solution") + {:ok, _comment} = CMS.update_article_comment(comment, mock_comment("new solution")) {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) assert post.solution_digest == "new solution" end diff --git a/test/groupher_server_web/mutation/cms/articles/blog_test.exs b/test/groupher_server_web/mutation/cms/articles/blog_test.exs index 051c3242e..f3a25b9ee 100644 --- a/test/groupher_server_web/mutation/cms/articles/blog_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/blog_test.exs @@ -67,6 +67,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do assert created["id"] == to_string(found.id) end + @tag :wip test "create blog should excape xss attracts" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) diff --git a/test/groupher_server_web/query/cms/comments/job_comment_test.exs b/test/groupher_server_web/query/cms/comments/job_comment_test.exs index 0c9de33fc..3a1fbe550 100644 --- a/test/groupher_server_web/query/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/job_comment_test.exs @@ -209,7 +209,8 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do acc ++ [comment] end) - {:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent_content", user) + {:ok, parent_comment} = + CMS.create_article_comment(:job, job.id, mock_comment("parent_comment"), user) {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) @@ -650,13 +651,14 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do {:ok, parent_comment} = CMS.create_article_comment(thread, job.id, mock_comment(), user) Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, "reply #{i}", user2) + {:ok, reply_comment} = + CMS.reply_article_comment(parent_comment.id, mock_comment("reply #{i}"), user2) acc ++ [reply_comment] end) {:ok, author_reply_comment} = - CMS.reply_article_comment(parent_comment.id, "author reply", author_user) + CMS.reply_article_comment(parent_comment.id, mock_comment("author reply"), author_user) variables = %{id: parent_comment.id, filter: %{page: 1, size: page_size}} results = guest_conn |> query_result(@query, variables, "pagedCommentReplies") diff --git a/test/groupher_server_web/query/cms/comments/post_comment_test.exs b/test/groupher_server_web/query/cms/comments/post_comment_test.exs index 12c173437..488a01f27 100644 --- a/test/groupher_server_web/query/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/post_comment_test.exs @@ -211,7 +211,8 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do acc ++ [comment] end) - {:ok, parent_comment} = CMS.create_article_comment(:post, post.id, "parent_content", user) + {:ok, parent_comment} = + CMS.create_article_comment(:post, post.id, mock_comment("parent_comment"), user) {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) @@ -690,13 +691,14 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do {:ok, parent_comment} = CMS.create_article_comment(thread, post.id, mock_comment(), user) Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, "reply #{i}", user2) + {:ok, reply_comment} = + CMS.reply_article_comment(parent_comment.id, mock_comment("reply #{i}"), user2) acc ++ [reply_comment] end) {:ok, author_reply_comment} = - CMS.reply_article_comment(parent_comment.id, "author reply", author_user) + CMS.reply_article_comment(parent_comment.id, mock_comment("author reply"), author_user) variables = %{id: parent_comment.id, filter: %{page: 1, size: page_size}} results = guest_conn |> query_result(@query, variables, "pagedCommentReplies") diff --git a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs index c086296ed..f8fec8db9 100644 --- a/test/groupher_server_web/query/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/repo_comment_test.exs @@ -207,7 +207,8 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do acc ++ [comment] end) - {:ok, parent_comment} = CMS.create_article_comment(:repo, repo.id, "parent_content", user) + {:ok, parent_comment} = + CMS.create_article_comment(:repo, repo.id, mock_comment("parent_comment"), user) {:ok, replyed_comment_1} = CMS.reply_article_comment(parent_comment.id, mock_comment(), user2) @@ -648,13 +649,14 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do {:ok, parent_comment} = CMS.create_article_comment(thread, repo.id, mock_comment(), user) Enum.reduce(1..total_count, [], fn i, acc -> - {:ok, reply_comment} = CMS.reply_article_comment(parent_comment.id, "reply #{i}", user2) + {:ok, reply_comment} = + CMS.reply_article_comment(parent_comment.id, mock_comment("reply #{i}"), user2) acc ++ [reply_comment] end) {:ok, author_reply_comment} = - CMS.reply_article_comment(parent_comment.id, "author reply", author_user) + CMS.reply_article_comment(parent_comment.id, mock_comment("author reply"), author_user) variables = %{id: parent_comment.id, filter: %{page: 1, size: page_size}} results = guest_conn |> query_result(@query, variables, "pagedCommentReplies") From fa9a36c3ba9015ea362ec668fdd3ca97c8960a6a Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 10 Jun 2021 01:07:51 +0800 Subject: [PATCH 20/31] refactor(editor-workflow): fix comment test --- .../cms/delegates/article_curd.ex | 2 +- .../cms/comments/post_comment_test.exs | 2 +- .../mutation/cms/articles/blog_test.exs | 19 ++++++++++-- .../mutation/cms/articles/job_test.exs | 20 +++++++++++-- .../mutation/cms/articles/post_test.exs | 22 ++++++++++++-- .../mutation/cms/articles/repo_test.exs | 5 ++-- .../cms/comments/blog_comment_test.exs | 2 +- test/support/assert_helper.ex | 7 ----- test/support/factory.ex | 30 ++++++++----------- 9 files changed, 72 insertions(+), 37 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index 778937b6c..f5e94b686 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -455,7 +455,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do defp result({:ok, %{update_article_meta: result}}), do: {:ok, result} defp result({:error, :create_article, _result, _steps}) do - {:error, [message: "create cms article author", code: ecode(:create_fails)]} + {:error, [message: "create article", code: ecode(:create_fails)]} end defp result({:error, :mirror_article, _result, _steps}) do diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 31d8f9242..84e6bcdc3 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -782,7 +782,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert answers |> List.first() |> Map.get(:id) == comment2.id end - @tag :wip + @tag :wip2 test "update a solution should also update post's solution digest", ~m(user community)a do post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true}) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) diff --git a/test/groupher_server_web/mutation/cms/articles/blog_test.exs b/test/groupher_server_web/mutation/cms/articles/blog_test.exs index f3a25b9ee..d7f1c7fa9 100644 --- a/test/groupher_server_web/mutation/cms/articles/blog_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/blog_test.exs @@ -73,13 +73,28 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) - blog_attr = mock_attrs(:blog, %{body: assert_v(:xss_string)}) + blog_attr = mock_attrs(:blog, %{body: mock_xss_string()}) variables = blog_attr |> Map.merge(%{communityId: community.id}) |> camelize_map_key created = user_conn |> mutation_result(@create_blog_query, variables, "createBlog") {:ok, blog} = ORM.find(Blog, created["id"]) - assert blog.body == assert_v(:xss_safe_string) + assert not String.contains?(blog.body_html, "script") + end + + @tag :wip + test "create blog should excape xss attracts 2" do + {:ok, user} = db_insert(:user) + user_conn = simu_conn(:user, user) + + {:ok, community} = db_insert(:community) + + blog_attr = mock_attrs(:blog, %{body: mock_xss_string(:safe)}) + variables = blog_attr |> Map.merge(%{communityId: community.id}) |> camelize_map_key + created = user_conn |> mutation_result(@create_blog_query, variables, "createBlog") + {:ok, blog} = ORM.find(Blog, created["id"]) + + assert String.contains?(blog.body_html, "<script>blackmail</script>") end @query """ diff --git a/test/groupher_server_web/mutation/cms/articles/job_test.exs b/test/groupher_server_web/mutation/cms/articles/job_test.exs index dc7185ce9..34a260ca0 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_test.exs @@ -72,18 +72,34 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do assert created["id"] == to_string(found.id) end + @tag :wip test "create job should excape xss attracts" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) - job_attr = mock_attrs(:job, %{body: assert_v(:xss_string)}) + job_attr = mock_attrs(:job, %{body: mock_xss_string()}) variables = job_attr |> Map.merge(%{communityId: community.id}) |> camelize_map_key created = user_conn |> mutation_result(@create_job_query, variables, "createJob") {:ok, job} = ORM.find(Job, created["id"]) - assert job.body == assert_v(:xss_safe_string) + assert not String.contains?(job.body_html, "script") + end + + @tag :wip + test "create job should excape xss attracts 2" do + {:ok, user} = db_insert(:user) + user_conn = simu_conn(:user, user) + + {:ok, community} = db_insert(:community) + + job_attr = mock_attrs(:job, %{body: mock_xss_string(:safe)}) + variables = job_attr |> Map.merge(%{communityId: community.id}) |> camelize_map_key + created = user_conn |> mutation_result(@create_job_query, variables, "createJob") + {:ok, job} = ORM.find(Job, created["id"]) + + assert String.contains?(job.body_html, "<script>blackmail</script>") end test "can create job with mentionUsers" do diff --git a/test/groupher_server_web/mutation/cms/articles/post_test.exs b/test/groupher_server_web/mutation/cms/articles/post_test.exs index 00af5cf9d..db2d56b09 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_test.exs @@ -63,18 +63,34 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do assert {:ok, _} = ORM.find_by(Author, user_id: user.id) end + @tag :wip test "create post should excape xss attracts" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) - post_attr = mock_attrs(:post, %{body: assert_v(:xss_string)}) - variables = post_attr |> Map.merge(%{communityId: community.id}) + post_attr = mock_attrs(:post, %{body: mock_xss_string()}) + variables = post_attr |> Map.merge(%{communityId: community.id}) |> camelize_map_key + created = user_conn |> mutation_result(@create_post_query, variables, "createPost") + {:ok, post} = ORM.find(Post, created["id"]) + + assert not String.contains?(post.body_html, "script") + end + + @tag :wip + test "create post should excape xss attracts 2" do + {:ok, user} = db_insert(:user) + user_conn = simu_conn(:user, user) + + {:ok, community} = db_insert(:community) + + post_attr = mock_attrs(:post, %{body: mock_xss_string(:safe)}) + variables = post_attr |> Map.merge(%{communityId: community.id}) |> camelize_map_key created = user_conn |> mutation_result(@create_post_query, variables, "createPost") {:ok, post} = ORM.find(Post, created["id"]) - assert post.body == assert_v(:xss_safe_string) + assert String.contains?(post.body_html, "<script>blackmail</script>") end # NOTE: this test is IMPORTANT, cause json_codec: Jason in router will cause diff --git a/test/groupher_server_web/mutation/cms/articles/repo_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_test.exs index b3217eb16..434a792f5 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_test.exs @@ -155,18 +155,19 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do # assert updated["readme"] == "new readme" end + @tag :wip test "create repo should excape xss attracts" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) {:ok, community} = db_insert(:community) - repo_attr = mock_attrs(:repo, %{readme: assert_v(:xss_string)}) + repo_attr = mock_attrs(:repo, %{body: mock_xss_string()}) variables = repo_attr |> Map.merge(%{communityId: community.id}) |> camelize_map_key created = user_conn |> mutation_result(@create_repo_query, variables, "createRepo") {:ok, repo} = ORM.find(Repo, created["id"]) - assert repo.readme == assert_v(:xss_safe_string) + assert not String.contains?(repo.body_html, "script") end test "unauth user update git-repo fails", ~m(user_conn guest_conn repo)a do diff --git a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs index b3804542d..e461ee577 100644 --- a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs @@ -27,7 +27,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do } } """ - @tag :wip + @tag :wip2 test "write article comment to a exsit blog", ~m(blog user_conn)a do variables = %{thread: "BLOG", id: blog.id, body: mock_comment()} diff --git a/test/support/assert_helper.ex b/test/support/assert_helper.ex index cda8eb490..1b358f421 100644 --- a/test/support/assert_helper.ex +++ b/test/support/assert_helper.ex @@ -27,13 +27,6 @@ defmodule GroupherServer.Test.AssertHelper do end def assert_v(:inner_page_size), do: @inner_page_size - def assert_v(:page_size), do: @page_size - - def assert_v(:xss_string), do: "" - - def assert_v(:xss_safe_string), - # "<script>alert("hello,world")</script>" - do: "" def is_valid_kv?(obj, key, :list) when is_map(obj) do obj = map_key_stringify(obj) diff --git a/test/support/factory.ex b/test/support/factory.ex index f03f14db2..e6086ea3e 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -28,7 +28,8 @@ defmodule GroupherServer.Support.Factory do @default_article_meta CMS.Model.Embeds.ArticleMeta.default_meta() @default_emotions CMS.Model.Embeds.ArticleCommentEmotion.default_emotions() - def mock_comment(text \\ "comment") do + # simulate editor.js fmt rich text + def mock_rich_text(text \\ "text") do """ { "time": 111, @@ -46,23 +47,16 @@ defmodule GroupherServer.Support.Factory do """ end - # simulate editor.js fmt rich text - defp mock_rich_text() do - """ - { - "time": 111, - "blocks": [ - { - "id": "lldjfiek", - "type": "paragraph", - "data": { - "text": "coderplanets is awesome" - } - } - ], - "version": "2.22.0" - } - """ + def mock_xss_string(:safe) do + mock_rich_text("<script>blackmail</script>") + end + + def mock_xss_string(text \\ "blackmail") do + mock_rich_text("") + end + + def mock_comment(text \\ "comment") do + mock_rich_text(text) end defp mock_meta(:post) do From 79ad4b9271e51482e500c605d0b130efda39bda5 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 10 Jun 2021 01:14:24 +0800 Subject: [PATCH 21/31] refactor(editor-workflow): fix comment test --- test/groupher_server/cms/comments/blog_comment_test.exs | 6 ++---- test/groupher_server/cms/comments/post_comment_test.exs | 6 ++---- test/groupher_server/cms/comments/repo_comment_test.exs | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/test/groupher_server/cms/comments/blog_comment_test.exs b/test/groupher_server/cms/comments/blog_comment_test.exs index 67e083490..190db8ef4 100644 --- a/test/groupher_server/cms/comments/blog_comment_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_test.exs @@ -209,8 +209,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "user can undo upvote a blog comment", ~m(user blog)a do - content = "blog_comment" - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, content, user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) {:ok, comment} = ORM.find(ArticleComment, comment.id, preload: :upvotes) @@ -221,8 +220,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do end test "user can undo upvote a blog comment with no upvote", ~m(user blog)a do - content = "blog_comment" - {:ok, comment} = CMS.create_article_comment(:blog, blog.id, content, user) + {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) {:ok, comment} = CMS.undo_upvote_article_comment(comment.id, user) assert 0 == comment.upvotes_count diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 84e6bcdc3..96726c884 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -209,8 +209,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "user can undo upvote a post comment", ~m(user post)a do - content = "post_comment" - {:ok, comment} = CMS.create_article_comment(:post, post.id, content, user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) {:ok, comment} = ORM.find(ArticleComment, comment.id, preload: :upvotes) @@ -221,8 +220,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do end test "user can undo upvote a post comment with no upvote", ~m(user post)a do - content = "post_comment" - {:ok, comment} = CMS.create_article_comment(:post, post.id, content, user) + {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, comment} = CMS.undo_upvote_article_comment(comment.id, user) assert 0 == comment.upvotes_count diff --git a/test/groupher_server/cms/comments/repo_comment_test.exs b/test/groupher_server/cms/comments/repo_comment_test.exs index acf64231b..e0a3e4e61 100644 --- a/test/groupher_server/cms/comments/repo_comment_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_test.exs @@ -209,8 +209,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "user can undo upvote a repo comment", ~m(user repo)a do - content = "repo_comment" - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, content, user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) CMS.upvote_article_comment(comment.id, user) {:ok, comment} = ORM.find(ArticleComment, comment.id, preload: :upvotes) @@ -221,8 +220,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do end test "user can undo upvote a repo comment with no upvote", ~m(user repo)a do - content = "repo_comment" - {:ok, comment} = CMS.create_article_comment(:repo, repo.id, content, user) + {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, comment} = CMS.undo_upvote_article_comment(comment.id, user) assert 0 == comment.upvotes_count From 1d30730a230fa60e8d7f35eb554225a0be6a76bf Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 10 Jun 2021 01:26:44 +0800 Subject: [PATCH 22/31] refactor(editor-workflow): fix comment test --- .../cms/comments/blog_comment_replies_test.exs | 4 ++-- .../groupher_server/cms/comments/job_comment_replies_test.exs | 4 ++-- .../cms/comments/post_comment_replies_test.exs | 4 ++-- test/groupher_server/cms/comments/post_comment_test.exs | 4 ++-- .../cms/comments/repo_comment_replies_test.exs | 4 ++-- test/groupher_server/cms/comments/repo_comment_test.exs | 2 +- .../mutation/cms/comments/blog_comment_test.exs | 2 +- .../mutation/cms/comments/job_comment_test.exs | 2 +- .../mutation/cms/comments/post_comment_test.exs | 2 +- .../mutation/cms/comments/repo_comment_test.exs | 2 +- .../query/cms/abuse_reports/post_report_test.exs | 1 + .../query/cms/comments/post_comment_test.exs | 4 +++- .../query/cms/paged_articles/paged_jobs_test.exs | 2 +- .../query/cms/paged_articles/paged_posts_test.exs | 2 +- .../query/cms/paged_articles/paged_repos_test.exs | 2 +- 15 files changed, 22 insertions(+), 19 deletions(-) diff --git a/test/groupher_server/cms/comments/blog_comment_replies_test.exs b/test/groupher_server/cms/comments/blog_comment_replies_test.exs index d96b9dce6..f518c16d2 100644 --- a/test/groupher_server/cms/comments/blog_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_replies_test.exs @@ -113,7 +113,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do reply_comment_list = Enum.reduce(1..total_reply_count, [], fn n, acc -> {:ok, replyed_comment} = - CMS.reply_article_comment(parent_comment.id, "reply_content_#{n}", user) + CMS.reply_article_comment(parent_comment.id, mock_comment("reply_content_#{n}"), user) acc ++ [replyed_comment] end) @@ -162,7 +162,7 @@ defmodule GroupherServer.Test.CMS.Comments.BlogCommentReplies do reply_comment_list = Enum.reduce(1..total_reply_count, [], fn n, acc -> {:ok, replyed_comment} = - CMS.reply_article_comment(parent_comment.id, "reply_content_#{n}", user) + CMS.reply_article_comment(parent_comment.id, mock_comment("reply_content_#{n}"), user) acc ++ [replyed_comment] end) diff --git a/test/groupher_server/cms/comments/job_comment_replies_test.exs b/test/groupher_server/cms/comments/job_comment_replies_test.exs index 5b82a984e..ecbac42fb 100644 --- a/test/groupher_server/cms/comments/job_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/job_comment_replies_test.exs @@ -113,7 +113,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do reply_comment_list = Enum.reduce(1..total_reply_count, [], fn n, acc -> {:ok, replyed_comment} = - CMS.reply_article_comment(parent_comment.id, "reply_content_#{n}", user) + CMS.reply_article_comment(parent_comment.id, mock_comment("reply_content_#{n}"), user) acc ++ [replyed_comment] end) @@ -162,7 +162,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do reply_comment_list = Enum.reduce(1..total_reply_count, [], fn n, acc -> {:ok, replyed_comment} = - CMS.reply_article_comment(parent_comment.id, "reply_content_#{n}", user) + CMS.reply_article_comment(parent_comment.id, mock_comment("reply_content_#{n}"), user) acc ++ [replyed_comment] end) diff --git a/test/groupher_server/cms/comments/post_comment_replies_test.exs b/test/groupher_server/cms/comments/post_comment_replies_test.exs index 3d08b2693..3ef1ee014 100644 --- a/test/groupher_server/cms/comments/post_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/post_comment_replies_test.exs @@ -113,7 +113,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do reply_comment_list = Enum.reduce(1..total_reply_count, [], fn n, acc -> {:ok, replyed_comment} = - CMS.reply_article_comment(parent_comment.id, "reply_content_#{n}", user) + CMS.reply_article_comment(parent_comment.id, mock_comment("reply_content_#{n}"), user) acc ++ [replyed_comment] end) @@ -162,7 +162,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostCommentReplies do reply_comment_list = Enum.reduce(1..total_reply_count, [], fn n, acc -> {:ok, replyed_comment} = - CMS.reply_article_comment(parent_comment.id, "reply_content_#{n}", user) + CMS.reply_article_comment(parent_comment.id, mock_comment("reply_content_#{n}"), user) acc ++ [replyed_comment] end) diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 96726c884..098ca954f 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -58,7 +58,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do Process.sleep(1000) {:ok, _comment} = - CMS.create_article_comment(:post, post.id, "post comment", post.author.user) + CMS.create_article_comment(:post, post.id, mock_comment(), post.author.user) {:ok, post} = ORM.find(Post, post.id, preload: :article_comments) @@ -780,7 +780,7 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert answers |> List.first() |> Map.get(:id) == comment2.id end - @tag :wip2 + @tag :wip test "update a solution should also update post's solution digest", ~m(user community)a do post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true}) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) diff --git a/test/groupher_server/cms/comments/repo_comment_replies_test.exs b/test/groupher_server/cms/comments/repo_comment_replies_test.exs index a5afceb19..6a8c283cc 100644 --- a/test/groupher_server/cms/comments/repo_comment_replies_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_replies_test.exs @@ -113,7 +113,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do reply_comment_list = Enum.reduce(1..total_reply_count, [], fn n, acc -> {:ok, replyed_comment} = - CMS.reply_article_comment(parent_comment.id, "reply_content_#{n}", user) + CMS.reply_article_comment(parent_comment.id, mock_comment("reply_content_#{n}"), user) acc ++ [replyed_comment] end) @@ -162,7 +162,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoCommentReplies do reply_comment_list = Enum.reduce(1..total_reply_count, [], fn n, acc -> {:ok, replyed_comment} = - CMS.reply_article_comment(parent_comment.id, "reply_content_#{n}", user) + CMS.reply_article_comment(parent_comment.id, mock_comment("reply_content_#{n}"), user) acc ++ [replyed_comment] end) diff --git a/test/groupher_server/cms/comments/repo_comment_test.exs b/test/groupher_server/cms/comments/repo_comment_test.exs index e0a3e4e61..2247d2b13 100644 --- a/test/groupher_server/cms/comments/repo_comment_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_test.exs @@ -58,7 +58,7 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do Process.sleep(1000) {:ok, _comment} = - CMS.create_article_comment(:repo, repo.id, "repo comment", repo.author.user) + CMS.create_article_comment(:repo, repo.id, mock_comment(), repo.author.user) {:ok, repo} = ORM.find(Repo, repo.id, preload: :article_comments) diff --git a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs index e461ee577..2aaa76e88 100644 --- a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs @@ -69,7 +69,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do test "only owner can update a exsit comment", ~m(blog user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) - variables = %{id: comment.id, content: mock_comment("updated comment")} + variables = %{id: comment.id, body: mock_comment("updated comment")} assert user_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:passport)) diff --git a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs index 0a70b8848..2676a87c9 100644 --- a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs @@ -68,7 +68,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do test "only owner can update a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) - variables = %{id: comment.id, content: mock_comment("updated comment")} + variables = %{id: comment.id, body: mock_comment("updated comment")} assert user_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:passport)) diff --git a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs index bd3bd8ef3..3d85a9aae 100644 --- a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs @@ -68,7 +68,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do test "only owner can update a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) - variables = %{id: comment.id, content: mock_comment("updated comment")} + variables = %{id: comment.id, body: mock_comment("updated comment")} assert user_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:passport)) diff --git a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs index d101b8486..eb76d1e07 100644 --- a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs @@ -68,7 +68,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do test "only owner can update a exsit comment", ~m(repo user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - variables = %{id: comment.id, content: mock_comment("updated comment")} + variables = %{id: comment.id, body: mock_comment("updated comment")} assert user_conn |> mutation_get_error?(@update_comment_query, variables, ecode(:passport)) diff --git a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs index 8ef2e2a40..fe676b800 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs @@ -91,6 +91,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostReport do assert results["totalCount"] == 1 end + @tag :wip test "support article_comment", ~m(guest_conn post user)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) diff --git a/test/groupher_server_web/query/cms/comments/post_comment_test.exs b/test/groupher_server_web/query/cms/comments/post_comment_test.exs index 488a01f27..c3a4e540c 100644 --- a/test/groupher_server_web/query/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/post_comment_test.exs @@ -309,7 +309,9 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do Process.sleep(1000) - {:ok, comment} = CMS.create_article_comment(thread, post.id, "solution", post_author) + {:ok, comment} = + CMS.create_article_comment(thread, post.id, mock_comment("solution"), post_author) + {:ok, solution_comment} = CMS.mark_comment_solution(comment.id, post_author) Process.sleep(1000) diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs index b666b1bfd..a61c57d78 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs @@ -444,7 +444,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedJobs do CMS.create_article_comment( :job, job_last_week.id, - "comment", + modk_comment(), job_last_week.author.user ) diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs index f1e78d297..291e112d0 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs @@ -351,7 +351,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do CMS.create_article_comment( :post, post_last_week.id, - "comment", + modk_comment(), post_last_week.author.user ) diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs index 8401485b2..593670e76 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs @@ -389,7 +389,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedRepos do CMS.create_article_comment( :repo, repo_last_week.id, - "comment", + modk_comment(), repo_last_week.author.user ) From 0197eabc5ca89ec01c9ac01bf5c2717e79aee197 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 10 Jun 2021 01:32:21 +0800 Subject: [PATCH 23/31] refactor(editor-workflow): fix comment test wip --- .../query/cms/paged_articles/paged_jobs_test.exs | 2 +- .../query/cms/paged_articles/paged_posts_test.exs | 2 +- .../query/cms/paged_articles/paged_repos_test.exs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs index a61c57d78..c2dd9f0f9 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_jobs_test.exs @@ -444,7 +444,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedJobs do CMS.create_article_comment( :job, job_last_week.id, - modk_comment(), + mock_comment(), job_last_week.author.user ) diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs index 291e112d0..c9e9c1e0e 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs @@ -351,7 +351,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do CMS.create_article_comment( :post, post_last_week.id, - modk_comment(), + mock_comment(), post_last_week.author.user ) diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs index 593670e76..50c1258d8 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_repos_test.exs @@ -389,7 +389,7 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedRepos do CMS.create_article_comment( :repo, repo_last_week.id, - modk_comment(), + mock_comment(), repo_last_week.author.user ) From 254a421a01b36811be90ea91222e64008866a474 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 10 Jun 2021 10:56:21 +0800 Subject: [PATCH 24/31] refactor(editor-workflow): fix comment test wip --- .../cms/delegates/article_comment.ex | 13 +++++++++---- .../cms/comments/post_comment_test.exs | 3 ++- .../mutation/cms/articles/blog_test.exs | 2 -- .../mutation/cms/articles/job_test.exs | 2 -- .../mutation/cms/articles/post_test.exs | 2 -- .../mutation/cms/articles/repo_test.exs | 1 - .../mutation/cms/comments/blog_comment_test.exs | 3 ++- .../mutation/cms/comments/job_comment_test.exs | 1 + .../mutation/cms/comments/post_comment_test.exs | 1 + .../mutation/cms/comments/repo_comment_test.exs | 1 + .../mutation/statistics/statistics_test.exs | 5 +++-- .../query/cms/abuse_reports/post_report_test.exs | 1 - 12 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_comment.ex b/lib/groupher_server/cms/delegates/article_comment.ex index 408ff04a0..8c102fbb1 100644 --- a/lib/groupher_server/cms/delegates/article_comment.ex +++ b/lib/groupher_server/cms/delegates/article_comment.ex @@ -134,14 +134,19 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do """ # 如果是 solution, 那么要更新对应的 post 的 solution_digest def update_article_comment(%ArticleComment{is_solution: true} = article_comment, body) do - with {:ok, post} <- ORM.find(Post, article_comment.post_id) do - post |> ORM.update(%{solution_digest: body}) - article_comment |> ORM.update(%{body: body, body_html: body}) + with {:ok, post} <- ORM.find(Post, article_comment.post_id), + {:ok, parsed} <- Converter.Article.parse_body(body), + {:ok, digest} <- Converter.Article.parse_digest(parsed.body_map) do + %{body: body, body_html: body_html} = parsed + post |> ORM.update(%{solution_digest: digest}) + article_comment |> ORM.update(%{body: body, body_html: body_html}) end end def update_article_comment(%ArticleComment{} = article_comment, body) do - article_comment |> ORM.update(%{body: body, body_html: body}) + with {:ok, %{body: body, body_html: body_html}} <- Converter.Article.parse_body(body) do + article_comment |> ORM.update(%{body: body, body_html: body_html}) + end end @doc """ diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 098ca954f..21d764a74 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -794,7 +794,8 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do {:ok, comment} = CMS.mark_comment_solution(comment.id, post_author) {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) - assert post.solution_digest == "solution" + assert post.solution_digest |> String.contains?(~s(

String.contains?(~s(solution

)) {:ok, _comment} = CMS.update_article_comment(comment, mock_comment("new solution")) {:ok, post} = ORM.find(Post, post.id, preload: [author: :user]) diff --git a/test/groupher_server_web/mutation/cms/articles/blog_test.exs b/test/groupher_server_web/mutation/cms/articles/blog_test.exs index d7f1c7fa9..87d9e5d8d 100644 --- a/test/groupher_server_web/mutation/cms/articles/blog_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/blog_test.exs @@ -67,7 +67,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do assert created["id"] == to_string(found.id) end - @tag :wip test "create blog should excape xss attracts" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) @@ -82,7 +81,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do assert not String.contains?(blog.body_html, "script") end - @tag :wip test "create blog should excape xss attracts 2" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) diff --git a/test/groupher_server_web/mutation/cms/articles/job_test.exs b/test/groupher_server_web/mutation/cms/articles/job_test.exs index 34a260ca0..72a933211 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_test.exs @@ -72,7 +72,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do assert created["id"] == to_string(found.id) end - @tag :wip test "create job should excape xss attracts" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) @@ -87,7 +86,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do assert not String.contains?(job.body_html, "script") end - @tag :wip test "create job should excape xss attracts 2" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) diff --git a/test/groupher_server_web/mutation/cms/articles/post_test.exs b/test/groupher_server_web/mutation/cms/articles/post_test.exs index db2d56b09..504e3eafc 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_test.exs @@ -63,7 +63,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do assert {:ok, _} = ORM.find_by(Author, user_id: user.id) end - @tag :wip test "create post should excape xss attracts" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) @@ -78,7 +77,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do assert not String.contains?(post.body_html, "script") end - @tag :wip test "create post should excape xss attracts 2" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) diff --git a/test/groupher_server_web/mutation/cms/articles/repo_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_test.exs index 434a792f5..864fb209d 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_test.exs @@ -155,7 +155,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do # assert updated["readme"] == "new readme" end - @tag :wip test "create repo should excape xss attracts" do {:ok, user} = db_insert(:user) user_conn = simu_conn(:user, user) diff --git a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs index 2aaa76e88..8012085f8 100644 --- a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs @@ -60,12 +60,13 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do @update_comment_query """ mutation($id: ID!, $body: String!) { - updateArticleComment(id: $id, content: $content) { + updateArticleComment(id: $id, body: $body) { id bodyHtml } } """ + @tag :wip test "only owner can update a exsit comment", ~m(blog user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) diff --git a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs index 2676a87c9..499672185 100644 --- a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs @@ -65,6 +65,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ + @tag :wip test "only owner can update a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) diff --git a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs index 3d85a9aae..11e48cb66 100644 --- a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs @@ -65,6 +65,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ + @tag :wip test "only owner can update a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) diff --git a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs index eb76d1e07..b9907c931 100644 --- a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs @@ -65,6 +65,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do } } """ + @tag :wip test "only owner can update a exsit comment", ~m(repo user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) diff --git a/test/groupher_server_web/mutation/statistics/statistics_test.exs b/test/groupher_server_web/mutation/statistics/statistics_test.exs index dad163ff3..80c5a252b 100644 --- a/test/groupher_server_web/mutation/statistics/statistics_test.exs +++ b/test/groupher_server_web/mutation/statistics/statistics_test.exs @@ -190,15 +190,16 @@ defmodule GroupherServer.Test.Mutation.Statistics do @write_comment_query """ mutation($thread: Thread!, $id: ID!, $body: String!) { - createArticleComment(thread: $thread, id: $id, content: $content) { + createArticleComment(thread: $thread, id: $id, body: $body) { id bodyHtml } } """ + @tag :wip test "user should have contribute list after create a comment", ~m(user_conn user)a do {:ok, post} = db_insert(:post) - variables = %{thread: "POST", id: post.id, content: "comment"} + variables = %{thread: "POST", id: post.id, body: mock_comment()} user_conn |> mutation_result(@write_comment_query, variables, "createArticleComment") {:ok, contributes} = ORM.find_by(UserContribute, user_id: user.id) diff --git a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs index fe676b800..8ef2e2a40 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs @@ -91,7 +91,6 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostReport do assert results["totalCount"] == 1 end - @tag :wip test "support article_comment", ~m(guest_conn post user)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) {:ok, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) From d6b48e564e48415eabd6ad272c49392e31cc7bda Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 10 Jun 2021 10:57:21 +0800 Subject: [PATCH 25/31] chore: clean up --- test/groupher_server/cms/comments/post_comment_test.exs | 1 - .../mutation/cms/comments/blog_comment_test.exs | 3 +-- .../mutation/cms/comments/job_comment_test.exs | 2 +- .../mutation/cms/comments/post_comment_test.exs | 2 +- .../mutation/cms/comments/repo_comment_test.exs | 2 +- .../mutation/statistics/statistics_test.exs | 2 +- 6 files changed, 5 insertions(+), 7 deletions(-) diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 21d764a74..9a62c0946 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -780,7 +780,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do assert answers |> List.first() |> Map.get(:id) == comment2.id end - @tag :wip test "update a solution should also update post's solution digest", ~m(user community)a do post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true}) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) diff --git a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs index 8012085f8..7fb808968 100644 --- a/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/blog_comment_test.exs @@ -27,7 +27,6 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do } } """ - @tag :wip2 test "write article comment to a exsit blog", ~m(blog user_conn)a do variables = %{thread: "BLOG", id: blog.id, body: mock_comment()} @@ -66,7 +65,7 @@ defmodule GroupherServer.Test.Mutation.Comments.BlogComment do } } """ - @tag :wip + test "only owner can update a exsit comment", ~m(blog user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) diff --git a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs index 499672185..67e92ea72 100644 --- a/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/job_comment_test.exs @@ -65,7 +65,7 @@ defmodule GroupherServer.Test.Mutation.Comments.JobComment do } } """ - @tag :wip + test "only owner can update a exsit comment", ~m(job user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) diff --git a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs index 11e48cb66..32cb628de 100644 --- a/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/post_comment_test.exs @@ -65,7 +65,7 @@ defmodule GroupherServer.Test.Mutation.Comments.PostComment do } } """ - @tag :wip + test "only owner can update a exsit comment", ~m(post user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) diff --git a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs index b9907c931..9cd8e13cb 100644 --- a/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs +++ b/test/groupher_server_web/mutation/cms/comments/repo_comment_test.exs @@ -65,7 +65,7 @@ defmodule GroupherServer.Test.Mutation.Comments.RepoComment do } } """ - @tag :wip + test "only owner can update a exsit comment", ~m(repo user guest_conn user_conn owner_conn)a do {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) diff --git a/test/groupher_server_web/mutation/statistics/statistics_test.exs b/test/groupher_server_web/mutation/statistics/statistics_test.exs index 80c5a252b..4fbe0b2c2 100644 --- a/test/groupher_server_web/mutation/statistics/statistics_test.exs +++ b/test/groupher_server_web/mutation/statistics/statistics_test.exs @@ -196,7 +196,7 @@ defmodule GroupherServer.Test.Mutation.Statistics do } } """ - @tag :wip + test "user should have contribute list after create a comment", ~m(user_conn user)a do {:ok, post} = db_insert(:post) variables = %{thread: "POST", id: post.id, body: mock_comment()} From a4d979d9171e778eef169a9ff22d3b7c5cd9182c Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 10 Jun 2021 11:21:32 +0800 Subject: [PATCH 26/31] test(comment): body refactor wip --- test/groupher_server/cms/comments/blog_comment_test.exs | 5 +++-- test/groupher_server/cms/comments/job_comment_test.exs | 5 +++-- test/groupher_server/cms/comments/post_comment_test.exs | 5 +++-- test/groupher_server/cms/comments/repo_comment_test.exs | 5 +++-- .../query/cms/abuse_reports/job_report_test.exs | 2 +- .../query/cms/abuse_reports/post_report_test.exs | 2 +- .../query/cms/abuse_reports/repo_report_test.exs | 3 ++- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/test/groupher_server/cms/comments/blog_comment_test.exs b/test/groupher_server/cms/comments/blog_comment_test.exs index 190db8ef4..7b66a3604 100644 --- a/test/groupher_server/cms/comments/blog_comment_test.exs +++ b/test/groupher_server/cms/comments/blog_comment_test.exs @@ -94,9 +94,10 @@ defmodule GroupherServer.Test.CMS.Comments.BlogComment do test "comment can be updated", ~m(blog user)a do {:ok, comment} = CMS.create_article_comment(:blog, blog.id, mock_comment(), user) - {:ok, updated_comment} = CMS.update_article_comment(comment, "updated content") + {:ok, updated_comment} = + CMS.update_article_comment(comment, mock_comment("updated content")) - assert updated_comment.body_html == "updated content" + assert updated_comment.body_html |> String.contains?(~s(updated content

)) end end diff --git a/test/groupher_server/cms/comments/job_comment_test.exs b/test/groupher_server/cms/comments/job_comment_test.exs index 2f8e7435d..6a6fe7341 100644 --- a/test/groupher_server/cms/comments/job_comment_test.exs +++ b/test/groupher_server/cms/comments/job_comment_test.exs @@ -93,9 +93,10 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do test "comment can be updated", ~m(job user)a do {:ok, comment} = CMS.create_article_comment(:job, job.id, mock_comment(), user) - {:ok, updated_comment} = CMS.update_article_comment(comment, "updated content") + {:ok, updated_comment} = + CMS.update_article_comment(comment, mock_comment("updated content")) - assert updated_comment.body_html == "updated content" + assert updated_comment.body_html |> String.contains?(~s(updated content

)) end end diff --git a/test/groupher_server/cms/comments/post_comment_test.exs b/test/groupher_server/cms/comments/post_comment_test.exs index 9a62c0946..cfc714305 100644 --- a/test/groupher_server/cms/comments/post_comment_test.exs +++ b/test/groupher_server/cms/comments/post_comment_test.exs @@ -94,9 +94,10 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do test "comment can be updated", ~m(post user)a do {:ok, comment} = CMS.create_article_comment(:post, post.id, mock_comment(), user) - {:ok, updated_comment} = CMS.update_article_comment(comment, "updated content") + {:ok, updated_comment} = + CMS.update_article_comment(comment, mock_comment("updated content")) - assert updated_comment.body_html == "updated content" + assert updated_comment.body_html |> String.contains?(~s(updated content

)) end end diff --git a/test/groupher_server/cms/comments/repo_comment_test.exs b/test/groupher_server/cms/comments/repo_comment_test.exs index 2247d2b13..8d080b1bb 100644 --- a/test/groupher_server/cms/comments/repo_comment_test.exs +++ b/test/groupher_server/cms/comments/repo_comment_test.exs @@ -94,9 +94,10 @@ defmodule GroupherServer.Test.CMS.Comments.RepoComment do test "comment can be updated", ~m(repo user)a do {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) - {:ok, updated_comment} = CMS.update_article_comment(comment, "updated content") + {:ok, updated_comment} = + CMS.update_article_comment(comment, mock_comment("updated content")) - assert updated_comment.body_html == "updated content" + assert updated_comment.body_html |> String.contains?(~s(updated content

)) end end diff --git a/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs index ef3ccb38d..4041f6ee1 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/job_report_test.exs @@ -102,7 +102,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.JobReport do report_case = get_in(report, ["reportCases"]) assert is_list(report_case) - assert get_in(report, ["articleComment", "bodyHtml"]) == "comment" + assert get_in(report, ["articleComment", "bodyHtml"]) |> String.contains?(~s(comment

)) assert get_in(report, ["articleComment", "id"]) == to_string(comment.id) assert not is_nil(get_in(report, ["articleComment", "author", "login"])) end diff --git a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs index 8ef2e2a40..0edd5de10 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/post_report_test.exs @@ -102,7 +102,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.PostReport do report_case = get_in(report, ["reportCases"]) assert is_list(report_case) - assert get_in(report, ["articleComment", "bodyHtml"]) == "comment" + assert get_in(report, ["articleComment", "bodyHtml"]) |> String.contains?(~s(comment

)) assert get_in(report, ["articleComment", "id"]) == to_string(comment.id) assert not is_nil(get_in(report, ["articleComment", "author", "login"])) end diff --git a/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs index c36ad9d9d..0fa749a5e 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs @@ -91,6 +91,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.RepoReport do assert results["totalCount"] == 1 end + @tag :wip test "support article_comment", ~m(guest_conn repo user)a do {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) @@ -102,7 +103,7 @@ defmodule GroupherServer.Test.Query.AbuseReports.RepoReport do report_case = get_in(report, ["reportCases"]) assert is_list(report_case) - assert get_in(report, ["articleComment", "bodyHtml"]) == "comment" + assert get_in(report, ["articleComment", "bodyHtml"]) |> String.contains?(~s(comment

)) assert get_in(report, ["articleComment", "id"]) == to_string(comment.id) assert not is_nil(get_in(report, ["articleComment", "author", "login"])) end From 5ff746bb7cb7289bb98264cf42972fc273fad89c Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 10 Jun 2021 12:23:18 +0800 Subject: [PATCH 27/31] test(article): body parse & test adjust --- .../cms/delegates/article_curd.ex | 67 +++++++++++-------- .../resolvers/cms_resolver.ex | 4 +- .../cms/articles/post_test.exs | 1 + .../mutation/cms/articles/blog_test.exs | 11 +-- .../mutation/cms/articles/job_test.exs | 11 +-- .../mutation/cms/articles/post_test.exs | 16 +++-- .../mutation/cms/articles/repo_test.exs | 2 +- 7 files changed, 64 insertions(+), 48 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index f5e94b686..e3e8720d4 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -6,16 +6,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do import GroupherServer.CMS.Helper.Matcher - import Helper.Utils, - only: [ - done: 1, - pick_by: 2, - integerfy: 1, - strip_struct: 1, - module_to_atom: 1, - get_config: 2, - ensure: 2 - ] + import Helper.Utils, only: [done: 1, pick_by: 2, module_to_atom: 1, get_config: 2, ensure: 2] import GroupherServer.CMS.Delegate.Helper, only: [mark_viewer_emotion_states: 2] import Helper.ErrorCode @@ -223,7 +214,9 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do """ def update_article(article, args) do Multi.new() - |> Multi.run(:update_article, fn _, _ -> ORM.update(article, args) end) + |> Multi.run(:update_article, fn _, _ -> + do_update_article(article, args) + end) |> Multi.run(:update_comment_question_flag_if_need, fn _, %{update_article: update_article} -> # 如果帖子的类型变了,那么 update 所有的 flag case Map.has_key?(args, :is_question) do @@ -396,29 +389,41 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do end # for create artilce step in Multi.new - defp do_create_article(target, attrs, %Author{id: aid}, %Community{id: cid}) do - # special article like Repo do not have :body, assign it with default "{}" - default_rich_text = Converter.Article.default_rich_text() - body = Map.get(attrs, :body, default_rich_text) - - with {:ok, parsed} <- Converter.Article.parse_body(body), - {:ok, digest} <- Converter.Article.parse_digest(parsed.body_map) do - attrs = - attrs - |> Map.merge(Map.take(parsed, [:body, :body_html])) - |> Map.merge(%{digest: digest}) - - target - |> struct() - |> target.changeset(attrs) + defp do_create_article(model, attrs, %Author{id: author_id}, %Community{id: community_id}) do + # special article like Repo do not have :body, assign it with default-empty rich text + body = Map.get(attrs, :body, Converter.Article.default_rich_text()) + attrs = attrs |> Map.merge(%{body: body}) + + with {:ok, attrs} <- add_rich_text_attrs(attrs) do + model.__struct__ + |> model.changeset(attrs) |> Ecto.Changeset.put_change(:emotions, @default_emotions) - |> Ecto.Changeset.put_change(:author_id, aid) - |> Ecto.Changeset.put_change(:original_community_id, integerfy(cid)) + |> Ecto.Changeset.put_change(:author_id, author_id) + |> Ecto.Changeset.put_change(:original_community_id, community_id) |> Ecto.Changeset.put_embed(:meta, @default_article_meta) |> Repo.insert() end end + defp do_update_article(article, attrs) do + with {:ok, attrs} <- add_rich_text_attrs(attrs) do + ORM.update(article, attrs) + end + end + + # is update or create article with body field, parsed and extand it into attrs + defp add_rich_text_attrs(%{body: body} = attrs) when not is_nil(body) do + with {:ok, parsed} <- Converter.Article.parse_body(body), + {:ok, digest} <- Converter.Article.parse_digest(parsed.body_map) do + attrs + |> Map.merge(Map.take(parsed, [:body, :body_html])) + |> Map.merge(%{digest: digest}) + |> done + end + end + + defp add_rich_text_attrs(attrs), do: attrs + # except Job, other article will just pass, should use set_article_tags function instead # defp exec_update_tags(_, _tags_ids), do: {:ok, :pass} @@ -435,7 +440,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do case Enum.empty?(meta.viewed_user_ids) or user_not_viewed do true -> new_ids = Enum.uniq([user_id] ++ meta.viewed_user_ids) - meta = meta |> Map.merge(%{viewed_user_ids: new_ids}) |> strip_struct + meta = meta |> Map.merge(%{viewed_user_ids: new_ids}) ORM.update_meta(article, meta) false -> @@ -458,6 +463,10 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do {:error, [message: "create article", code: ecode(:create_fails)]} end + defp result({:error, :update_article, result, _steps}) do + {:error, [message: "update article", code: ecode(:update_fails)]} + end + defp result({:error, :mirror_article, _result, _steps}) do {:error, [message: "set community", code: ecode(:create_fails)]} end diff --git a/lib/groupher_server_web/resolvers/cms_resolver.ex b/lib/groupher_server_web/resolvers/cms_resolver.ex index 05875392e..fc3b697ce 100644 --- a/lib/groupher_server_web/resolvers/cms_resolver.ex +++ b/lib/groupher_server_web/resolvers/cms_resolver.ex @@ -69,8 +69,8 @@ defmodule GroupherServerWeb.Resolvers.CMS do CMS.create_article(%Community{id: community_id}, thread, args, user) end - def update_article(_root, %{passport_source: content} = args, _info) do - CMS.update_article(content, args) + def update_article(_root, %{passport_source: article} = args, _info) do + CMS.update_article(article, args) end def delete_article(_root, %{passport_source: content}, _info), do: ORM.delete(content) diff --git a/test/groupher_server/cms/articles/post_test.exs b/test/groupher_server/cms/articles/post_test.exs index f62ec7dee..1daae5998 100644 --- a/test/groupher_server/cms/articles/post_test.exs +++ b/test/groupher_server/cms/articles/post_test.exs @@ -23,6 +23,7 @@ defmodule GroupherServer.Test.CMS.Articles.Post do end describe "[cms post curd]" do + @tag :wip test "can create post with valid attrs", ~m(user community post_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) diff --git a/test/groupher_server_web/mutation/cms/articles/blog_test.exs b/test/groupher_server_web/mutation/cms/articles/blog_test.exs index 87d9e5d8d..3d25e8a8c 100644 --- a/test/groupher_server_web/mutation/cms/articles/blog_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/blog_test.exs @@ -101,6 +101,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do id title body + bodyHtml articleTags { id } @@ -114,7 +115,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do variables = %{ id: blog.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } assert guest_conn |> mutation_get_error?(@query, variables, ecode(:account_login)) @@ -126,13 +127,13 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do variables = %{ id: blog.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } updated = owner_conn |> mutation_result(@query, variables, "updateBlog") assert updated["title"] == variables.title - assert updated["body"] == variables.body + assert updated_post["bodyHtml"] |> String.contains?(~s(updated body #{unique_num})) end test "login user with auth passport update a blog", ~m(blog)a do @@ -145,7 +146,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do variables = %{ id: blog.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } updated = rule_conn |> mutation_result(@query, variables, "updateBlog") @@ -159,7 +160,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do variables = %{ id: blog.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) diff --git a/test/groupher_server_web/mutation/cms/articles/job_test.exs b/test/groupher_server_web/mutation/cms/articles/job_test.exs index 72a933211..d3f78153f 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_test.exs @@ -134,6 +134,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do id title body + bodyHtml articleTags { id } @@ -146,7 +147,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do variables = %{ id: job.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } assert guest_conn |> mutation_get_error?(@query, variables, ecode(:account_login)) @@ -158,13 +159,13 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do variables = %{ id: job.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } updated = owner_conn |> mutation_result(@query, variables, "updateJob") assert updated["title"] == variables.title - assert updated["body"] == variables.body + assert updated_post["bodyHtml"] |> String.contains?(~s(updated body #{unique_num})) end test "login user with auth passport update a job", ~m(job)a do @@ -177,7 +178,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do variables = %{ id: job.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } updated = rule_conn |> mutation_result(@query, variables, "updateJob") @@ -191,7 +192,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do variables = %{ id: job.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) diff --git a/test/groupher_server_web/mutation/cms/articles/post_test.exs b/test/groupher_server_web/mutation/cms/articles/post_test.exs index 504e3eafc..f443bf61c 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_test.exs @@ -185,6 +185,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do id title body + bodyHtml copyRight meta { isEdited @@ -199,32 +200,35 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do } } """ + @tag :wip test "update a post without login user fails", ~m(guest_conn post)a do unique_num = System.unique_integer([:positive, :monotonic]) variables = %{ id: post.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } assert guest_conn |> mutation_get_error?(@query, variables, ecode(:account_login)) end + @tag :wip test "post can be update by owner", ~m(owner_conn post)a do unique_num = System.unique_integer([:positive, :monotonic]) variables = %{ id: post.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}", + # body: mock_rich_text("updated body #{unique_num}"),, + body: mock_rich_text("updated body #{unique_num}"), copyRight: "translate" } updated_post = owner_conn |> mutation_result(@query, variables, "updatePost") assert updated_post["title"] == variables.title - assert updated_post["body"] == variables.body + assert updated_post["bodyHtml"] |> String.contains?(~s(updated body #{unique_num})) assert updated_post["copyRight"] == variables.copyRight end @@ -235,7 +239,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do variables = %{ id: post.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } updated_post = owner_conn |> mutation_result(@query, variables, "updatePost") @@ -255,7 +259,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do variables = %{ id: post.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } updated_post = rule_conn |> mutation_result(@query, variables, "updatePost") @@ -269,7 +273,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do variables = %{ id: post.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) diff --git a/test/groupher_server_web/mutation/cms/articles/repo_test.exs b/test/groupher_server_web/mutation/cms/articles/repo_test.exs index 864fb209d..bd6be0065 100644 --- a/test/groupher_server_web/mutation/cms/articles/repo_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/repo_test.exs @@ -175,7 +175,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Repo do variables = %{ id: repo.id, title: "updated title #{unique_num}", - body: "updated body #{unique_num}" + body: mock_rich_text("updated body #{unique_num}") } rule_conn = simu_conn(:user, cms: %{"what.ever" => true}) From 93c757e07019fd0c243aec4650a04c46e42fb0dd Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 10 Jun 2021 12:30:49 +0800 Subject: [PATCH 28/31] test(article): body parse & test adjust --- test/groupher_server_web/mutation/cms/articles/blog_test.exs | 2 +- test/groupher_server_web/mutation/cms/articles/job_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/groupher_server_web/mutation/cms/articles/blog_test.exs b/test/groupher_server_web/mutation/cms/articles/blog_test.exs index 3d25e8a8c..2fbc893db 100644 --- a/test/groupher_server_web/mutation/cms/articles/blog_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/blog_test.exs @@ -133,7 +133,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Blog do updated = owner_conn |> mutation_result(@query, variables, "updateBlog") assert updated["title"] == variables.title - assert updated_post["bodyHtml"] |> String.contains?(~s(updated body #{unique_num})) + assert updated["bodyHtml"] |> String.contains?(~s(updated body #{unique_num})) end test "login user with auth passport update a blog", ~m(blog)a do diff --git a/test/groupher_server_web/mutation/cms/articles/job_test.exs b/test/groupher_server_web/mutation/cms/articles/job_test.exs index d3f78153f..1e3f6ad57 100644 --- a/test/groupher_server_web/mutation/cms/articles/job_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/job_test.exs @@ -165,7 +165,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Job do updated = owner_conn |> mutation_result(@query, variables, "updateJob") assert updated["title"] == variables.title - assert updated_post["bodyHtml"] |> String.contains?(~s(updated body #{unique_num})) + assert updated["bodyHtml"] |> String.contains?(~s(updated body #{unique_num})) end test "login user with auth passport update a job", ~m(job)a do From 95f7b8741e265c6f42ecc0ae9341dc8f255caf36 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 10 Jun 2021 13:10:55 +0800 Subject: [PATCH 29/31] test(article): body parse & test adjust --- lib/groupher_server/cms/delegates/article_curd.ex | 5 +++-- test/groupher_server/cms/articles/post_test.exs | 2 +- test/groupher_server_web/mutation/cms/articles/post_test.exs | 3 +-- .../query/cms/abuse_reports/repo_report_test.exs | 1 - 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index e3e8720d4..bac910433 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -405,12 +405,14 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do end end - defp do_update_article(article, attrs) do + defp do_update_article(article, %{body: _} = attrs) do with {:ok, attrs} <- add_rich_text_attrs(attrs) do ORM.update(article, attrs) end end + defp do_update_article(article, attrs), do: ORM.update(article, attrs) + # is update or create article with body field, parsed and extand it into attrs defp add_rich_text_attrs(%{body: body} = attrs) when not is_nil(body) do with {:ok, parsed} <- Converter.Article.parse_body(body), @@ -457,7 +459,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do defp result({:ok, %{update_edit_status: result}}), do: {:ok, result} defp result({:ok, %{update_article: result}}), do: {:ok, result} defp result({:ok, %{set_viewer_has_states: result}}), do: result |> done() - defp result({:ok, %{update_article_meta: result}}), do: {:ok, result} defp result({:error, :create_article, _result, _steps}) do {:error, [message: "create article", code: ecode(:create_fails)]} diff --git a/test/groupher_server/cms/articles/post_test.exs b/test/groupher_server/cms/articles/post_test.exs index 1daae5998..a2c6444cd 100644 --- a/test/groupher_server/cms/articles/post_test.exs +++ b/test/groupher_server/cms/articles/post_test.exs @@ -23,7 +23,6 @@ defmodule GroupherServer.Test.CMS.Articles.Post do end describe "[cms post curd]" do - @tag :wip test "can create post with valid attrs", ~m(user community post_attrs)a do assert {:error, _} = ORM.find_by(Author, user_id: user.id) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) @@ -173,6 +172,7 @@ defmodule GroupherServer.Test.CMS.Articles.Post do assert post.is_question end + @tag :wip test "can update post with question", ~m(user community post_attrs)a do post_attrs = Map.merge(post_attrs, %{is_question: true}) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) diff --git a/test/groupher_server_web/mutation/cms/articles/post_test.exs b/test/groupher_server_web/mutation/cms/articles/post_test.exs index f443bf61c..8ddf617fa 100644 --- a/test/groupher_server_web/mutation/cms/articles/post_test.exs +++ b/test/groupher_server_web/mutation/cms/articles/post_test.exs @@ -200,7 +200,7 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do } } """ - @tag :wip + test "update a post without login user fails", ~m(guest_conn post)a do unique_num = System.unique_integer([:positive, :monotonic]) @@ -213,7 +213,6 @@ defmodule GroupherServer.Test.Mutation.Articles.Post do assert guest_conn |> mutation_get_error?(@query, variables, ecode(:account_login)) end - @tag :wip test "post can be update by owner", ~m(owner_conn post)a do unique_num = System.unique_integer([:positive, :monotonic]) diff --git a/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs b/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs index 0fa749a5e..975e1f5fc 100644 --- a/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs +++ b/test/groupher_server_web/query/cms/abuse_reports/repo_report_test.exs @@ -91,7 +91,6 @@ defmodule GroupherServer.Test.Query.AbuseReports.RepoReport do assert results["totalCount"] == 1 end - @tag :wip test "support article_comment", ~m(guest_conn repo user)a do {:ok, comment} = CMS.create_article_comment(:repo, repo.id, mock_comment(), user) {:ok, _} = CMS.report_article_comment(comment.id, mock_comment(), "attr", user) From 8d4c8fd669068fd5f70727f9d057136c1dca5694 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 10 Jun 2021 13:49:46 +0800 Subject: [PATCH 30/31] test(article): fix test --- lib/groupher_server/cms/delegates/article_curd.ex | 11 ++--------- test/groupher_server/cms/articles/post_test.exs | 1 - .../query/cms/comments/post_comment_test.exs | 1 + 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index bac910433..c6abcdc4c 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -25,14 +25,6 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do @default_emotions Embeds.ArticleEmotion.default_emotions() @default_article_meta Embeds.ArticleMeta.default_meta() - content = """ - { - "time": 2018, - "blocks": [], - "version": "2.22.0" - } - """ - @doc """ read articles for un-logined user """ @@ -458,13 +450,14 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do defp result({:ok, %{update_edit_status: result}}), do: {:ok, result} defp result({:ok, %{update_article: result}}), do: {:ok, result} + defp result({:ok, %{update_article_meta: result}}), do: {:ok, result} defp result({:ok, %{set_viewer_has_states: result}}), do: result |> done() defp result({:error, :create_article, _result, _steps}) do {:error, [message: "create article", code: ecode(:create_fails)]} end - defp result({:error, :update_article, result, _steps}) do + defp result({:error, :update_article, _result, _steps}) do {:error, [message: "update article", code: ecode(:update_fails)]} end diff --git a/test/groupher_server/cms/articles/post_test.exs b/test/groupher_server/cms/articles/post_test.exs index a2c6444cd..f62ec7dee 100644 --- a/test/groupher_server/cms/articles/post_test.exs +++ b/test/groupher_server/cms/articles/post_test.exs @@ -172,7 +172,6 @@ defmodule GroupherServer.Test.CMS.Articles.Post do assert post.is_question end - @tag :wip test "can update post with question", ~m(user community post_attrs)a do post_attrs = Map.merge(post_attrs, %{is_question: true}) {:ok, post} = CMS.create_article(community, :post, post_attrs, user) diff --git a/test/groupher_server_web/query/cms/comments/post_comment_test.exs b/test/groupher_server_web/query/cms/comments/post_comment_test.exs index c3a4e540c..5e400c96e 100644 --- a/test/groupher_server_web/query/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/post_comment_test.exs @@ -34,6 +34,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do } } """ + @tag :wip test "guest user can get comment participators after comment created", ~m(guest_conn post user user2)a do total_count = 5 From b639ecf0da42da58e81e1e8d11742f215c20a0e1 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 10 Jun 2021 14:01:08 +0800 Subject: [PATCH 31/31] test(article): fix test --- lib/groupher_server/cms/delegates/article_curd.ex | 3 ++- test/groupher_server/cms/articles/repo_test.exs | 1 + .../query/cms/comments/post_comment_test.exs | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/groupher_server/cms/delegates/article_curd.ex b/lib/groupher_server/cms/delegates/article_curd.ex index c6abcdc4c..21e5fce72 100644 --- a/lib/groupher_server/cms/delegates/article_curd.ex +++ b/lib/groupher_server/cms/delegates/article_curd.ex @@ -450,8 +450,9 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do defp result({:ok, %{update_edit_status: result}}), do: {:ok, result} defp result({:ok, %{update_article: result}}), do: {:ok, result} - defp result({:ok, %{update_article_meta: result}}), do: {:ok, result} + # NOTE: for read article, order is import defp result({:ok, %{set_viewer_has_states: result}}), do: result |> done() + defp result({:ok, %{update_article_meta: result}}), do: {:ok, result} defp result({:error, :create_article, _result, _steps}) do {:error, [message: "create article", code: ecode(:create_fails)]} diff --git a/test/groupher_server/cms/articles/repo_test.exs b/test/groupher_server/cms/articles/repo_test.exs index 14c9c14e6..ea0d68425 100644 --- a/test/groupher_server/cms/articles/repo_test.exs +++ b/test/groupher_server/cms/articles/repo_test.exs @@ -63,6 +63,7 @@ defmodule GroupherServer.Test.Articles.Repo do assert user2.id in created.meta.viewed_user_ids end + @tag :wip test "read repo should contains viewer_has_xxx state", ~m(repo_attrs community user user2)a do {:ok, repo} = CMS.create_article(community, :repo, repo_attrs, user) {:ok, repo} = CMS.read_article(:repo, repo.id, user) diff --git a/test/groupher_server_web/query/cms/comments/post_comment_test.exs b/test/groupher_server_web/query/cms/comments/post_comment_test.exs index 5e400c96e..c3a4e540c 100644 --- a/test/groupher_server_web/query/cms/comments/post_comment_test.exs +++ b/test/groupher_server_web/query/cms/comments/post_comment_test.exs @@ -34,7 +34,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do } } """ - @tag :wip test "guest user can get comment participators after comment created", ~m(guest_conn post user user2)a do total_count = 5