@@ -7,145 +7,134 @@ defmodule Algora.Github.CommandTest do
7
7
8
8
describe "parse/1 with bounty command" do
9
9
test "parses simple bounty amount" do
10
- assert { :ok , % { bounty: [ { :amount , ~M[ 1000] usd } ] } } ==
10
+ assert { :ok , [ bounty: [ { :amount , ~M[ 1000] usd } ] ] } ==
11
11
Command . parse ( "/bounty 1000" )
12
12
end
13
13
14
14
test "parses bounty with EN thousand separators and decimal points" do
15
- assert { :ok , % { bounty: [ { :amount , ~M[ 1000.5] usd } ] } } ==
15
+ assert { :ok , [ bounty: [ { :amount , ~M[ 1000.5] usd } ] ] } ==
16
16
Command . parse ( "/bounty 1,000.5" )
17
17
end
18
18
19
19
test "parses bounty with EN thousand separators" do
20
- assert { :ok , % { bounty: [ { :amount , ~M[ 1_000_000] usd } ] } } ==
20
+ assert { :ok , [ bounty: [ { :amount , ~M[ 1_000_000] usd } ] ] } ==
21
21
Command . parse ( "/bounty 1,000,000" )
22
22
end
23
23
24
24
test "parses bounty with EN decimal points" do
25
- assert { :ok , % { bounty: [ { :amount , ~M[ 1000.50] usd } ] } } ==
25
+ assert { :ok , [ bounty: [ { :amount , ~M[ 1000.50] usd } ] ] } ==
26
26
Command . parse ( "/bounty 1000.50" )
27
27
end
28
28
29
29
test "parses bounty with DE thousand separators and decimal points" do
30
- assert { :ok , % { bounty: [ { :amount , ~M[ 1000.5] usd } ] } } ==
30
+ assert { :ok , [ bounty: [ { :amount , ~M[ 1000.5] usd } ] ] } ==
31
31
Command . parse ( "/bounty 1.000,5" )
32
32
end
33
33
34
34
test "parses bounty with DE thousand separators" do
35
- assert { :ok , % { bounty: [ { :amount , ~M[ 1_000_000] usd } ] } } ==
35
+ assert { :ok , [ bounty: [ { :amount , ~M[ 1_000_000] usd } ] ] } ==
36
36
Command . parse ( "/bounty 1.000.000" )
37
37
end
38
38
39
39
test "parses bounty with DE decimal points" do
40
- assert { :ok , % { bounty: [ { :amount , ~M[ 1000.50] usd } ] } } ==
40
+ assert { :ok , [ bounty: [ { :amount , ~M[ 1000.50] usd } ] ] } ==
41
41
Command . parse ( "/bounty 1000,50" )
42
42
end
43
43
44
44
test "parses bounty with dollar sign" do
45
- assert { :ok , % { bounty: [ { :amount , ~M[ 50] usd } ] } } ==
45
+ assert { :ok , [ bounty: [ { :amount , ~M[ 50] usd } ] ] } ==
46
46
Command . parse ( "/bounty $50" )
47
47
end
48
48
end
49
49
50
50
describe "parse/1 with tip command" do
51
51
test "parses tip with amount first" do
52
- assert { :ok , % { tip: [ { :amount , ~M[ 100] usd } , { :recipient , "user" } ] } } ==
52
+ assert { :ok , [ tip: [ { :amount , ~M[ 100] usd } , { :recipient , "user" } ] ] } ==
53
53
Command . parse ( "/tip 100 @user" )
54
54
end
55
55
56
56
test "parses tip with recipient first" do
57
- assert { :ok , % { tip: [ { :recipient , "user" } , { :amount , ~M[ 100] usd } ] } } ==
57
+ assert { :ok , [ tip: [ { :recipient , "user" } , { :amount , ~M[ 100] usd } ] ] } ==
58
58
Command . parse ( "/tip @user 100" )
59
59
end
60
60
61
61
test "parses tip with only amount" do
62
- assert { :ok , % { tip: [ { :amount , ~M[ 100] usd } ] } } ==
62
+ assert { :ok , [ tip: [ { :amount , ~M[ 100] usd } ] ] } ==
63
63
Command . parse ( "/tip 100" )
64
64
end
65
65
66
66
test "parses tip with only recipient" do
67
- assert { :ok , % { tip: [ { :recipient , "user" } ] } } ==
67
+ assert { :ok , [ tip: [ { :recipient , "user" } ] ] } ==
68
68
Command . parse ( "/tip @user" )
69
69
end
70
70
end
71
71
72
72
describe "parse/1 with claim command" do
73
73
test "parses simple issue number" do
74
- assert { :ok , % { claim: [ { :ticket_ref , [ number: 123 ] } ] } } ==
74
+ assert { :ok , [ claim: [ { :ticket_ref , [ number: 123 ] } ] ] } ==
75
75
Command . parse ( "/claim 123" )
76
76
end
77
77
78
78
test "parses issue with hash" do
79
- assert { :ok , % { claim: [ { :ticket_ref , [ number: 123 ] } ] } } ==
79
+ assert { :ok , [ claim: [ { :ticket_ref , [ number: 123 ] } ] ] } ==
80
80
Command . parse ( "/claim #123" )
81
81
end
82
82
83
83
test "parses repo issue reference" do
84
- assert { :ok , % { claim: [ { :ticket_ref , [ repo: "repo" , number: 123 ] } ] } } ==
84
+ assert { :ok , [ claim: [ { :ticket_ref , [ repo: "repo" , number: 123 ] } ] ] } ==
85
85
Command . parse ( "/claim repo#123" )
86
86
end
87
87
88
88
test "parses full repo path" do
89
- assert { :ok , % { claim: [ { :ticket_ref , [ owner: "owner" , repo: "repo" , number: 123 ] } ] } } ==
89
+ assert { :ok , [ claim: [ { :ticket_ref , [ owner: "owner" , repo: "repo" , number: 123 ] } ] ] } ==
90
90
Command . parse ( "/claim owner/repo#123" )
91
91
end
92
92
93
93
test "parses full GitHub URL for issues" do
94
94
expected =
95
- { :ok ,
96
- % {
97
- claim: [ { :ticket_ref , [ owner: "owner" , repo: "repo" , type: "issues" , number: 123 ] } ]
98
- } }
95
+ { :ok , [ claim: [ { :ticket_ref , [ owner: "owner" , repo: "repo" , type: "issues" , number: 123 ] } ] ] }
99
96
100
97
assert expected == Command . parse ( "/claim github.com/owner/repo/issues/123" )
101
98
assert expected == Command . parse ( "/claim http://github.com/owner/repo/issues/123" )
102
99
assert expected == Command . parse ( "/claim https://github.com/owner/repo/issues/123" )
103
100
end
104
101
105
102
test "parses full GitHub URL for pull requests" do
106
- assert { :ok ,
107
- % {
108
- claim: [ { :ticket_ref , [ owner: "owner" , repo: "repo" , type: "pull" , number: 123 ] } ]
109
- } } ==
103
+ assert { :ok , [ claim: [ { :ticket_ref , [ owner: "owner" , repo: "repo" , type: "pull" , number: 123 ] } ] ] } ==
110
104
Command . parse ( "/claim https://github.com/owner/repo/pull/123" )
111
105
end
112
106
113
107
test "parses full GitHub URL for discussions" do
114
- assert { :ok ,
115
- % {
116
- claim: [
117
- { :ticket_ref , [ owner: "owner" , repo: "repo" , type: "discussions" , number: 123 ] }
118
- ]
119
- } } ==
108
+ assert { :ok , [ claim: [ { :ticket_ref , [ owner: "owner" , repo: "repo" , type: "discussions" , number: 123 ] } ] ] } ==
120
109
Command . parse ( "/claim https://github.com/owner/repo/discussions/123" )
121
110
end
122
111
end
123
112
124
113
describe "parse/1 with multiple commands" do
125
114
test "parses multiple commands in sequence" do
126
115
assert { :ok ,
127
- % {
116
+ [
128
117
bounty: [ { :amount , Money . new! ( 100 , :USD ) } ] ,
129
118
tip: [ { :amount , Money . new! ( 50 , :USD ) } , { :recipient , "user" } ]
130
- } } == Command . parse ( "/bounty 100 /tip 50 @user" )
119
+ ] } == Command . parse ( "/bounty 100 /tip 50 @user" )
131
120
end
132
121
133
122
test "handles text between commands" do
134
123
assert { :ok ,
135
- % {
124
+ [
136
125
bounty: [ { :amount , Money . new! ( 100 , :USD ) } ] ,
137
126
tip: [ { :recipient , "user" } , { :amount , Money . new! ( 50 , :USD ) } ]
138
- } } == Command . parse ( "Hello /bounty 100 world /tip @user 50" )
127
+ ] } == Command . parse ( "Hello /bounty 100 world /tip @user 50" )
139
128
end
140
129
end
141
130
142
131
describe "parse/1 with invalid input" do
143
132
test "returns empty list for invalid commands" do
144
- assert { :ok , % { } } == Command . parse ( "/invalid" )
133
+ assert { :ok , [ ] } == Command . parse ( "/invalid" )
145
134
end
146
135
147
136
test "returns empty list for no commands" do
148
- assert { :ok , % { } } == Command . parse ( "just some text" )
137
+ assert { :ok , [ ] } == Command . parse ( "just some text" )
149
138
end
150
139
151
140
test "returns error for malformed amounts" do
0 commit comments