From 68c3baf3bf766a42e4ed5ad60bfb3daad1fa540a Mon Sep 17 00:00:00 2001 From: Logan Leger Date: Mon, 18 Feb 2019 14:43:58 -0600 Subject: [PATCH] Add missing tests for GitHub.Processor for PRs --- test/custodian/github/processor_test.exs | 70 ++++++++++++++++++++++++ test/support/mockcat/labels.ex | 18 ++++++ 2 files changed, 88 insertions(+) diff --git a/test/custodian/github/processor_test.exs b/test/custodian/github/processor_test.exs index 2a2a1df..634d0be 100644 --- a/test/custodian/github/processor_test.exs +++ b/test/custodian/github/processor_test.exs @@ -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 diff --git a/test/support/mockcat/labels.ex b/test/support/mockcat/labels.ex index 063d6db..efe2f57 100644 --- a/test/support/mockcat/labels.ex +++ b/test/support/mockcat/labels.ex @@ -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)