Skip to content
This repository has been archived by the owner on Apr 5, 2023. It is now read-only.

Commit

Permalink
Add missing tests for GitHub.Processor for PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
lleger committed Feb 18, 2019
1 parent bc8614e commit 68c3baf
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
70 changes: 70 additions & 0 deletions test/custodian/github/processor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,74 @@ defmodule Custodian.Github.ProcessorTest do
assert {:ok, bot} = Processor.installation(params)
assert_raise Ecto.NoResultsError, fn -> Bots.get_bot!(bot.id) end
end

test "labels pr when opened" do
Bots.create_bot(%{
repo_id: 1,
owner: "lleger",
name: "gh-api-test",
installation_id: 1
})

params = %{
"repository" => %{
"id" => 1
},
"pull_request" => %{
"number" => "open",
"state" => "open"
}
}

assert {:ok, bot} = Processor.pr(params)
assert_received {:add, ["needs-review"]}
end

test "labels pr when closed" do
Bots.create_bot(%{
repo_id: 1,
owner: "lleger",
name: "gh-api-test",
installation_id: 1
})

params = %{
"repository" => %{
"id" => 1
},
"pull_request" => %{
"number" => "close",
"state" => "closed"
}
}

assert {:ok, bot} = Processor.pr(params)
assert_received {:remove, "needs-review"}
assert_received {:remove, "in-progress"}
assert_received {:remove, "ready-to-merge"}
end

test "labels pr when reopened" do
Bots.create_bot(%{
repo_id: 1,
owner: "lleger",
name: "gh-api-test",
installation_id: 1
})

params = %{
"repository" => %{
"id" => 1
},
"pull_request" => %{
"number" => "reopen",
"state" => "closed"
}
}

assert {:ok, bot} = Processor.pr(params)
assert_received {:remove, "needs-review"}
assert_received {:remove, "in-progress"}
assert_received {:remove, "ready-to-merge"}
end
end
18 changes: 18 additions & 0 deletions test/support/mockcat/labels.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
defmodule Custodian.Github.Mockcat.Labels do
@behaviour Custodian.Github.Labels

def all({_, "open"}) do
send(self(), :list)

[]
end

def all({_, "close"}) do
send(self(), :list)

["needs-review", "in-progress", "ready-to-merge"]
end

def all({_, "reopen"}) do
send(self(), :list)

["needs-review", "in-progress", "ready-to-merge"]
end

def all(_) do
send(self(), :list)

Expand Down

0 comments on commit 68c3baf

Please sign in to comment.