11defmodule 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