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

Commit b35d121

Browse files
committed
refactor(abuse-report): clean up
1 parent 3b31554 commit b35d121

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+63
-194
lines changed

lib/groupher_server/cms/embeds/article_comment_meta.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ defmodule GroupherServer.CMS.Embeds.ArticleCommentMeta do
77

88
import Ecto.Changeset
99

10-
@optional_fields ~w(is_article_author_upvoted is_solution report_count is_reply_to_others reported_count)a
10+
@optional_fields ~w(is_article_author_upvoted is_solution report_count is_reply_to_others reported_count reported_user_ids)a
1111

1212
@default_meta %{
1313
is_article_author_upvoted: false,
1414
is_solution: false,
1515
is_reply_to_others: false,
1616
report_count: 0,
1717
upvoted_user_ids: [],
18+
reported_user_ids: [],
1819
reported_count: 0
1920
}
2021

@@ -30,6 +31,7 @@ defmodule GroupherServer.CMS.Embeds.ArticleCommentMeta do
3031
field(:report_count, :integer, default: 0)
3132

3233
field(:upvoted_user_ids, {:array, :integer}, default: [])
34+
field(:reported_user_ids, {:array, :integer}, default: [])
3335
field(:reported_count, :integer, default: 0)
3436
end
3537

test/groupher_server/cms/abuse_reports/account_report_test.exs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do
2323
end
2424

2525
describe "[account report/unreport]" do
26-
@tag :wip3
2726
# test "list article reports should work", ~m(community user user2 post_attrs)a do
2827
# {:ok, post} = CMS.create_content(community, :post, post_attrs, user)
2928
# {:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user)
@@ -37,7 +36,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do
3736
# assert report.article.thread == :post
3837
# end
3938

40-
@tag :wip3
4139
test "report an account should have a abuse report record", ~m(user user2)a do
4240
{:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2)
4341

@@ -56,7 +54,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do
5654
assert user.meta.reported_count == 1
5755
end
5856

59-
@tag :wip2
6057
test "can undo a report", ~m(user user2)a do
6158
{:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2)
6259
{:ok, user} = ORM.find(User, user.id)
@@ -72,7 +69,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do
7269
assert user2.id not in user.meta.reported_user_ids
7370
end
7471

75-
@tag :wip2
7672
test "can undo a existed report", ~m(user user2 user3)a do
7773
{:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2)
7874
{:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user3)
@@ -87,7 +83,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do
8783
assert user3.id in user.meta.reported_user_ids
8884
end
8985

90-
@tag :wip3
9186
test "can undo a report with other user report it too", ~m(user user2 user3)a do
9287
{:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2)
9388
{:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user3)
@@ -112,7 +107,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do
112107
assert Enum.any?(report.report_cases, &(&1.user.login == user3.login))
113108
end
114109

115-
@tag :wip3
116110
test "different user report a account should have same report with different report cases",
117111
~m(user user2 user3)a do
118112
{:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2)
@@ -132,7 +126,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.AccountReport do
132126
assert List.last(report_cases).user.login == user3.login
133127
end
134128

135-
@tag :wip3
136129
test "same user can not report a account twice", ~m(user user2)a do
137130
{:ok, _report} = CMS.report_account(user.id, "reason", "attr_info", user2)
138131
assert {:error, _report} = CMS.report_account(user.id, "reason", "attr_info", user2)

test/groupher_server/cms/abuse_reports/comment_report_test.exs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do
1515
end
1616

1717
describe "[article comment report/unreport]" do
18-
@tag :wip3
1918
test "report a comment should have a abuse report record", ~m(user post)a do
2019
{:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user)
2120
{:ok, _comment} = CMS.report_article_comment(comment.id, "reason", "attr", user)
@@ -32,7 +31,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.CommentReport do
3231
assert List.first(report_cases).user.login == user.login
3332
end
3433

35-
@tag :wip3
3634
test "different user report a comment should have same report with different report cases",
3735
~m(user user2 post)a do
3836
{:ok, comment} = CMS.create_article_comment(:post, post.id, "commment", user)

