@@ -143,52 +143,40 @@ defmodule GroupherServer.Test.Query.PostComment do
143
143
}
144
144
}
145
145
"""
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
148
147
body = "this is a test comment"
149
148
150
149
{ :ok , community } = db_insert ( :community )
151
150
{ :ok , post } = CMS . create_content ( community , :post , mock_attrs ( :post ) , user )
152
151
{ :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 )
160
154
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 )
165
157
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
+ )
169
162
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
+ )
175
167
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" )
180
170
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" )
185
173
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
190
176
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" )
192
180
end
193
181
end
194
182
0 commit comments