@@ -61,65 +61,65 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
61
61
62
62
@ tag user: @ unauthorized_user
63
63
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 )
65
65
end
66
66
67
67
test "handles bounty command without amount" do
68
- assert { :ok , [ ] } = process_bounty_command ( "/bounty" )
68
+ assert { :ok , [ ] } = process_commands ( "issue_comment.created" , "/bounty" )
69
69
end
70
70
71
71
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" )
73
73
assert bounty . amount == ~M[ 100] usd
74
74
end
75
75
76
76
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$" )
78
78
assert bounty . amount == ~M[ 100] usd
79
79
end
80
80
81
81
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" )
83
83
assert bounty . amount == ~M[ 100] usd
84
84
end
85
85
86
86
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" )
88
88
assert bounty . amount == ~M[ 100.50] usd
89
89
end
90
90
91
91
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" )
93
93
assert bounty . amount == ~M[ 100.5] usd
94
94
end
95
95
96
96
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" )
98
98
assert bounty . amount == ~M[ 100.50] usd
99
99
end
100
100
101
101
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" )
103
103
assert bounty . amount == ~M[ 100.5] usd
104
104
end
105
105
106
106
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$" )
108
108
assert bounty . amount == ~M[ 100.50] usd
109
109
end
110
110
111
111
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$" )
113
113
assert bounty . amount == ~M[ 100.5] usd
114
114
end
115
115
116
116
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" )
118
118
assert bounty . amount == ~M[ 1000] usd
119
119
end
120
120
121
121
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" )
123
123
assert bounty . amount == ~M[ 1000.50] usd
124
124
end
125
125
end
@@ -206,18 +206,21 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
206
206
)
207
207
end
208
208
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
211
210
body = """
212
211
Lorem
213
212
ipsum #{ command } dolor
214
213
sit
215
214
amet
216
215
"""
217
216
217
+ [ event , action ] = String . split ( event_action , "." )
218
+
218
219
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 )
221
224
)
222
225
end
223
226
end
0 commit comments