test/groupher_server/cms/abuse_reports/job_report_test.exs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do
1717
end
1818

1919
describe "[article job report/unreport]" do
20-
@tag :wip3
2120
test "list article reports should work", ~m(community user user2 job_attrs)a do
2221
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
2322
{:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user)
@@ -31,7 +30,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do
3130
assert report.article.thread == :job
3231
end
3332

34-
@tag :wip3
3533
test "report a job should have a abuse report record", ~m(community user job_attrs)a do
3634
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
3735
{:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user)
@@ -52,7 +50,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do
5250
assert user.id in job.meta.reported_user_ids
5351
end
5452

55-
@tag :wip3
5653
test "can undo a report", ~m(community user job_attrs)a do
5754
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
5855
{:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user)
@@ -66,7 +63,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do
6663
assert user.id not in job.meta.reported_user_ids
6764
end
6865

69-
@tag :wip2
7066
test "can undo a existed report", ~m(community user user2 job_attrs)a do
7167
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
7268
{:ok, _report} = CMS.report_article(:job, job.id, "reason", "attr_info", user)
@@ -83,7 +79,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do
8379
assert user.id not in job.meta.reported_user_ids
8480
end
8581

86-
@tag :wip3
8782
test "can undo a report with other user report it too",
8883
~m(community user user2 job_attrs)a do
8984
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
@@ -110,7 +105,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do
110105
assert Enum.any?(report.report_cases, &(&1.user.login == user2.login))
111106
end
112107

113-
@tag :wip3
114108
test "different user report a comment should have same report with different report cases",
115109
~m(community user user2 job_attrs)a do
116110
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
@@ -132,7 +126,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.JobReport do
132126
assert List.last(report_cases).user.login == user2.login
133127
end
134128

135-
@tag :wip3
136129
test "same user can not report a comment twice", ~m(community job_attrs user)a do
137130
{:ok, job} = CMS.create_content(community, :job, job_attrs, user)
138131

test/groupher_server/cms/abuse_reports/post_report_test.exs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
1717
end
1818

1919
describe "[article post report/unreport]" do
20-
@tag :wip3
2120
test "list article reports should work", ~m(community user user2 post_attrs)a do
2221
{:ok, post} = CMS.create_content(community, :post, post_attrs, user)
2322
{:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user)
@@ -31,7 +30,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
3130
assert report.article.thread == :post
3231
end
3332

34-
@tag :wip3
3533
test "report a post should have a abuse report record", ~m(community user post_attrs)a do
3634
{:ok, post} = CMS.create_content(community, :post, post_attrs, user)
3735
{:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user)
@@ -52,7 +50,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
5250
assert user.id in post.meta.reported_user_ids
5351
end
5452

55-
@tag :wip3
5653
test "can undo a report", ~m(community user post_attrs)a do
5754
{:ok, post} = CMS.create_content(community, :post, post_attrs, user)
5855
{:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user)
@@ -66,7 +63,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
6663
assert user.id not in post.meta.reported_user_ids
6764
end
6865

69-
@tag :wip2
7066
test "can undo a existed report", ~m(community user user2 post_attrs)a do
7167
{:ok, post} = CMS.create_content(community, :post, post_attrs, user)
7268
{:ok, _report} = CMS.report_article(:post, post.id, "reason", "attr_info", user)
@@ -83,7 +79,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
8379
assert user.id not in post.meta.reported_user_ids
8480
end
8581

86-
@tag :wip3
8782
test "can undo a report with other user report it too",
8883
~m(community user user2 post_attrs)a do
8984
{:ok, post} = CMS.create_content(community, :post, post_attrs, user)
@@ -110,7 +105,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
110105
assert Enum.any?(report.report_cases, &(&1.user.login == user2.login))
111106
end
112107

113-
@tag :wip3
114108
test "different user report a comment should have same report with different report cases",
115109
~m(community user user2 post_attrs)a do
116110
{:ok, post} = CMS.create_content(community, :post, post_attrs, user)
@@ -132,7 +126,6 @@ defmodule GroupherServer.Test.CMS.AbuseReports.PostReport do
132126
assert List.last(report_cases).user.login == user2.login
133127
end
134128

