@@ -7,6 +7,9 @@ defmodule Algora.BountiesTest do
7
7
8
8
alias Algora.Activities.Notifier
9
9
alias Algora.Activities.SendEmail
10
+ alias Algora.Bounties
11
+ alias Algora.Payments.Transaction
12
+ alias Bounties.Tip
10
13
11
14
describe "bounties" do
12
15
test "create" do
@@ -35,10 +38,10 @@ defmodule Algora.BountiesTest do
35
38
amount: amount
36
39
}
37
40
38
- assert { :ok , bounty } = Algora. Bounties. create_bounty ( bounty_params , [ ] )
41
+ assert { :ok , bounty } = Bounties . create_bounty ( bounty_params , [ ] )
39
42
40
43
assert { :ok , claims } =
41
- Algora. Bounties. claim_bounty (
44
+ Bounties . claim_bounty (
42
45
% {
43
46
user: recipient ,
44
47
coauthor_provider_logins: [ ] ,
@@ -53,7 +56,7 @@ defmodule Algora.BountiesTest do
53
56
claims = Repo . preload ( claims , :user )
54
57
55
58
assert { :ok , _bounty } =
56
- Algora. Bounties. reward_bounty (
59
+ Bounties . reward_bounty (
57
60
% {
58
61
owner: owner ,
59
62
amount: ~M[ 4000] usd ,
@@ -64,7 +67,7 @@ defmodule Algora.BountiesTest do
64
67
)
65
68
66
69
assert { :ok , _stripe_session_url } =
67
- Algora. Bounties. create_tip (
70
+ Bounties . create_tip (
68
71
% {
69
72
amount: amount ,
70
73
owner: owner ,
@@ -83,7 +86,7 @@ defmodule Algora.BountiesTest do
83
86
assert "tip_activities" == tip . assoc_name
84
87
assert tip . notify_users == [ recipient . id ]
85
88
assert activity = Algora.Activities . get_with_preloaded_assoc ( tip . assoc_name , tip . id )
86
- assert activity . assoc . __meta__ . schema == Algora.Bounties. Tip
89
+ assert activity . assoc . __meta__ . schema == Tip
87
90
assert activity . assoc . creator . id == creator . id
88
91
89
92
assert_enqueued ( worker: Notifier , args: % { "activity_id" => bounty . id } )
@@ -115,18 +118,99 @@ defmodule Algora.BountiesTest do
115
118
amount: amount
116
119
}
117
120
118
- Algora. Bounties. create_bounty ( bounty_params , [ ] )
121
+ Bounties . create_bounty ( bounty_params , [ ] )
119
122
end )
120
123
121
- assert Algora. Bounties. list_bounties (
124
+ assert Bounties . list_bounties (
122
125
owner_id: bounty . owner_id ,
123
126
tech_stack: [ "elixir" ] ,
124
127
status: :open
125
128
)
126
129
127
- # assert Algora.Bounties.fetch_stats(bounty.owner_id)
128
- # assert Algora.Bounties.fetch_stats()
129
- assert Algora.Bounties.PrizePool . list ( )
130
+ # assert Bounties.fetch_stats(bounty.owner_id)
131
+ # assert Bounties.fetch_stats()
132
+ assert Bounties.PrizePool . list ( )
133
+ end
134
+
135
+ test "successfully creates and pays invoice for bounty claim" do
136
+ creator = insert! ( :user )
137
+ owner = insert! ( :organization )
138
+ customer = insert! ( :customer , user: owner )
139
+ payment_method = insert! ( :payment_method , customer: customer )
140
+ recipient = insert! ( :user )
141
+ installation = insert! ( :installation , owner: creator , connected_user: owner )
142
+ _identity = insert! ( :identity , user: creator , provider_email: creator . email )
143
+ repo = insert! ( :repository , % { user: owner } )
144
+ ticket = insert! ( :ticket , % { repository: repo } )
145
+ amount = ~M[ 4000] usd
146
+
147
+ ticket_ref = % {
148
+ owner: owner . handle ,
149
+ repo: repo . name ,
150
+ number: ticket . number
151
+ }
152
+
153
+ assert { :ok , bounty } =
154
+ Bounties . create_bounty (
155
+ % {
156
+ ticket_ref: ticket_ref ,
157
+ owner: owner ,
158
+ creator: creator ,
159
+ amount: amount
160
+ } ,
161
+ installation_id: installation . id
162
+ )
163
+
164
+ assert { :ok , [ claim ] } =
165
+ Bounties . claim_bounty (
166
+ % {
167
+ user: recipient ,
168
+ coauthor_provider_logins: [ ] ,
169
+ target_ticket_ref: ticket_ref ,
170
+ source_ticket_ref: ticket_ref ,
171
+ status: :pending ,
172
+ type: :pull_request
173
+ } ,
174
+ installation_id: installation . id
175
+ )
176
+
177
+ claim = Repo . preload ( claim , :user )
178
+
179
+ assert { :ok , invoice } =
180
+ Bounties . create_invoice (
181
+ % { owner: owner , amount: amount } ,
182
+ ticket_ref: ticket_ref ,
183
+ bounty_id: bounty . id ,
184
+ claims: [ claim ]
185
+ )
186
+
187
+ assert { :ok , _invoice } =
188
+ Algora.Stripe.Invoice . pay ( invoice , % {
189
+ payment_method: payment_method . provider_id ,
190
+ off_session: true
191
+ } )
192
+
193
+ charge = Repo . one! ( from t in Transaction , where: t . type == :charge )
194
+ assert Money . equal? ( charge . net_amount , amount )
195
+ assert charge . status == :initialized
196
+ assert charge . user_id == owner . id
197
+
198
+ debit = Repo . one! ( from t in Transaction , where: t . type == :debit )
199
+ assert Money . equal? ( debit . net_amount , amount )
200
+ assert debit . status == :initialized
201
+ assert debit . user_id == owner . id
202
+ assert debit . bounty_id == bounty . id
203
+ assert debit . claim_id == claim . id
204
+
205
+ credit = Repo . one! ( from t in Transaction , where: t . type == :credit )
206
+ assert Money . equal? ( credit . net_amount , amount )
207
+ assert credit . status == :initialized
208
+ assert credit . user_id == recipient . id
209
+ assert credit . bounty_id == bounty . id
210
+ assert credit . claim_id == claim . id
211
+
212
+ transfer = Repo . one ( from t in Transaction , where: t . type == :transfer )
213
+ assert is_nil ( transfer )
130
214
end
131
215
end
132
216
end
0 commit comments