Skip to content

Commit 218b583

Browse files
committed
add event_action param to GithubController tests
1 parent 85a04a1 commit 218b583

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

test/algora_web/controllers/webhooks/github_controller_test.exs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,65 +61,65 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
6161

6262
@tag user: @unauthorized_user
6363
test "handles bounty command with unauthorized user", %{user: user} do
64-
assert {:error, :unauthorized} = process_bounty_command("/bounty $100", user)
64+
assert {:error, :unauthorized} = process_commands("issue_comment.created", "/bounty $100", user)
6565
end
6666

6767
test "handles bounty command without amount" do
68-
assert {:ok, []} = process_bounty_command("/bounty")
68+
assert {:ok, []} = process_commands("issue_comment.created", "/bounty")
6969
end
7070

7171
test "handles valid bounty command with $ prefix" do
72-
assert {:ok, [bounty]} = process_bounty_command("/bounty $100")
72+
assert {:ok, [bounty]} = process_commands("issue_comment.created", "/bounty $100")
7373
assert bounty.amount == ~M[100]usd
7474
end
7575

7676
test "handles invalid bounty command with $ suffix" do
77-
assert {:ok, [bounty]} = process_bounty_command("/bounty 100$")
77+
assert {:ok, [bounty]} = process_commands("issue_comment.created", "/bounty 100$")
7878
assert bounty.amount == ~M[100]usd
7979
end
8080

8181
test "handles bounty command without $ symbol" do
82-
assert {:ok, [bounty]} = process_bounty_command("/bounty 100")
82+
assert {:ok, [bounty]} = process_commands("issue_comment.created", "/bounty 100")
8383
assert bounty.amount == ~M[100]usd
8484
end
8585

8686
test "handles bounty command with decimal amount" do
87-
assert {:ok, [bounty]} = process_bounty_command("/bounty 100.50")
87+
assert {:ok, [bounty]} = process_commands("issue_comment.created", "/bounty 100.50")
8888
assert bounty.amount == ~M[100.50]usd
8989
end
9090

9191
test "handles bounty command with partial decimal amount" do
92-
assert {:ok, [bounty]} = process_bounty_command("/bounty 100.5")
92+
assert {:ok, [bounty]} = process_commands("issue_comment.created", "/bounty 100.5")
9393
assert bounty.amount == ~M[100.5]usd
9494
end
9595

9696
test "handles bounty command with decimal amount and $ prefix" do
97-
assert {:ok, [bounty]} = process_bounty_command("/bounty $100.50")
97+
assert {:ok, [bounty]} = process_commands("issue_comment.created", "/bounty $100.50")
9898
assert bounty.amount == ~M[100.50]usd
9999
end
100100

101101
test "handles bounty command with partial decimal amount and $ prefix" do
102-
assert {:ok, [bounty]} = process_bounty_command("/bounty $100.5")
102+
assert {:ok, [bounty]} = process_commands("issue_comment.created", "/bounty $100.5")
103103
assert bounty.amount == ~M[100.5]usd
104104
end
105105

106106
test "handles bounty command with decimal amount and $ suffix" do
107-
assert {:ok, [bounty]} = process_bounty_command("/bounty 100.50$")
107+
assert {:ok, [bounty]} = process_commands("issue_comment.created", "/bounty 100.50$")
108108
assert bounty.amount == ~M[100.50]usd
109109
end
110110

111111
test "handles bounty command with partial decimal amount and $ suffix" do
112-
assert {:ok, [bounty]} = process_bounty_command("/bounty 100.5$")
112+
assert {:ok, [bounty]} = process_commands("issue_comment.created", "/bounty 100.5$")
113113
assert bounty.amount == ~M[100.5]usd
114114
end
115115

116116
test "handles bounty command with comma separator" do
117-
assert {:ok, [bounty]} = process_bounty_command("/bounty 1,000")
117+
assert {:ok, [bounty]} = process_commands("issue_comment.created", "/bounty 1,000")
118118
assert bounty.amount == ~M[1000]usd
119119
end
120120

121121
test "handles bounty command with comma separator and decimal amount" do
122-
assert {:ok, [bounty]} = process_bounty_command("/bounty 1,000.50")
122+
assert {:ok, [bounty]} = process_commands("issue_comment.created", "/bounty 1,000.50")
123123
assert bounty.amount == ~M[1000.50]usd
124124
end
125125
end
@@ -206,18 +206,21 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
206206
)
207207
end
208208

209-
# Helper function to process bounty commands
210-
defp process_bounty_command(command, author \\ @admin_user) do
209+
defp process_commands(event_action, command, author \\ @admin_user) do
211210
body = """
212211
Lorem
213212
ipsum #{command} dolor
214213
sit
215214
amet
216215
"""
217216

217+
[event, action] = String.split(event_action, ".")
218+
218219
GithubController.process_commands(
219-
@webhook,
220-
Map.put(@params, "comment", %{"user" => %{"login" => author}, "body" => body})
220+
Map.put(@webhook, :event, event),
221+
@params
222+
|> Map.put("comment", %{"user" => %{"login" => author}, "body" => body})
223+
|> Map.put("action", action)
221224
)
222225
end
223226
end

0 commit comments

Comments
 (0)