Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit bdc9257

Browse files
committed
feat(post-qa): solution digest edge case
1 parent ddb876f commit bdc9257

File tree

6 files changed

+27
-15
lines changed

6 files changed

+27
-15
lines changed

lib/groupher_server/cms/delegates/article_comment.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ defmodule GroupherServer.CMS.Delegate.ArticleComment do
134134
@doc """
135135
update a comment for article like psot, job ...
136136
"""
137+
# 如果是 solution, 那么要更新对应的 post 的 solution_digest
138+
def update_article_comment(%ArticleComment{is_solution: true} = article_comment, content) do
139+
with {:ok, post} <- ORM.find(Post, article_comment.post_id) do
140+
post |> ORM.update(%{solution_digest: content})
141+
article_comment |> ORM.update(%{body_html: content})
142+
end
143+
end
144+
137145
def update_article_comment(%ArticleComment{} = article_comment, content) do
138146
article_comment |> ORM.update(%{body_html: content})
139147
end

test/groupher_server/cms/articles/post_test.exs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,20 @@ defmodule GroupherServer.Test.CMS.Articles.Post do
148148
end
149149

150150
describe "[cms post question]" do
151-
@tag :wip2
152151
test "post have default question flags", ~m(user community post_attrs)a do
153152
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
154153

155154
assert not post.is_question
156155
assert not post.is_solved
157156
end
158157

159-
@tag :wip2
160158
test "can create post with question", ~m(user community post_attrs)a do
161159
post_attrs = Map.merge(post_attrs, %{is_question: true})
162160
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
163161

164162
assert post.is_question
165163
end
166164

167-
@tag :wip2
168165
test "can update post with question", ~m(user community post_attrs)a do
169166
post_attrs = Map.merge(post_attrs, %{is_question: true})
170167
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)

test/groupher_server/cms/comments/post_comment_test.exs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
670670
end
671671

672672
describe "[article comment qa type]" do
673-
@tag :wip2
674673
test "create comment for normal post should have default qa flags", ~m(user community)a do
675674
post_attrs = mock_attrs(:post, %{community_id: community.id})
676675
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
@@ -680,7 +679,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
680679
assert not post_comment.is_solution
681680
end
682681

683-
@tag :wip2
684682
test "create comment for question post should have flags", ~m(user community)a do
685683
post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true})
686684
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
@@ -690,7 +688,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
690688
assert post_comment.is_for_question
691689
end
692690

693-
@tag :wip2
694691
test "update comment with is_question should batch update exsit comments is_for_question field",
695692
~m(user community)a do
696693
post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true})
@@ -714,7 +711,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
714711
assert not comment3.is_for_question
715712
end
716713

717-
@tag :wip2
718714
test "can mark a comment as solution", ~m(user community)a do
719715
post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true})
720716
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
@@ -732,7 +728,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
732728
assert post.solution_digest == comment.body_html
733729
end
734730

735-
@tag :wip2
736731
test "non-post-author can not mark a comment as solution", ~m(user community)a do
737732
post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true})
738733
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
@@ -747,7 +742,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
747742
reason |> is_error?(:require_questioner)
748743
end
749744

750-
@tag :wip2
751745
test "can undo mark a comment as solution", ~m(user community)a do
752746
post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true})
753747
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
@@ -765,7 +759,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
765759
assert not post.is_solved
766760
end
767761

768-
@tag :wip2
769762
test "non-post-author can not undo mark a comment as solution", ~m(user community)a do
770763
post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true})
771764
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
@@ -780,7 +773,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
780773
reason |> is_error?(:require_questioner)
781774
end
782775

783-
@tag :wip2
784776
test "can only mark one best comment as solution", ~m(user community)a do
785777
post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true})
786778
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
@@ -801,5 +793,23 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
801793
assert answers |> length == 1
802794
assert answers |> List.first() |> Map.get(:id) == comment2.id
803795
end
796+
797+
test "update a solution should also update post's solution digest", ~m(user community)a do
798+
post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true})
799+
{:ok, post} = CMS.create_article(community, :post, post_attrs, user)
800+
801+
{:ok, post} = ORM.find(Post, post.id, preload: [author: :user])
802+
post_author = post.author.user
803+
804+
{:ok, comment} = CMS.create_article_comment(:post, post.id, "solution", post_author)
805+
{:ok, comment} = CMS.mark_comment_solution(comment.id, post_author)
806+
807+
{:ok, post} = ORM.find(Post, post.id, preload: [author: :user])
808+
assert post.solution_digest == "solution"
809+
810+
{:ok, _comment} = CMS.update_article_comment(comment, "new solution")
811+
{:ok, post} = ORM.find(Post, post.id, preload: [author: :user])
812+
assert post.solution_digest == "new solution"
813+
end
804814
end
805815
end

test/groupher_server_web/query/cms/comments/job_comment_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ defmodule GroupherServer.Test.Query.Comments.JobComment do
240240
assert results["totalCount"] == total_count
241241
end
242242

243-
@tag :wip
244243
test "guest user can get paged comment with pinned comment in it",
245244
~m(guest_conn job user)a do
246245
total_count = 20

test/groupher_server_web/query/cms/comments/post_comment_test.exs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do
242242
assert results["totalCount"] == total_count
243243
end
244244

245-
@tag :wip
246245
test "guest user can get paged comment with pinned comment in it",
247246
~m(guest_conn post user)a do
248247
total_count = 20
@@ -272,7 +271,7 @@ defmodule GroupherServer.Test.Query.Comments.PostComment do
272271
end
273272

274273
# post only
275-
@tag :wip
274+
276275
test "if solution in pinned comments, solution should always on top",
277276
~m(guest_conn community user)a do
278277
post_attrs = mock_attrs(:post, %{community_id: community.id, is_question: true})

test/groupher_server_web/query/cms/comments/repo_comment_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ defmodule GroupherServer.Test.Query.Comments.RepoComment do
238238
assert results["totalCount"] == total_count
239239
end
240240

241-
@tag :wip
242241
test "guest user can get paged comment with pinned comment in it",
243242
~m(guest_conn repo user)a do
244243
total_count = 20

0 commit comments

Comments
 (0)