@@ -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
221280end
0 commit comments