@@ -8,6 +8,7 @@ defmodule CodeCorps.GitHub.SyncTest do
88
99 alias CodeCorps . {
1010 Comment ,
11+ GitHub.Adapters ,
1112 GitHub.Sync ,
1213 GithubAppInstallation ,
1314 GithubComment ,
@@ -21,6 +22,8 @@ defmodule CodeCorps.GitHub.SyncTest do
2122 User
2223 }
2324
25+ alias Ecto.Changeset
26+
2427 describe "installation_repositories_event/1 added" do
2528
2629 @ payload load_event_fixture ( "installation_repositories_added" )
@@ -51,7 +54,7 @@ defmodule CodeCorps.GitHub.SyncTest do
5154 end
5255
5356 test "can fail when installation not found" do
54- assert { :error , :unmatched_installation , % { } } == @ payload |> Sync . installation_repositories_event ( )
57+ assert { :error , :unmatched_installation } == @ payload |> Sync . installation_repositories_event ( )
5558 end
5659
5760 test "fails with validation errors when syncing repos" do
@@ -337,6 +340,72 @@ defmodule CodeCorps.GitHub.SyncTest do
337340
338341 assert existing_task . id == task . id
339342 end
343+
344+ test "can fail when finding repo" do
345+ assert { :error , :repo_not_found } == @ payload |> Sync . issue_event ( )
346+ end
347+
348+ test "can fail on github issue validation" do
349+ insert ( :github_repo , github_id: @ payload [ "repository" ] [ "id" ] )
350+ assert { :error , :validating_github_issue , % Changeset { } = changeset } =
351+ @ payload
352+ |> Kernel . put_in ( [ "issue" , "number" ] , nil )
353+ |> Sync . issue_event ( )
354+
355+ refute changeset . valid?
356+ end
357+
358+ test "can fail on github user validation" do
359+ insert ( :github_repo , github_id: @ payload [ "repository" ] [ "id" ] )
360+ assert { :error , :validating_github_user , % Changeset { } = changeset } =
361+ @ payload
362+ |> Kernel . put_in ( [ "issue" , "user" , "login" ] , nil )
363+ |> Sync . issue_event ( )
364+
365+ refute changeset . valid?
366+ end
367+
368+ test "can fail on user validation" do
369+ insert ( :github_repo , github_id: @ payload [ "repository" ] [ "id" ] )
370+
371+ # setup data to trigger a unique constraint
372+ 373+ insert ( :user , email: email )
374+ payload = @ payload |> Kernel . put_in ( [ "issue" , "user" , "email" ] , email )
375+
376+ assert { :error , :validating_user , % Changeset { } = changeset } =
377+ payload |> Sync . issue_event ( )
378+
379+ refute changeset . valid?
380+ end
381+
382+ test "can fail if matched by multiple users" do
383+ github_repo =
384+ insert ( :github_repo , github_id: @ payload [ "repository" ] [ "id" ] )
385+
386+ attrs =
387+ @ payload [ "issue" ]
388+ |> Adapters.Issue . to_issue ( )
389+ |> Map . put ( :github_repo , github_repo )
390+
391+ github_issue = insert ( :github_issue , attrs )
392+ # creates a user for each task, which should never happen normally
393+ insert_pair ( :task , github_issue: github_issue )
394+
395+ assert { :error , :multiple_issue_users_match } ==
396+ @ payload |> Sync . issue_event ( )
397+ end
398+
399+ test "can fail on task validation" do
400+ insert ( :github_repo , github_id: @ payload [ "repository" ] [ "id" ] )
401+
402+ # validation is triggered due to missing task list
403+
404+ assert { :error , :validating_task , % Changeset { } = changeset } =
405+ @ payload |> Sync . issue_event ( )
406+
407+ refute changeset . valid?
408+ end
340409 end
341410
342411 describe "sync_repo/1" do
0 commit comments