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

Commit 69f37b6

Browse files
committed
refactor(cite): naming adjust
1 parent 0733508 commit 69f37b6

File tree

8 files changed

+161
-34
lines changed

8 files changed

+161
-34
lines changed

lib/groupher_server/cms/delegates/hooks/cite.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ defmodule GroupherServer.CMS.Delegate.Hooks.Cite do
2121
cited_type: thread or comment
2222
artiment: article or comment
2323
# cited_article_comment_id, [xxx_article]_id, [block_id, block2_id, ...],
24+
25+
注意 cited_by_type 不能命名为 cited_by_thread
26+
27+
因为 cited_by_thread 无法表示这样的语义:
28+
# 某评论被 post 以 comment link 的方式引用了
2429
"""
2530

2631
import Ecto.Query, warn: false

test/groupher_server/cms/hooks/cite_blog_test.exs

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ defmodule GroupherServer.Test.CMS.Hooks.CiteBlog do
3131
test "cited multi blog should work", ~m(user community blog2 blog3 blog4 blog5 blog_attrs)a do
3232
body =
3333
mock_rich_text(
34-
~s(the <a href=#{@site_host}/blog/#{blog2.id} /> and <a href=#{@site_host}/blog/#{
35-
blog2.id
36-
}>same la</a> is awesome, the <a href=#{@site_host}/blog/#{blog3.id}></a> is awesome too.),
34+
~s(the <a href=#{@site_host}/blog/#{blog2.id} /> and <a href=#{@site_host}/blog/#{blog2.id}>same la</a> is awesome, the <a href=#{
35+
@site_host
36+
}/blog/#{blog3.id}></a> is awesome too.),
3737
# second paragraph
3838
~s(the paragraph 2 <a href=#{@site_host}/blog/#{blog2.id} class=#{blog2.title}> again</a>, the paragraph 2 <a href=#{
3939
@site_host
@@ -90,6 +90,7 @@ defmodule GroupherServer.Test.CMS.Hooks.CiteBlog do
9090
assert cited_comment.meta.citing_count == 0
9191
end
9292

93+
@tag :wip
9394
test "can cite blog's comment in blog", ~m(community user blog blog2 blog_attrs)a do
9495
{:ok, comment} = CMS.create_comment(:blog, blog.id, mock_rich_text("hello"), user)
9596

@@ -104,9 +105,11 @@ defmodule GroupherServer.Test.CMS.Hooks.CiteBlog do
104105
{:ok, comment} = ORM.find(Comment, comment.id)
105106
assert comment.meta.citing_count == 1
106107

107-
{:ok, cite_content} = ORM.find_by(CitedArtiment, %{cited_by_id: comment.id})
108-
assert blog.id == cite_content.blog_id
109-
assert cite_content.cited_by_type == "COMMENT"
108+
{:ok, cited_content} = ORM.find_by(CitedArtiment, %{cited_by_id: comment.id})
109+
110+
# 被 blog 以 comment link 的方式引用了
111+
assert cited_content.blog_id == blog.id
112+
assert cited_content.cited_by_type == "COMMENT"
110113
end
111114

112115
test "can cite a comment in a comment", ~m(user blog)a do
@@ -124,18 +127,18 @@ defmodule GroupherServer.Test.CMS.Hooks.CiteBlog do
124127
{:ok, cited_comment} = ORM.find(Comment, cited_comment.id)
125128
assert cited_comment.meta.citing_count == 1
126129

127-
{:ok, cite_content} = ORM.find_by(CitedArtiment, %{cited_by_id: cited_comment.id})
128-
assert comment.id == cite_content.comment_id
129-
assert cited_comment.id == cite_content.cited_by_id
130-
assert cite_content.cited_by_type == "COMMENT"
130+
{:ok, cited_content} = ORM.find_by(CitedArtiment, %{cited_by_id: cited_comment.id})
131+
assert comment.id == cited_content.comment_id
132+
assert cited_comment.id == cited_content.cited_by_id
133+
assert cited_content.cited_by_type == "COMMENT"
131134
end
132135

133136
test "can cited blog inside a comment", ~m(user blog blog2 blog3 blog4 blog5)a do
134137
comment_body =
135138
mock_rich_text(
136-
~s(the <a href=#{@site_host}/blog/#{blog2.id} /> and <a href=#{@site_host}/blog/#{
137-
blog2.id
138-
}>same la</a> is awesome, the <a href=#{@site_host}/blog/#{blog3.id}></a> is awesome too.),
139+
~s(the <a href=#{@site_host}/blog/#{blog2.id} /> and <a href=#{@site_host}/blog/#{blog2.id}>same la</a> is awesome, the <a href=#{
140+
@site_host
141+
}/blog/#{blog3.id}></a> is awesome too.),
139142
# second paragraph
140143
~s(the paragraph 2 <a href=#{@site_host}/blog/#{blog2.id} class=#{blog2.title}> again</a>, the paragraph 2 <a href=#{
141144
@site_host
@@ -218,4 +221,60 @@ defmodule GroupherServer.Test.CMS.Hooks.CiteBlog do
218221
assert result.total_count == 3
219222
end
220223
end
224+
225+
describe "[cross cite]" do
226+
test "can citing multi type thread and comment in one time", ~m(user community blog2)a do
227+
blog_attrs = mock_attrs(:blog, %{community_id: community.id})
228+
blog_attrs = mock_attrs(:blog, %{community_id: community.id})
229+
blog_attrs = mock_attrs(:blog, %{community_id: community.id})
230+
231+
body = mock_rich_text(~s(the <a href=#{@site_host}/blog/#{blog2.id} />))
232+
233+
{:ok, blog} = CMS.create_article(community, :blog, Map.merge(blog_attrs, %{body: body}), user)
234+
235+
Hooks.Cite.handle(blog)
236+
237+
Process.sleep(1000)
238+
239+
{:ok, blog} = CMS.create_article(community, :blog, Map.merge(blog_attrs, %{body: body}), user)
240+
Hooks.Cite.handle(blog)
241+
242+
Process.sleep(1000)
243+
244+
comment_body = mock_comment(~s(the <a href=#{@site_host}/blog/#{blog2.id} />))
245+
{:ok, comment} = CMS.create_comment(:blog, blog.id, comment_body, user)
246+
247+
Hooks.Cite.handle(comment)
248+
249+
Process.sleep(1000)
250+
251+
{:ok, blog} =
252+
CMS.create_article(community, :blog, Map.merge(blog_attrs, %{body: body}), user)
253+
254+
Hooks.Cite.handle(blog)
255+
256+
{:ok, result} = CMS.paged_citing_contents("BLOG", blog2.id, %{page: 1, size: 10})
257+
# IO.inspect(result, label: "the result")
258+
259+
assert result.total_count == 4
260+
261+
result_blog = result.entries |> List.first()
262+
result_blog = result.entries |> Enum.at(1)
263+
result_comment = result.entries |> Enum.at(2)
264+
result_blog = result.entries |> List.last()
265+
266+
assert result_blog.id == blog.id
267+
assert result_blog.thread == :blog
268+
269+
assert result_blog.id == blog.id
270+
assert result_blog.thread == :blog
271+
272+
assert result_comment.id == blog.id
273+
assert result_comment.thread == :blog
274+
assert result_comment.comment_id == comment.id
275+
276+
assert result_blog.id == blog.id
277+
assert result_blog.thread == :blog
278+
end
279+
end
221280
end

test/groupher_server/cms/hooks/cite_job_test.exs

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ defmodule GroupherServer.Test.CMS.Hooks.CiteJob do
9090
assert cited_comment.meta.citing_count == 0
9191
end
9292

93+
@tag :wip
9394
test "can cite job's comment in job", ~m(community user job job2 job_attrs)a do
9495
{:ok, comment} = CMS.create_comment(:job, job.id, mock_rich_text("hello"), user)
9596

@@ -104,9 +105,11 @@ defmodule GroupherServer.Test.CMS.Hooks.CiteJob do
104105
{:ok, comment} = ORM.find(Comment, comment.id)
105106
assert comment.meta.citing_count == 1
106107

107-
{:ok, cite_content} = ORM.find_by(CitedArtiment, %{cited_by_id: comment.id})
108-
assert job.id == cite_content.job_id
109-
assert cite_content.cited_by_type == "COMMENT"
108+
{:ok, cited_content} = ORM.find_by(CitedArtiment, %{cited_by_id: comment.id})
109+
110+
# 被 job 以 comment link 的方式引用了
111+
assert cited_content.job_id == job.id
112+
assert cited_content.cited_by_type == "COMMENT"
110113
end
111114

112115
test "can cite a comment in a comment", ~m(user job)a do
@@ -124,10 +127,10 @@ defmodule GroupherServer.Test.CMS.Hooks.CiteJob do
124127
{:ok, cited_comment} = ORM.find(Comment, cited_comment.id)
125128
assert cited_comment.meta.citing_count == 1
126129

127-
{:ok, cite_content} = ORM.find_by(CitedArtiment, %{cited_by_id: cited_comment.id})
128-
assert comment.id == cite_content.comment_id
129-
assert cited_comment.id == cite_content.cited_by_id
130-
assert cite_content.cited_by_type == "COMMENT"
130+
{:ok, cited_content} = ORM.find_by(CitedArtiment, %{cited_by_id: cited_comment.id})
131+
assert comment.id == cited_content.comment_id
132+
assert cited_comment.id == cited_content.cited_by_id
133+
assert cited_content.cited_by_type == "COMMENT"
131134
end
132135

133136
test "can cited job inside a comment", ~m(user job job2 job3 job4 job5)a do
@@ -182,6 +185,7 @@ defmodule GroupherServer.Test.CMS.Hooks.CiteJob do
182185

183186
job_attrs = job_attrs |> Map.merge(%{body: body})
184187
{:ok, job_x} = CMS.create_article(community, :job, job_attrs, user)
188+
185189
Process.sleep(1000)
186190
body = mock_rich_text(~s(the <a href=#{@site_host}/job/#{job2.id} />))
187191
job_attrs = job_attrs |> Map.merge(%{body: body})
@@ -217,4 +221,60 @@ defmodule GroupherServer.Test.CMS.Hooks.CiteJob do
217221
assert result.total_count == 3
218222
end
219223
end
224+
225+
describe "[cross cite]" do
226+
test "can citing multi type thread and comment in one time", ~m(user community job2)a do
227+
job_attrs = mock_attrs(:job, %{community_id: community.id})
228+
job_attrs = mock_attrs(:job, %{community_id: community.id})
229+
blog_attrs = mock_attrs(:blog, %{community_id: community.id})
230+
231+
body = mock_rich_text(~s(the <a href=#{@site_host}/job/#{job2.id} />))
232+
233+
{:ok, job} = CMS.create_article(community, :job, Map.merge(job_attrs, %{body: body}), user)
234+
235+
Hooks.Cite.handle(job)
236+
237+
Process.sleep(1000)
238+
239+
{:ok, job} = CMS.create_article(community, :job, Map.merge(job_attrs, %{body: body}), user)
240+
Hooks.Cite.handle(job)
241+
242+
Process.sleep(1000)
243+
244+
comment_body = mock_comment(~s(the <a href=#{@site_host}/job/#{job2.id} />))
245+
{:ok, comment} = CMS.create_comment(:job, job.id, comment_body, user)
246+
247+
Hooks.Cite.handle(comment)
248+
249+
Process.sleep(1000)
250+
251+
{:ok, blog} =
252+
CMS.create_article(community, :blog, Map.merge(blog_attrs, %{body: body}), user)
253+
254+
Hooks.Cite.handle(blog)
255+
256+
{:ok, result} = CMS.paged_citing_contents("JOB", job2.id, %{page: 1, size: 10})
257+
# IO.inspect(result, label: "the result")
258+
259+
assert result.total_count == 4
260+
261+
result_job = result.entries |> List.first()
262+
result_job = result.entries |> Enum.at(1)
263+
result_comment = result.entries |> Enum.at(2)
264+
result_blog = result.entries |> List.last()
265+
266+
assert result_job.id == job.id
267+
assert result_job.thread == :job
268+
269+
assert result_job.id == job.id
270+
assert result_job.thread == :job
271+
272+
assert result_comment.id == job.id
273+
assert result_comment.thread == :job
274+
assert result_comment.comment_id == comment.id
275+
276+
assert result_blog.id == blog.id
277+
assert result_blog.thread == :blog
278+
end
279+
end
220280
end

test/groupher_server/cms/hooks/cite_post_test.exs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ defmodule GroupherServer.Test.CMS.Hooks.CitePost do
9090
assert cited_comment.meta.citing_count == 0
9191
end
9292

93+
@tag :wip
9394
test "can cite post's comment in post", ~m(community user post post2 post_attrs)a do
9495
{:ok, comment} = CMS.create_comment(:post, post.id, mock_rich_text("hello"), user)
9596

@@ -104,9 +105,11 @@ defmodule GroupherServer.Test.CMS.Hooks.CitePost do
104105
{:ok, comment} = ORM.find(Comment, comment.id)
105106
assert comment.meta.citing_count == 1
106107

107-
{:ok, cite_content} = ORM.find_by(CitedArtiment, %{cited_by_id: comment.id})
108-
assert post.id == cite_content.post_id
109-
assert cite_content.cited_by_type == "COMMENT"
108+
{:ok, cited_content} = ORM.find_by(CitedArtiment, %{cited_by_id: comment.id})
109+
110+
# 被 post 以 comment link 的方式引用了
111+
assert cited_content.post_id == post.id
112+
assert cited_content.cited_by_type == "COMMENT"
110113
end
111114

112115
test "can cite a comment in a comment", ~m(user post)a do
@@ -124,10 +127,10 @@ defmodule GroupherServer.Test.CMS.Hooks.CitePost do
124127
{:ok, cited_comment} = ORM.find(Comment, cited_comment.id)
125128
assert cited_comment.meta.citing_count == 1
126129

127-
{:ok, cite_content} = ORM.find_by(CitedArtiment, %{cited_by_id: cited_comment.id})
128-
assert comment.id == cite_content.comment_id
129-
assert cited_comment.id == cite_content.cited_by_id
130-
assert cite_content.cited_by_type == "COMMENT"
130+
{:ok, cited_content} = ORM.find_by(CitedArtiment, %{cited_by_id: cited_comment.id})
131+
assert comment.id == cited_content.comment_id
132+
assert cited_comment.id == cited_content.cited_by_id
133+
assert cited_content.cited_by_type == "COMMENT"
131134
end
132135

133136
test "can cited post inside a comment", ~m(user post post2 post3 post4 post5)a do

test/groupher_server/cms/hooks/notify_blog_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyBlog do
135135
end
136136

137137
describe "[comment notify]" do
138-
@tag :wip
138+
@tag :wip2
139139
test "blog author should get notify after some one comment on it", ~m(user2 blog)a do
140140
{:ok, blog} = preload_author(blog)
141141

@@ -155,7 +155,7 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyBlog do
155155
assert user_exist_in?(user2, notify.from_users)
156156
end
157157

158-
@tag :wip
158+
@tag :wip2
159159
test "blog comment author should get notify after some one reply it", ~m(user2 user3 blog)a do
160160
{:ok, blog} = preload_author(blog)
161161

test/groupher_server/cms/hooks/notify_job_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyJob do
135135
end
136136

137137
describe "[comment notify]" do
138-
@tag :wip
138+
@tag :wip2
139139
test "job author should get notify after some one comment on it", ~m(user2 job)a do
140140
{:ok, job} = preload_author(job)
141141

@@ -155,7 +155,7 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyJob do
155155
assert user_exist_in?(user2, notify.from_users)
156156
end
157157

158-
@tag :wip
158+
@tag :wip2
159159
test "job comment author should get notify after some one reply it", ~m(user2 user3 job)a do
160160
{:ok, job} = preload_author(job)
161161

test/groupher_server/cms/hooks/notify_post_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyPost do
135135
end
136136

137137
describe "[comment notify]" do
138-
@tag :wip
138+
@tag :wip2
139139
test "post author should get notify after some one comment on it", ~m(user2 post)a do
140140
{:ok, post} = preload_author(post)
141141

@@ -155,7 +155,7 @@ defmodule GroupherServer.Test.CMS.Hooks.NotifyPost do
155155
assert user_exist_in?(user2, notify.from_users)
156156
end
157157

158-
@tag :wip
158+
@tag :wip2
159159
test "post comment author should get notify after some one reply it", ~m(user2 user3 post)a do
160160
{:ok, post} = preload_author(post)
161161

test/groupher_server/delivery/notification_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ defmodule GroupherServer.Test.Delivery.Notification do
172172
end
173173

174174
describe "basic thread support" do
175-
@tag :wip
175+
@tag :wip2
176176
test "support upvote", ~m(post user user2 notify_attrs)a do
177177
notify_attrs
178178
|> Map.merge(%{

0 commit comments

Comments
 (0)