Skip to content

Commit d2c4a76

Browse files
committed
update tests
1 parent 605b576 commit d2c4a76

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

lib/algora_web/controllers/webhooks/github_controller.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ defmodule AlgoraWeb.Webhooks.GithubController do
1313
# TODO: auto-retry failed deliveries with exponential backoff
1414

1515
def new(conn, params) do
16-
with {:ok, %Webhook{event: event}} <- Webhook.new(conn),
17-
{:ok, _} <- process_commands(event, params) do
16+
with {:ok, webhook} <- Webhook.new(conn),
17+
{:ok, _} <- process_commands(webhook, params) do
1818
conn |> put_status(:accepted) |> json(%{status: "ok"})
1919
else
2020
{:error, :missing_header} ->
@@ -149,10 +149,10 @@ defmodule AlgoraWeb.Webhooks.GithubController do
149149
end
150150

151151
defp execute_command(_event_action, _command, _author, _params) do
152-
{:error, :unhandled_command}
152+
{:ok, nil}
153153
end
154154

155-
def process_commands(event, params) do
155+
def process_commands(%Webhook{event: event, hook_id: hook_id}, params) do
156156
author = get_author(event, params)
157157
body = get_body(event, params)
158158

@@ -167,7 +167,7 @@ defmodule AlgoraWeb.Webhooks.GithubController do
167167

168168
error ->
169169
Logger.error(
170-
"Command execution failed for #{event_action}(#{event["id"]}): #{inspect(command)}: #{inspect(error)}"
170+
"Command execution failed for #{event_action}(#{hook_id}): #{inspect(command)}: #{inspect(error)}"
171171
)
172172

173173
{:halt, error}

test/algora_web/controllers/webhooks/github_controller_test.exs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
55
import Money.Sigil
66
import Mox
77

8+
alias Algora.Github.Webhook
89
alias AlgoraWeb.Webhooks.GithubController
910

1011
setup :verify_on_exit!
@@ -15,7 +16,20 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
1516
@repo_name "repo"
1617
@installation_id 123
1718

19+
@webhook %Webhook{
20+
event: "issue_comment",
21+
hook_id: "123456789",
22+
delivery: "00000000-0000-0000-0000-000000000000",
23+
signature: "sha1=0000000000000000000000000000000000000000",
24+
signature_256: "sha256=0000000000000000000000000000000000000000000000000000000000000000",
25+
user_agent: "GitHub-Hookshot/0000000",
26+
installation_type: "integration",
27+
installation_id: "123456"
28+
}
29+
1830
@params %{
31+
"id" => 123,
32+
"action" => "created",
1933
"repository" => %{
2034
"owner" => %{"login" => @repo_owner},
2135
"name" => @repo_name
@@ -202,7 +216,7 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
202216
"""
203217

204218
GithubController.process_commands(
205-
"issue_comment",
219+
@webhook,
206220
Map.put(@params, "comment", %{"user" => %{"login" => author}, "body" => body})
207221
)
208222
end

0 commit comments

Comments
 (0)