135-
@tag :wip3
136129
test "same user can not report a comment twice", ~m(community post_attrs user)a do
137130
{:ok, post} = CMS.create_content(community, :post, post_attrs, user)
138131

test/groupher_server/cms/comments/job_comment_emotions_test.exs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
2121
end
2222

2323
describe "[emotion in paged article comment]" do
24-
@tag :wip3
2524
test "login user should got viewer has emotioned status", ~m(job user)a do
2625
total_count = 0
2726
page_number = 10
@@ -76,7 +75,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
7675
assert @default_emotions == emotions
7776
end
7877

79-
@tag :wip3
8078
test "can make emotion to comment", ~m(job user user2)a do
8179
parent_content = "parent comment"
8280
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user)
@@ -91,7 +89,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
9189
assert user_exist_in?(user2, emotions.latest_downvote_users)
9290
end
9391

94-
@tag :wip3
9592
test "can undo emotion to comment", ~m(job user user2)a do
9693
parent_content = "parent comment"
9794
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user)
@@ -114,7 +111,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
114111
assert not user_exist_in?(user2, emotions.latest_downvote_users)
115112
end
116113

117-
@tag :wip3
118114
test "same user make same emotion to same comment.", ~m(job user)a do
119115
parent_content = "parent comment"
120116
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, parent_content, user)
@@ -128,7 +124,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
128124
assert user_exist_in?(user, parent_comment.emotions.latest_downvote_users)
129125
end
130126

131-
@tag :wip3
132127
test "same user same emotion to same comment only have one user_emotion record",
133128
~m(job user)a do
134129
parent_content = "parent comment"
@@ -152,7 +147,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentEmotions do
152147
assert record.heart
153148
end
154149

155-
@tag :wip3
156150
test "different user can make same emotions on same comment", ~m(job user user2 user3)a do
157151
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user)
158152

test/groupher_server/cms/comments/job_comment_replies_test.exs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do
3333
assert exist_in?(replyed_comment, parent_comment.replies)
3434
end
3535

36-
@tag :wip3
3736
test "deleted comment can not be reply", ~m(job user user2)a do
3837
parent_content = "parent comment"
3938
reply_content = "reply comment"
@@ -64,7 +63,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do
6463
assert exist_in?(replyed_comment_2, parent_comment.replies)
6564
end
6665

67-
@tag :wip3
6866
test "reply to reply inside a comment should belong same parent comment",
6967
~m(job user user2)a do
7068
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user)
@@ -90,7 +88,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do
9088
assert replyed_comment_3.reply_to_id == replyed_comment_2.id
9189
end
9290

93-
@tag :wip3
9491
test "reply to reply inside a comment should have is_reply_to_others flag in meta",
9592
~m(job user user2)a do
9693
{:ok, parent_comment} = CMS.create_article_comment(:job, job.id, "parent comment", user)
@@ -110,7 +107,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobCommentReplies do
110107
assert replyed_comment_3.meta.is_reply_to_others
111108
end
112109

113-
@tag :wip3
114110
test "comment replies only contains @max_parent_replies_count replies", ~m(job user)a do
115111
total_reply_count = @max_parent_replies_count + 1
116112

test/groupher_server/cms/comments/job_comment_test.exs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
3939
assert comment.meta |> Map.from_struct() |> Map.delete(:id) == @default_comment_meta
4040
end
4141

42-
@tag :wip3
4342
test "comment can be updated", ~m(job user)a do
4443
{:ok, comment} = CMS.create_article_comment(:job, job.id, "job comment", user)
4544

@@ -130,7 +129,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
130129
assert comment.meta.is_article_author_upvoted
131130
end
132131

133-
@tag :wip3
134132
test "user upvote job comment will add id to upvoted_user_ids", ~m(job user)a do
135133
comment = "job_comment"
136134
{:ok, comment} = CMS.create_article_comment(:job, job.id, comment, user)
@@ -139,7 +137,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
139137
assert user.id in comment.meta.upvoted_user_ids
140138
end
141139

