Skip to content

Commit 35b302b

Browse files
committed
Add more sync tests and some docs
1 parent 2296fa5 commit 35b302b

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

lib/code_corps/github/sync/comment/comment/changeset.ex

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ defmodule CodeCorps.GitHub.Sync.Comment.Comment.Changeset do
77
alias CodeCorps.{
88
Comment,
99
GithubComment,
10-
ProjectGithubRepo,
1110
Services.MarkdownRendererService,
1211
Task,
1312
User,
@@ -17,8 +16,7 @@ defmodule CodeCorps.GitHub.Sync.Comment.Comment.Changeset do
1716
alias Ecto.Changeset
1817

1918
@doc ~S"""
20-
Constructs a changeset for syncing a task when processing a GitHub Comment
21-
payload
19+
Constructs a changeset for syncing a task from a GitHub API Comment payload.
2220
"""
2321
@spec build_changeset(Comment.t, map, GithubComment.t, Task.t, User.t) :: Changeset.t
2422
def build_changeset(
@@ -34,6 +32,9 @@ defmodule CodeCorps.GitHub.Sync.Comment.Comment.Changeset do
3432
comment |> update_changeset(attrs)
3533
end
3634

35+
@doc ~S"""
36+
Constructs a changeset for syncing a task from a `GithubComment` record.
37+
"""
3738
@spec build_changeset(Comment.t, GithubComment.t, Task.t, User.t) :: Changeset.t
3839
def build_changeset(
3940
%Comment{id: comment_id} = comment,

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

+21-1
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,34 @@ defmodule CodeCorps.GitHub.SyncTest do
9090
end
9191

9292
describe "sync_project_github_repo/1" do
93-
test "syncs with the project repo" do
93+
test "syncs and resyncs with the project repo" do
9494
owner = "baxterthehacker"
9595
repo = "public-repo"
9696
github_app_installation = insert(:github_app_installation, github_account_login: owner)
9797
github_repo = insert(:github_repo, github_app_installation: github_app_installation, name: repo, github_account_id: 6752317, github_account_avatar_url: "https://avatars3.githubusercontent.com/u/6752317?v=4", github_account_type: "User", github_id: 35129377)
9898
%{project: project} = project_github_repo = insert(:project_github_repo, github_repo: github_repo)
9999
insert(:task_list, project: project, inbox: true)
100100

101+
# Sync a first time
102+
103+
Sync.sync_project_github_repo(project_github_repo)
104+
105+
repo = Repo.one(GithubRepo)
106+
107+
assert repo.syncing_pull_requests_count == 4
108+
assert repo.syncing_issues_count == 8
109+
assert repo.syncing_comments_count == 12
110+
111+
assert Repo.aggregate(GithubComment, :count, :id) == 12
112+
assert Repo.aggregate(GithubIssue, :count, :id) == 8
113+
assert Repo.aggregate(GithubPullRequest, :count, :id) == 4
114+
assert Repo.aggregate(GithubUser, :count, :id) == 10
115+
assert Repo.aggregate(Comment, :count, :id) == 12
116+
assert Repo.aggregate(Task, :count, :id) == 8
117+
assert Repo.aggregate(User, :count, :id) == 13
118+
119+
# Sync a second time – should run without trouble
120+
101121
Sync.sync_project_github_repo(project_github_repo)
102122

103123
repo = Repo.one(GithubRepo)

0 commit comments

Comments
 (0)