Skip to content

Commit 0b728a5

Browse files
committed
Add test helpers and full integration testing of GitHub.Sync
1 parent 9bb08b6 commit 0b728a5

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

test/lib/code_corps/github/sync/sync_test.exs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,21 @@ defmodule CodeCorps.GitHub.SyncTest do
104104
assert Repo.aggregate(Comment, :count, :id) == 0
105105
assert Repo.aggregate(Task, :count, :id) == 8
106106
end
107+
108+
@tag acceptance: true
109+
test "syncs issues with the repo with the real API" do
110+
github_repo = setup_real_repo()
111+
112+
with_real_api do
113+
Sync.sync_issues(github_repo)
114+
end
115+
116+
assert Repo.aggregate(GithubComment, :count, :id) == 0
117+
assert Repo.aggregate(GithubIssue, :count, :id) == 1
118+
assert Repo.aggregate(GithubPullRequest, :count, :id) == 0
119+
assert Repo.aggregate(Comment, :count, :id) == 0
120+
assert Repo.aggregate(Task, :count, :id) == 1
121+
assert Repo.aggregate(User, :count, :id) == 1
122+
end
107123
end
108124
end

test/support/github/test_helpers.ex

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
defmodule CodeCorps.GitHub.TestHelpers do
2+
import CodeCorps.Factories
3+
24
@spec load_endpoint_fixture(String.t) :: map
35
def load_endpoint_fixture(id) do
46
"./test/fixtures/github/endpoints/#{id}.json" |> File.read! |> Poison.decode!
@@ -9,6 +11,61 @@ defmodule CodeCorps.GitHub.TestHelpers do
911
"./test/fixtures/github/events/#{id}.json" |> File.read! |> Poison.decode!
1012
end
1113

14+
@spec setup_real_repo :: %CodeCorps.GithubRepo{}
15+
def setup_real_repo do
16+
# Data is from the real repository
17+
#
18+
# Uses:
19+
#
20+
# - the real repository owner
21+
# - the real repository name
22+
# - the real GitHub user id of the repository owner
23+
# - the real GitHub App id
24+
repo_owner = "coderly"
25+
repo_name = "github-app-testing"
26+
repo_owner_id = 321667
27+
app_github_id = 63365
28+
29+
# Create the user
30+
#
31+
# Simulates:
32+
#
33+
# - user (the repo owner) connecting their account with GitHub
34+
user = insert(:user, github_id: repo_owner_id)
35+
36+
# Create the organization and project for that organization
37+
#
38+
# Simulates:
39+
#
40+
# - user creating an organization
41+
# - organization creating a project
42+
# - project being bootstrapped with an inbox task list to receive new tasks
43+
organization = insert(:organization, owner: user)
44+
project = insert(:project, organization: organization)
45+
insert(:task_list, project: project, inbox: true)
46+
47+
# Create the GitHub App installation on the organization
48+
#
49+
# Simulates:
50+
#
51+
# - installation webhook
52+
# - user installing the organization
53+
github_app_installation = insert(:github_app_installation, github_account_login: repo_owner, github_id: app_github_id, project: project, user: user)
54+
insert(:organization_github_app_installation, github_app_installation: github_app_installation, organization: organization)
55+
56+
# Create the repo on the installation
57+
#
58+
# Simulates:
59+
#
60+
# - installation or installation_repositories webhook
61+
# - user connecting the repository to the project
62+
github_repo = insert(:github_repo, github_app_installation: github_app_installation, name: repo_name)
63+
insert(:project_github_repo, github_repo: github_repo, project: project)
64+
65+
# Return the %CodeCorps.GithubRepo{} record
66+
github_repo
67+
end
68+
1269
@doc ~S"""
1370
Allows setting a mock Github API module for usage in specific tests
1471
To use it, define a module containing the methods expected to be called, then

0 commit comments

Comments
 (0)