142-
@tag :wip3
143140
test "user undo upvote job comment will remove id from upvoted_user_ids",
144141
~m(job user user2)a do
145142
comment = "job_comment"
@@ -289,7 +286,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
289286
# {:ok, comment} = ORM.find(ArticleComment, comment.id)
290287
# end
291288

292-
@tag :wip3
293289
test "can undo a report with other user report it too",
294290
~m(user user2 job)a do
295291
{:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user)
@@ -317,7 +313,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
317313
assert Enum.any?(report.report_cases, &(&1.user.login == user2.login))
318314
end
319315

320-
@tag :wip3
321316
test "report user < @report_threshold_for_fold will not fold comment", ~m(user job)a do
322317
{:ok, comment} = CMS.create_article_comment(:job, job.id, "commment", user)
323318

@@ -453,7 +448,7 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
453448
assert paged_comments.total_count == total_count
454449
end
455450

456-
@tag :wip3
451+
@tag :wip2
457452
test "paged article comments should not contains folded and repoted comments",
458453
~m(user job)a do
459454
total_count = 15
@@ -471,32 +466,20 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
471466
random_comment_2 = all_comments |> Enum.at(1)
472467
random_comment_3 = all_comments |> Enum.at(3)
473468

474-
random_comment_4 = all_comments |> Enum.at(2)
475-
random_comment_5 = all_comments |> Enum.at(4)
476-
random_comment_6 = all_comments |> Enum.at(8)
477-
478469
{:ok, _comment} = CMS.fold_article_comment(random_comment_1.id, user)
479470
{:ok, _comment} = CMS.fold_article_comment(random_comment_2.id, user)
480471
{:ok, _comment} = CMS.fold_article_comment(random_comment_3.id, user)
481472

482-
{:ok, _comment} = CMS.report_article_comment(random_comment_4.id, "reason", "attr", user)
483-
{:ok, _comment} = CMS.report_article_comment(random_comment_5.id, "reason", "attr", user)
484-
{:ok, _comment} = CMS.report_article_comment(random_comment_6.id, "reason", "attr", user)
485-
486473
{:ok, paged_comments} =
487474
CMS.list_article_comments(:job, job.id, %{page: page_number, size: page_size}, :replies)
488475

489476
assert not exist_in?(random_comment_1, paged_comments.entries)
490477
assert not exist_in?(random_comment_2, paged_comments.entries)
491478
assert not exist_in?(random_comment_3, paged_comments.entries)
492479

493-
assert not exist_in?(random_comment_4, paged_comments.entries)
494-
assert not exist_in?(random_comment_5, paged_comments.entries)
495-
assert not exist_in?(random_comment_6, paged_comments.entries)
496-
497480
assert page_number == paged_comments.page_number
498481
assert page_size == paged_comments.page_size
499-
assert total_count - 6 == paged_comments.total_count
482+
assert total_count - 3 == paged_comments.total_count
500483
end
501484

502485
@tag :wip
@@ -531,7 +514,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
531514
end
532515

533516
describe "[article comment delete]" do
534-
@tag :wip3
535517
test "delete comment still exsit in paged list and content is gone", ~m(user job)a do
536518
total_count = 10
537519
page_number = 1
@@ -556,7 +538,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
556538
assert deleted_comment.body_html == @delete_hint
557539
end
558540

559-
@tag :wip3
560541
test "delete comment still update article's comments_count field", ~m(user job)a do
561542
{:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user)
562543
{:ok, _comment} = CMS.create_article_comment(:job, job.id, "commment", user)
@@ -574,7 +555,6 @@ defmodule GroupherServer.Test.CMS.Comments.JobComment do
574555
assert job.article_comments_count == 4
575556
end
576557

577-
@tag :wip3
578558
test "delete comment still delete pined record if needed", ~m(user job)a do
579559
total_count = 10
580560

0 commit comments

Comments
 (0)