Resolve merge conflicts in payout system implementation
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -10,64 +10,49 @@ class PayoutServiceTest < ActiveSupport::TestCase
|
||||
Stripe.api_key = "test_key"
|
||||
end
|
||||
|
||||
test "process! success creates transfer and updates status" do
|
||||
# Mock Stripe Transfer
|
||||
Stripe::Transfer.expects(:create).with(
|
||||
amount: 90, # cents to euros
|
||||
currency: "eur",
|
||||
destination: @user.stripe_connected_account_id,
|
||||
description: "Payout for event #{@event.name}"
|
||||
).returns(stub(id: "tr_123", status: "succeeded"))
|
||||
|
||||
test "process! throws error for manual workflow" do
|
||||
@payout.update(status: :pending)
|
||||
|
||||
service = PayoutService.new(@payout)
|
||||
service.process!
|
||||
|
||||
@payout.reload
|
||||
assert_equal :completed, @payout.status
|
||||
assert_equal "tr_123", @payout.stripe_payout_id
|
||||
assert @payout.earnings.update_all(status: :paid) # assume update_earnings_status
|
||||
end
|
||||
|
||||
test "process! failure with Stripe error sets status to failed" do
|
||||
Stripe::Transfer.expects(:create).raises(Stripe::CardError.new("Insufficient funds"))
|
||||
|
||||
@payout.update(status: :pending)
|
||||
|
||||
service = PayoutService.new(@payout)
|
||||
assert_raises Stripe::CardError do
|
||||
error = assert_raises(RuntimeError) do
|
||||
service.process!
|
||||
end
|
||||
|
||||
@payout.reload
|
||||
assert_equal :failed, @payout.status
|
||||
assert_not_nil @payout.error_message # assume logged
|
||||
assert_includes error.message, "Automatic payout processing is disabled"
|
||||
end
|
||||
|
||||
test "process! idempotent for already completed" do
|
||||
@payout.update(status: :completed, stripe_payout_id: "tr_456")
|
||||
|
||||
Stripe::Transfer.expects(:create).never
|
||||
test "generate_transfer_summary returns payout details" do
|
||||
@user.update!(iban: "FR1420041010050500013M02606", bank_name: "Test Bank", account_holder_name: "John Doe")
|
||||
@payout.update(status: :approved)
|
||||
|
||||
service = PayoutService.new(@payout)
|
||||
service.process!
|
||||
summary = service.generate_transfer_summary
|
||||
|
||||
@payout.reload
|
||||
assert_equal :completed, @payout.status
|
||||
assert_not_nil summary
|
||||
assert_equal @payout.id, summary[:payout_id]
|
||||
assert_equal @user.name, summary[:recipient]
|
||||
assert_equal @user.account_holder_name, summary[:account_holder]
|
||||
assert_equal @user.bank_name, summary[:bank_name]
|
||||
assert_equal @user.iban, summary[:iban]
|
||||
end
|
||||
|
||||
test "update_earnings_status marks earnings as paid" do
|
||||
earning1 = Earning.create!(event: @event, user: @user, order: orders(:one), amount_cents: 4500, fee_cents: 500, status: :pending)
|
||||
earning2 = Earning.create!(event: @event, user: @user, order: orders(:two), amount_cents: 4500, fee_cents: 500, status: :pending)
|
||||
@payout.earnings << earning1
|
||||
@payout.earnings << earning2
|
||||
test "validate_banking_info returns errors for missing data" do
|
||||
service = PayoutService.new(@payout)
|
||||
errors = service.validate_banking_info
|
||||
|
||||
assert_includes errors, "Missing IBAN"
|
||||
assert_includes errors, "Missing bank name"
|
||||
assert_includes errors, "Missing account holder name"
|
||||
end
|
||||
|
||||
test "validate_banking_info returns no errors for complete data" do
|
||||
@user.update!(iban: "FR1420041010050500013M02606", bank_name: "Test Bank", account_holder_name: "John Doe")
|
||||
|
||||
service = PayoutService.new(@payout)
|
||||
service.update_earnings_status(:paid)
|
||||
errors = service.validate_banking_info
|
||||
|
||||
assert_equal :paid, earning1.reload.status
|
||||
assert_equal :paid, earning2.reload.status
|
||||
assert_empty errors
|
||||
end
|
||||
|
||||
test "process! handles manual processing when user has no stripe account" do
|
||||
|
||||
Reference in New Issue
Block a user