@@ -143,52 +143,40 @@ defmodule GroupherServer.Test.Query.PostComment do
143143 }
144144 }
145145 """
146- @ tag :pain_in_ass
147- test "top N per Group test" , ~m( user guest_conn) a do
146+ test "top N per Group test v2" , ~m( user guest_conn) a do
148147 body = "this is a test comment"
149148
150149 { :ok , community } = db_insert ( :community )
151150 { :ok , post } = CMS . create_content ( community , :post , mock_attrs ( :post ) , user )
152151 { :ok , post2 } = CMS . create_content ( community , :post , mock_attrs ( :post ) , user )
153- # {:ok, users_list} = db_insert_multi(:user, 10)
154-
155- CMS . create_comment ( :post , post . id , % { community: community . raw , body: body } , user )
156- CMS . create_comment ( :post , post2 . id , % { community: community . raw , body: body } , user )
157-
158- variables = % { filter: % { community: community . raw } }
159- results = guest_conn |> query_result ( @ query , variables , "pagedPosts" )
152+ { :ok , users_list } = db_insert_multi ( :user , 10 )
153+ { :ok , users_list2 } = db_insert_multi ( :user , 10 )
160154
161- # for test window function
162- _commentsParticipators = results [ "entries" ]
163- # IO.inspect(commentsParticipators, label: "commentsParticipators->")
164- end
155+ post_last_comment_user_id = users_list |> List . last ( ) |> Map . get ( :id )
156+ post2_last_comment_user_id = users_list2 |> List . last ( ) |> Map . get ( :id )
165157
166- # ~m(user guest_conn)a do
167- test "top N per Group test v2" do
168- # body = "this is a test comment"
158+ Enum . each (
159+ users_list ,
160+ & CMS . create_comment ( :post , post . id , % { community: community . raw , body: body } , & 1 )
161+ )
169162
170- # {:ok, community} = db_insert(:community)
171- # {:ok, post} = CMS.create_content(community, :post, mock_attrs(:post), user)
172- # {:ok, post2} = CMS.create_content(community, :post, mock_attrs(:post), user)
173- # {:ok, users_list} = db_insert_multi(:user, 10)
174- # {:ok, users_list2} = db_insert_multi(:user, 10)
163+ Enum . each (
164+ users_list2 ,
165+ & CMS . create_comment ( :post , post2 . id , % { community: community . raw , body: body } , & 1 )
166+ )
175167
176- # Enum.each(
177- # users_list,
178- # &CMS.create_comment(:post, post.id, %{body: body}, &1)
179- # )
168+ variables = % { filter: % { community: community . raw } }
169+ results = guest_conn |> query_result ( @ query , variables , "pagedPosts" )
180170
181- # Enum.each(
182- # users_list2,
183- # &CMS.create_comment(:post, post2.id, body, &1)
184- # )
171+ first_result = results [ "entries" ] |> List . first ( ) |> Map . get ( "commentsParticipators" )
172+ last_result = results [ "entries" ] |> List . last ( ) |> Map . get ( "commentsParticipators" )
185173
186- # variables = %{filter: %{community: community.raw}}
187- # results = guest_conn |> query_result(@query, variables, "pagedPosts")
188- # commentsParticipators =
189- # results["entries"] |> List.first() |> Map.get("commentsParticipators")
174+ assert 5 == first_result |> length
175+ assert 5 == last_result |> length
190176
191- # IO.inspect(commentsParticipators, label: "commentsParticipators->")
177+ # 默认显示最新评论的登陆用户
178+ assert to_string ( post_last_comment_user_id ) == first_result |> List . first ( ) |> Map . get ( "id" )
179+ assert to_string ( post2_last_comment_user_id ) == last_result |> List . first ( ) |> Map . get ( "id" )
192180 end
193181 end
194182
0 commit comments