@@ -46,7 +46,7 @@ defmodule Test.EpochtalkServerWeb.Controllers.Thread do
4646 test "given an id for existing board, gets threads" , % {
4747 conn: conn ,
4848 board: board ,
49- threads: created_threads
49+ threads: factory_threads
5050 } do
5151 response =
5252 conn
@@ -56,10 +56,9 @@ defmodule Test.EpochtalkServerWeb.Controllers.Thread do
5656 assert Map . has_key? ( response , "normal" ) == true
5757 assert Map . has_key? ( response , "sticky" ) == true
5858
59+ # check thread keys
5960 normal_threads = response [ "normal" ]
6061 first_thread = normal_threads |> List . first ( )
61- first_created_thread = created_threads |> List . first ( )
62- first_created_thread_attributes = first_created_thread . attributes
6362 assert Map . has_key? ( first_thread , "created_at" ) == true
6463 assert Map . has_key? ( first_thread , "last_post_avatar" ) == true
6564 assert Map . has_key? ( first_thread , "last_post_created_at" ) == true
@@ -77,15 +76,22 @@ defmodule Test.EpochtalkServerWeb.Controllers.Thread do
7776 assert Map . has_key? ( first_thread , "user" ) == true
7877 assert Map . has_key? ( first_thread , "view_count" ) == true
7978
80- assert Map . get ( first_thread , "id" ) == first_created_thread . post . thread . id
81- assert Map . get ( first_thread , "locked" ) == Map . get ( first_created_thread_attributes , "locked" )
79+ # compare to factory results
80+ factory_threads = factory_threads |> Enum . sort ( & ( & 1 . post . thread . id < & 2 . post . thread . id ) )
8281
83- assert Map . get ( first_thread , "moderated" ) ==
84- Map . get ( first_created_thread_attributes , "moderated" )
82+ Enum . zip ( normal_threads , factory_threads )
83+ |> Enum . each ( fn { normal_thread , factory_thread } ->
84+ factory_thread_attributes = factory_thread . attributes
85+ assert Map . get ( normal_thread , "id" ) == factory_thread . post . thread . id
86+ assert Map . get ( normal_thread , "locked" ) == Map . get ( factory_thread_attributes , "locked" )
8587
86- assert Map . get ( first_thread , "slug" ) == Map . get ( first_created_thread_attributes , "slug" )
87- assert Map . get ( first_thread , "sticky" ) == Map . get ( first_created_thread_attributes , "sticky" )
88- assert Map . get ( first_thread , "title" ) == Map . get ( first_created_thread_attributes , "title" )
88+ assert Map . get ( normal_thread , "moderated" ) ==
89+ Map . get ( normal_thread , "moderated" )
90+
91+ assert Map . get ( normal_thread , "slug" ) == Map . get ( factory_thread_attributes , "slug" )
92+ assert Map . get ( normal_thread , "sticky" ) == Map . get ( factory_thread_attributes , "sticky" )
93+ assert Map . get ( normal_thread , "title" ) == Map . get ( factory_thread_attributes , "title" )
94+ end )
8995 end
9096
9197 test "given an id for board above unauthenticated user priority, does not get threads" , % {
0 commit comments