@@ -47,57 +47,66 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
47
47
48
48
@ tag user: @ unauthorized_user
49
49
test "handles bounty command with unauthorized user" , % { user: user } do
50
- assert process_bounty_command ( "/bounty $100" , user ) [ :ok ] == nil
51
- assert process_bounty_command ( "/bounty $100" , user ) [ :error ] == :unauthorized
50
+ assert { :error , :unauthorized } = process_bounty_command ( "/bounty $100" , user )
52
51
end
53
52
54
53
test "handles bounty command without amount" do
55
- assert process_bounty_command ( "/bounty" ) [ :ok ] == nil
56
- assert process_bounty_command ( "/bounty" ) [ :error ] == nil
54
+ assert { :ok , [ ] } = process_bounty_command ( "/bounty" )
57
55
end
58
56
59
57
test "handles valid bounty command with $ prefix" do
60
- assert process_bounty_command ( "/bounty $100" ) [ :ok ] . amount == ~M[ 100] usd
58
+ assert { :ok , [ bounty ] } = process_bounty_command ( "/bounty $100" )
59
+ assert bounty . amount == ~M[ 100] usd
61
60
end
62
61
63
62
test "handles invalid bounty command with $ suffix" do
64
- assert process_bounty_command ( "/bounty 100$" ) [ :ok ] . amount == ~M[ 100] usd
63
+ assert { :ok , [ bounty ] } = process_bounty_command ( "/bounty 100$" )
64
+ assert bounty . amount == ~M[ 100] usd
65
65
end
66
66
67
67
test "handles bounty command without $ symbol" do
68
- assert process_bounty_command ( "/bounty 100" ) [ :ok ] . amount == ~M[ 100] usd
68
+ assert { :ok , [ bounty ] } = process_bounty_command ( "/bounty 100" )
69
+ assert bounty . amount == ~M[ 100] usd
69
70
end
70
71
71
72
test "handles bounty command with decimal amount" do
72
- assert process_bounty_command ( "/bounty 100.50" ) [ :ok ] . amount == ~M[ 100.50] usd
73
+ assert { :ok , [ bounty ] } = process_bounty_command ( "/bounty 100.50" )
74
+ assert bounty . amount == ~M[ 100.50] usd
73
75
end
74
76
75
77
test "handles bounty command with partial decimal amount" do
76
- assert process_bounty_command ( "/bounty 100.5" ) [ :ok ] . amount == ~M[ 100.5] usd
78
+ assert { :ok , [ bounty ] } = process_bounty_command ( "/bounty 100.5" )
79
+ assert bounty . amount == ~M[ 100.5] usd
77
80
end
78
81
79
82
test "handles bounty command with decimal amount and $ prefix" do
80
- assert process_bounty_command ( "/bounty $100.50" ) [ :ok ] . amount == ~M[ 100.50] usd
83
+ assert { :ok , [ bounty ] } = process_bounty_command ( "/bounty $100.50" )
84
+ assert bounty . amount == ~M[ 100.50] usd
81
85
end
82
86
83
87
test "handles bounty command with partial decimal amount and $ prefix" do
84
- assert process_bounty_command ( "/bounty $100.5" ) [ :ok ] . amount == ~M[ 100.5] usd
88
+ assert { :ok , [ bounty ] } = process_bounty_command ( "/bounty $100.5" )
89
+ assert bounty . amount == ~M[ 100.5] usd
85
90
end
86
91
87
92
test "handles bounty command with decimal amount and $ suffix" do
88
- assert process_bounty_command ( "/bounty 100.50$" ) [ :ok ] . amount == ~M[ 100.50] usd
93
+ assert { :ok , [ bounty ] } = process_bounty_command ( "/bounty 100.50$" )
94
+ assert bounty . amount == ~M[ 100.50] usd
89
95
end
90
96
91
97
test "handles bounty command with partial decimal amount and $ suffix" do
92
- assert process_bounty_command ( "/bounty 100.5$" ) [ :ok ] . amount == ~M[ 100.5] usd
98
+ assert { :ok , [ bounty ] } = process_bounty_command ( "/bounty 100.5$" )
99
+ assert bounty . amount == ~M[ 100.5] usd
93
100
end
94
101
95
102
test "handles bounty command with comma separator" do
96
- assert process_bounty_command ( "/bounty 1,000" ) [ :ok ] . amount == ~M[ 1000] usd
103
+ assert { :ok , [ bounty ] } = process_bounty_command ( "/bounty 1,000" )
104
+ assert bounty . amount == ~M[ 1000] usd
97
105
end
98
106
99
107
test "handles bounty command with comma separator and decimal amount" do
100
- assert process_bounty_command ( "/bounty 1,000.50" ) [ :ok ] . amount == ~M[ 1000.50] usd
108
+ assert { :ok , [ bounty ] } = process_bounty_command ( "/bounty 1,000.50" )
109
+ assert bounty . amount == ~M[ 1000.50] usd
101
110
end
102
111
end
103
112
@@ -184,14 +193,17 @@ defmodule AlgoraWeb.Webhooks.GithubControllerTest do
184
193
end
185
194
186
195
# Helper function to process bounty commands
187
- defp process_bounty_command ( body , author \\ @ admin_user ) do
188
- full_body = """
196
+ defp process_bounty_command ( command , author \\ @ admin_user ) do
197
+ body = """
189
198
Lorem
190
- ipsum #{ body } dolor
199
+ ipsum #{ command } dolor
191
200
sit
192
201
amet
193
202
"""
194
203
195
- GithubController . process_commands ( full_body , % { "login" => author } , @ params )
204
+ GithubController . process_commands (
205
+ "issue_comment" ,
206
+ Map . put ( @ params , "comment" , % { "user" => % { "login" => author } , "body" => body } )
207
+ )
196
208
end
197
209
end
0 commit comments