@@ -12,6 +12,12 @@ defmodule CodeCorps.Sync.User.RecordLinkerTest do
1212 }
1313 alias CodeCorps.GitHub.Adapters.User , as: UserAdapter
1414
15+ def remove_nils ( payload ) do
16+ payload
17+ |> Enum . reject ( fn { _ , v } -> is_nil ( v ) end )
18+ |> Map . new ( )
19+ end
20+
1521 describe "link_to/2 for comments" do
1622 @ payload load_event_fixture ( "issue_comment_created" )
1723 @ bot_payload load_event_fixture ( "issue_comment_created_by_bot" )
@@ -43,7 +49,7 @@ defmodule CodeCorps.Sync.User.RecordLinkerTest do
4349
4450 test "finds user by github id if none is found by comment association" do
4551 % { "comment" => % { "id" => github_id } = comment } = @ payload
46- attributes = UserAdapter . to_user ( @ user_payload )
52+ attributes = @ user_payload |> UserAdapter . to_user ( ) |> remove_nils ( )
4753 preinserted_user = insert ( :user , attributes )
4854 github_comment = insert ( :github_comment , github_id: github_id )
4955
@@ -58,7 +64,7 @@ defmodule CodeCorps.Sync.User.RecordLinkerTest do
5864 github_comment = insert ( :github_comment , github_id: github_id )
5965 { :ok , % User { } = returned_user } = RecordLinker . link_to ( github_comment , comment )
6066
61- created_attributes = UserAdapter . to_user ( @ user_payload )
67+ created_attributes = @ user_payload |> UserAdapter . to_user ( ) |> remove_nils ( )
6268 created_user = Repo . get_by ( User , created_attributes )
6369 assert created_user . id == returned_user . id
6470 end
@@ -86,7 +92,7 @@ defmodule CodeCorps.Sync.User.RecordLinkerTest do
8692 github_comment = insert ( :github_comment , github_id: github_id )
8793 { :ok , % User { } = returned_user } = RecordLinker . link_to ( github_comment , comment )
8894
89- created_attributes = UserAdapter . to_user ( @ bot_user_payload )
95+ created_attributes = @ bot_user_payload |> UserAdapter . to_user ( ) |> remove_nils ( )
9096 created_user = Repo . get_by ( User , created_attributes )
9197 assert created_user . id == returned_user . id
9298 end
@@ -142,7 +148,7 @@ defmodule CodeCorps.Sync.User.RecordLinkerTest do
142148
143149 test "returns user by github id if no user by task association found" do
144150 % { "issue" => % { "number" => number } = issue } = @ payload
145- attributes = UserAdapter . to_user ( @ user_payload )
151+ attributes = @ user_payload |> UserAdapter . to_user ( ) |> remove_nils ( )
146152 preinserted_user = insert ( :user , attributes )
147153 github_issue = insert ( :github_issue , number: number )
148154
@@ -157,7 +163,7 @@ defmodule CodeCorps.Sync.User.RecordLinkerTest do
157163 github_issue = insert ( :github_issue , number: number )
158164 { :ok , % User { } = returned_user } = RecordLinker . link_to ( github_issue , issue )
159165
160- created_attributes = UserAdapter . to_user ( @ user_payload )
166+ created_attributes = @ user_payload |> UserAdapter . to_user ( ) |> remove_nils ( )
161167 created_user = Repo . get_by ( User , created_attributes )
162168 assert created_user . id == returned_user . id
163169 end
@@ -191,7 +197,7 @@ defmodule CodeCorps.Sync.User.RecordLinkerTest do
191197 github_issue = insert ( :github_issue , number: number )
192198 { :ok , % User { } = returned_user } = RecordLinker . link_to ( github_issue , issue )
193199
194- created_attributes = UserAdapter . to_user ( @ bot_user_payload )
200+ created_attributes = @ bot_user_payload |> UserAdapter . to_user ( ) |> remove_nils ( )
195201 created_user = Repo . get_by ( User , created_attributes )
196202 assert created_user . id == returned_user . id
197203 end
0 commit comments