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

Commit 3b31554

Browse files
committed
refactor(abuse-report): debug viewer_has_reported
1 parent 31708ef commit 3b31554

File tree

7 files changed

+26
-7
lines changed

7 files changed

+26
-7
lines changed

lib/groupher_server/accounts/user.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ defmodule GroupherServer.Accounts.User do
6060
# field(:sponsor_member, :boolean)
6161
# field(:paid_member, :boolean)
6262
# field(:platinum_member, :boolean)
63+
field(:viewer_has_reported, :boolean, default: false, virtual: true)
6364

6465
embeds_one(:meta, Embeds.UserMeta, on_replace: :update)
6566

lib/groupher_server/cms/job.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ defmodule GroupherServer.CMS.Job do
6161
has_many(:upvotes, {"article_upvotes", ArticleUpvote})
6262
field(:upvotes_count, :integer, default: 0)
6363

64+
field(:viewer_has_viewed, :boolean, default: false, virtual: true)
65+
field(:viewer_has_upvoted, :boolean, default: false, virtual: true)
66+
field(:viewer_has_collected, :boolean, default: false, virtual: true)
67+
field(:viewer_has_reported, :boolean, default: false, virtual: true)
68+
6469
has_many(:collects, {"article_collects", ArticleCollect})
6570
field(:collects_count, :integer, default: 0)
6671

lib/groupher_server/cms/repo.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ defmodule GroupherServer.CMS.Repo do
6262
field(:is_pinned, :boolean, default: false, virtual: true)
6363
field(:trash, :boolean, default_value: false)
6464

65+
field(:viewer_has_viewed, :boolean, default: false, virtual: true)
66+
field(:viewer_has_upvoted, :boolean, default: false, virtual: true)
67+
field(:viewer_has_collected, :boolean, default: false, virtual: true)
68+
field(:viewer_has_reported, :boolean, default: false, virtual: true)
69+
6570
has_many(:upvotes, {"article_upvotes", ArticleUpvote})
6671
field(:upvotes_count, :integer, default: 0)
6772

test/groupher_server/cms/comments/post_comment_test.exs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,6 @@ defmodule GroupherServer.Test.CMS.Comments.PostComment do
471471
random_comment_2 = all_comments |> Enum.at(1)
472472
random_comment_3 = all_comments |> Enum.at(3)
473473

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-
478474
{:ok, _comment} = CMS.fold_article_comment(random_comment_1.id, user)
479475
{:ok, _comment} = CMS.fold_article_comment(random_comment_2.id, user)
480476
{:ok, _comment} = CMS.fold_article_comment(random_comment_3.id, user)

test/groupher_server_web/query/cms/paged_jobs_test.exs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,13 @@ defmodule GroupherServer.Test.Query.PagedJobs do
9292
viewerHasCollected
9393
viewerHasUpvoted
9494
viewerHasViewed
95+
viewerHasReported
9596
}
9697
totalCount
9798
}
9899
}
99100
"""
100-
@tag :wip3
101+
@tag :wip2
101102
test "has_xxx state should work", ~m(user)a do
102103
user_conn = simu_conn(:user, user)
103104
{:ok, community} = db_insert(:community)
@@ -114,16 +115,19 @@ defmodule GroupherServer.Test.Query.PagedJobs do
114115
assert not the_job["viewerHasViewed"]
115116
assert not the_job["viewerHasUpvoted"]
116117
assert not the_job["viewerHasCollected"]
118+
assert not the_job["viewerHasReported"]
117119

118120
{:ok, _} = CMS.read_article(:job, job.id, user)
119121
{:ok, _} = CMS.upvote_article(:job, job.id, user)
120122
{:ok, _} = CMS.collect_article(:job, job.id, user)
123+
{:ok, _} = CMS.report_article(:job, job.id, "reason", "attr_info", user)
121124

122125
results = user_conn |> query_result(@query, variables, "pagedJobs")
123126
the_job = Enum.find(results["entries"], &(&1["id"] == to_string(job.id)))
124127
assert the_job["viewerHasViewed"]
125128
assert the_job["viewerHasUpvoted"]
126129
assert the_job["viewerHasCollected"]
130+
assert the_job["viewerHasReported"]
127131
end
128132
end
129133

test/groupher_server_web/query/cms/paged_posts_test.exs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,13 @@ defmodule GroupherServer.Test.Query.PagedPosts do
165165
viewerHasCollected
166166
viewerHasUpvoted
167167
viewerHasViewed
168+
viewerHasReported
168169
}
169170
totalCount
170171
}
171172
}
172173
"""
173-
@tag :wip3
174+
@tag :wip2
174175
test "has_xxx state should work", ~m(user)a do
175176
user_conn = simu_conn(:user, user)
176177
{:ok, community} = db_insert(:community)
@@ -187,16 +188,19 @@ defmodule GroupherServer.Test.Query.PagedPosts do
187188
assert not the_post["viewerHasViewed"]
188189
assert not the_post["viewerHasUpvoted"]
189190
assert not the_post["viewerHasCollected"]
191+
assert not the_post["viewerHasReported"]
190192

191193
{:ok, _} = CMS.read_article(:post, post.id, user)
192194
{:ok, _} = CMS.upvote_article(:post, post.id, user)
193195
{:ok, _} = CMS.collect_article(:post, post.id, user)
196+
{:ok, _} = CMS.report_article(:post, post.id, "reason", "attr_info", user)
194197

195198
results = user_conn |> query_result(@query, variables, "pagedPosts")
196199
the_post = Enum.find(results["entries"], &(&1["id"] == to_string(post.id)))
197200
assert the_post["viewerHasViewed"]
198201
assert the_post["viewerHasUpvoted"]
199202
assert the_post["viewerHasCollected"]
203+
assert the_post["viewerHasReported"]
200204
end
201205
end
202206

test/groupher_server_web/query/cms/paged_repos_test.exs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ defmodule GroupherServer.Test.Query.PagedRepos do
8888
viewerHasCollected
8989
viewerHasUpvoted
9090
viewerHasViewed
91+
viewerHasReported
9192
}
9293
totalCount
9394
}
9495
}
9596
"""
96-
@tag :wip3
97+
@tag :wip2
9798
test "has_xxx state should work", ~m(user)a do
9899
user_conn = simu_conn(:user, user)
99100
{:ok, community} = db_insert(:community)
@@ -110,16 +111,19 @@ defmodule GroupherServer.Test.Query.PagedRepos do
110111
assert not the_repo["viewerHasViewed"]
111112
assert not the_repo["viewerHasUpvoted"]
112113
assert not the_repo["viewerHasCollected"]
114+
assert not the_repo["viewerHasReported"]
113115

114116
{:ok, _} = CMS.read_article(:repo, repo.id, user)
115117
{:ok, _} = CMS.upvote_article(:repo, repo.id, user)
116118
{:ok, _} = CMS.collect_article(:repo, repo.id, user)
119+
{:ok, _} = CMS.report_article(:repo, repo.id, "reason", "attr_info", user)
117120

118121
results = user_conn |> query_result(@query, variables, "pagedRepos")
119122
the_repo = Enum.find(results["entries"], &(&1["id"] == to_string(repo.id)))
120123
assert the_repo["viewerHasViewed"]
121124
assert the_repo["viewerHasUpvoted"]
122125
assert the_repo["viewerHasCollected"]
126+
assert the_repo["viewerHasReported"]
123127
end
124128
end
125129

0 commit comments

Comments
 (0)