@@ -12,24 +12,22 @@ defmodule CodeCorps.GitHub.Event.InstallationRepositoriesTest do
1212 Repo
1313 }
1414
15- describe "handle/2 " do
15+ describe "handle/1 " do
1616 @ payload load_event_fixture ( "installation_repositories_added" )
1717
1818 test "marks event as errored if invalid action" do
1919 payload = @ payload |> Map . put ( "action" , "foo" )
20- event = build ( :github_event , action: "foo" , type: "installation_repositories" )
21- assert { :error , :unexpected_action } == InstallationRepositories . handle ( event , payload )
20+ assert { :error , :unexpected_action } == InstallationRepositories . handle ( payload )
2221 end
2322
2423 test "marks event as errored if invalid payload" do
25- event = build ( :github_event , action: "added" , type: "installation_repositories" )
2624 payload = @ payload |> Map . delete ( "action" )
2725 assert { :error , :unexpected_payload } ==
28- InstallationRepositories . handle ( event , payload )
26+ InstallationRepositories . handle ( payload )
2927 end
3028 end
3129
32- describe "handle/2 for InstallationRepositories::added" do
30+ describe "handle/1 for InstallationRepositories::added" do
3331 @ payload load_event_fixture ( "installation_repositories_added" )
3432
3533 test "creates repos" do
@@ -40,8 +38,7 @@ defmodule CodeCorps.GitHub.Event.InstallationRepositoriesTest do
4038
4139 % { id: installation_id } = insert ( :github_app_installation , github_id: installation_github_id )
4240
43- event = build ( :github_event , action: "added" , type: "installation_repositories" )
44- { :ok , [ % GithubRepo { } , % GithubRepo { } ] } = InstallationRepositories . handle ( event , @ payload )
41+ { :ok , [ % GithubRepo { } , % GithubRepo { } ] } = InstallationRepositories . handle ( @ payload )
4542
4643 github_repo_1 = Repo . get_by ( GithubRepo , github_id: repo_1_payload [ "id" ] )
4744 assert github_repo_1
@@ -63,8 +60,7 @@ defmodule CodeCorps.GitHub.Event.InstallationRepositoriesTest do
6360 installation = insert ( :github_app_installation , github_id: installation_github_id )
6461 preinserted_repo = insert ( :github_repo , github_app_installation: installation , github_id: repo_1_payload [ "id" ] )
6562
66- event = build ( :github_event , action: "added" , type: "installation_repositories" )
67- { :ok , [ % GithubRepo { } , % GithubRepo { } ] } = InstallationRepositories . handle ( event , @ payload )
63+ { :ok , [ % GithubRepo { } , % GithubRepo { } ] } = InstallationRepositories . handle ( @ payload )
6864
6965 github_repo_1 = Repo . get_by ( GithubRepo , github_id: repo_1_payload [ "id" ] )
7066 assert github_repo_1 . id == preinserted_repo . id
@@ -78,23 +74,20 @@ defmodule CodeCorps.GitHub.Event.InstallationRepositoriesTest do
7874 end
7975
8076 test "marks event as errored if invalid instalation payload" do
81- event = insert ( :github_event , action: "added" , type: "installation_repositories" )
82- assert { :error , :unexpected_payload } == InstallationRepositories . handle ( event , @ payload |> Map . put ( "installation" , "foo" ) )
77+ assert { :error , :unexpected_payload } == InstallationRepositories . handle ( @ payload |> Map . put ( "installation" , "foo" ) )
8378 end
8479
8580 test "marks event as errored if invalid repo payload" do
86- event = insert ( :github_event , action: "added" , type: "installation_repositories" )
8781 insert ( :github_app_installation , github_id: @ payload [ "installation" ] [ "id" ] )
88- assert { :error , :unexpected_payload } == InstallationRepositories . handle ( event , @ payload |> Map . put ( "repositories_added" , [ "foo" ] ) )
82+ assert { :error , :unexpected_payload } == InstallationRepositories . handle ( @ payload |> Map . put ( "repositories_added" , [ "foo" ] ) )
8983 end
9084
9185 test "marks event as errored if no installation" do
92- event = insert ( :github_event , action: "added" , type: "installation_repositories" )
93- assert { :error , :unmatched_installation } == InstallationRepositories . handle ( event , @ payload )
86+ assert { :error , :unmatched_installation } == InstallationRepositories . handle ( @ payload )
9487 end
9588 end
9689
97- describe "handle/2 for InstallationRepositories::removed" do
90+ describe "handle/1 for InstallationRepositories::removed" do
9891 @ payload load_event_fixture ( "installation_repositories_removed" )
9992
10093 test "deletes github repos and associated project github repos" do
@@ -108,8 +101,7 @@ defmodule CodeCorps.GitHub.Event.InstallationRepositoriesTest do
108101 insert ( :project_github_repo , project: project , github_repo: github_repo_1 )
109102 insert ( :github_repo , github_app_installation: installation , github_id: repo_2_payload [ "id" ] )
110103
111- event = build ( :github_event , action: "removed" , type: "installation_repositories" )
112- { :ok , [ % GithubRepo { } , % GithubRepo { } ] } = InstallationRepositories . handle ( event , @ payload )
104+ { :ok , [ % GithubRepo { } , % GithubRepo { } ] } = InstallationRepositories . handle ( @ payload )
113105
114106 assert Repo . aggregate ( GithubRepo , :count , :id ) == 0
115107 assert Repo . aggregate ( ProjectGithubRepo , :count , :id ) == 0
@@ -125,31 +117,27 @@ defmodule CodeCorps.GitHub.Event.InstallationRepositoriesTest do
125117 github_repo_1 = insert ( :github_repo , github_app_installation: installation , github_id: repo_1_payload [ "id" ] )
126118 insert ( :project_github_repo , project: project , github_repo: github_repo_1 )
127119
128- event = build ( :github_event , action: "removed" , type: "installation_repositories" )
129- { :ok , [ % GithubRepo { } ] } = InstallationRepositories . handle ( event , @ payload )
120+ { :ok , [ % GithubRepo { } ] } = InstallationRepositories . handle ( @ payload )
130121
131122 assert Repo . aggregate ( GithubRepo , :count , :id ) == 0
132123 assert Repo . aggregate ( ProjectGithubRepo , :count , :id ) == 0
133124 end
134125
135126 test "marks event as errored if invalid instalation payload" do
136- event = build ( :github_event , action: "removed" , type: "installation_repositories" )
137127 payload = @ payload |> Map . put ( "installation" , "foo" )
138128 assert { :error , :unexpected_payload } ==
139- InstallationRepositories . handle ( event , payload )
129+ InstallationRepositories . handle ( payload )
140130 end
141131
142132 test "marks event as errored if invalid repo payload" do
143- event = build ( :github_event , action: "removed" , type: "installation_repositories" )
144133 insert ( :github_app_installation , github_id: @ payload [ "installation" ] [ "id" ] )
145134 payload = @ payload |> Map . put ( "repositories_removed" , [ "foo" ] )
146135 assert { :error , :unexpected_payload } ==
147- InstallationRepositories . handle ( event , payload )
136+ InstallationRepositories . handle ( payload )
148137 end
149138
150139 test "marks event as errored if no installation" do
151- event = build ( :github_event , action: "added" , type: "installation_repositories" )
152- assert { :error , :unmatched_installation } == InstallationRepositories . handle ( event , @ payload )
140+ assert { :error , :unmatched_installation } == InstallationRepositories . handle ( @ payload )
153141 end
154142 end
155143end
0 commit comments