Skip to content

Commit

Permalink
Add github repo policy test
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Nov 15, 2017
1 parent f4b4d63 commit cbe14e3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/code_corps/github/sync/comment/comment/comment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ defmodule CodeCorps.GitHub.Sync.Comment.Comment do
GithubIssue,
GithubRepo,
GithubUser,
Project,
Repo,
Task,
User
Expand Down
34 changes: 34 additions & 0 deletions test/lib/code_corps/policy/github_repo_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
defmodule CodeCorps.Policy.GithubRepoTest do
use CodeCorps.PolicyCase

import CodeCorps.Policy.GithubRepo, only: [update?: 3]

alias CodeCorps.GithubRepo

describe "update?/3" do
test "returns true when user is adding project where they're an admin" do
project = insert(:project)
user = insert(:user)
insert(:project_user, project: project, user: user, role: "admin")
github_repo = %GithubRepo{project_id: project.id}

assert update?(user, github_repo, %{})
end

test "returns true when user is removing project where they're an admin" do
project = insert(:project)
user = insert(:user)
insert(:project_user, project: project, user: user, role: "admin")

assert update?(user, %GithubRepo{}, %{"project_id" => project.id})
end

test "returns false for normal user" do
project = insert(:project)
user = insert(:user)
github_repo = %GithubRepo{project_id: project.id}

refute update?(user, github_repo, %{})
end
end
end

0 comments on commit cbe14e3

Please sign in to comment.