-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set modified_from to "code_corps" on tasks and comments when updating from codecorps #1163
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,44 +3,59 @@ defmodule CodeCorps.GitHub.Sync.Issue.TaskTest do | |
|
||
use CodeCorps.DbAccessCase | ||
|
||
alias CodeCorps.{ | ||
Project, | ||
Repo, | ||
Task | ||
} | ||
alias CodeCorps.{Repo, Task} | ||
alias CodeCorps.GitHub.Sync.Issue.Task, as: IssueTaskSyncer | ||
|
||
describe "sync all/3" do | ||
test "creates missing, updates existing tasks for each project associated with the github repo" do | ||
defp setup_test_data do | ||
# Creates a user, 3 projects and a github issue all linked to a | ||
# github repo. Returns that data as a map | ||
user = insert(:user) | ||
projects = insert_list(3, :project) | ||
github_repo = insert(:github_repo) | ||
github_issue = insert( | ||
:github_issue, | ||
github_repo: github_repo, | ||
github_updated_at: DateTime.utc_now |> Timex.shift(hours: 1) | ||
) | ||
|
||
%{github_repo: github_repo} = github_issue = | ||
insert(:github_issue, github_updated_at: DateTime.utc_now |> Timex.shift(hours: 1)) | ||
projects |> Enum.each(&insert(:task_list, project: &1, inbox: true)) | ||
|
||
[%{project: project_1}, _, _] = project_github_repos = | ||
insert_list(3, :project_github_repo, github_repo: github_repo) | ||
projects | ||
|> Enum.each(&insert(:project_github_repo, project: &1, github_repo: github_repo)) | ||
|
||
task_1 = insert(:task, project: project_1, github_issue: github_issue, github_repo: github_repo, user: user) | ||
%{github_issue: github_issue, github_repo: github_repo, projects: projects, user: user} | ||
end | ||
|
||
project_ids = project_github_repos |> Enum.map(&Map.get(&1, :project_id)) | ||
test "creates missing, updates existing tasks for each project associated with the github repo" do | ||
%{ | ||
github_issue: github_issue, | ||
github_repo: github_repo, | ||
projects: [project_1 | _] = projects, | ||
user: user | ||
} = setup_test_data() | ||
|
||
project_ids |> Enum.each(fn project_id -> | ||
project = Project |> Repo.get_by(id: project_id) | ||
insert(:task_list, project: project, inbox: true) | ||
end) | ||
existing_task = | ||
insert(:task, project: project_1, github_issue: github_issue, github_repo: github_repo, user: user) | ||
|
||
{:ok, tasks} = github_issue |> IssueTaskSyncer.sync_all(user) | ||
|
||
assert Repo.aggregate(Task, :count, :id) == 3 | ||
assert Repo.aggregate(Task, :count, :id) == projects |> Enum.count | ||
assert tasks |> Enum.count == projects |> Enum.count | ||
|
||
tasks |> Enum.each(fn task -> | ||
assert task.user_id == user.id | ||
assert task.markdown == github_issue.body | ||
assert task.github_issue_id == github_issue.id | ||
end) | ||
|
||
task_ids = tasks |> Enum.map(&Map.get(&1, :id)) | ||
assert task_1.id in task_ids | ||
assert existing_task.id in (tasks |> Enum.map(&Map.get(&1, :id))) | ||
end | ||
|
||
test "sets task :modified_from to 'github'" do | ||
%{github_issue: github_issue, user: user} = setup_test_data() | ||
{:ok, tasks} = github_issue |> IssueTaskSyncer.sync_all(user) | ||
assert tasks |> Enum.all?(fn task -> task.modified_from == "github" end) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the same reason as the service test above, this is a sort of an integration test, even though our sync changeset already has the needed assertions in its own tests. I did not do the same for comments because of the complexity of the test data there. I'm hoping I'll get a chance to decouple the comment syncer from payloads first. |
||
end | ||
|
||
test "fails on validation errors" do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A changeset test might seem enough, but I wanted to add a sort of "integration" test to. The service is where the modification gets commited to the db.