fix: remove legacy admin payout process route and reorganize routes
- Remove legacy 'process' route from admin payouts (conflicted with Ruby's process method) - Reorganize admin routes to logical position with proper section comment - Simplify admin payout routes to only include actual functionality - Update admin controller tests to test approval workflow instead of legacy routes - Add proper test setup with banking info and onboarding completion - Improve test coverage for admin authentication and payout approval This resolves admin controller test failures and removes unnecessary legacy code since the application is not yet published. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -60,12 +60,6 @@ class Admin::PayoutsController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Legacy method - redirect to new workflow
|
|
||||||
def process
|
|
||||||
@payout = Payout.find(params[:id])
|
|
||||||
redirect_to admin_payout_path(@payout), alert: "Use the new manual payout workflow."
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_payout
|
def set_payout
|
||||||
|
|||||||
@@ -1,16 +1,4 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
namespace :admin do
|
|
||||||
resources :payouts, only: [ :index, :show ] do
|
|
||||||
member do
|
|
||||||
post :process # Legacy route
|
|
||||||
post :approve
|
|
||||||
post :reject
|
|
||||||
post :mark_processing
|
|
||||||
post :mark_completed
|
|
||||||
post :mark_failed
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
||||||
|
|
||||||
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
|
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
|
||||||
@@ -107,6 +95,19 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# === Administration ===
|
||||||
|
namespace :admin do
|
||||||
|
resources :payouts, only: [ :index, :show ] do
|
||||||
|
member do
|
||||||
|
post :approve
|
||||||
|
post :reject
|
||||||
|
post :mark_processing
|
||||||
|
post :mark_completed
|
||||||
|
post :mark_failed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# API routes versioning
|
# API routes versioning
|
||||||
namespace :api do
|
namespace :api do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
|
|||||||
@@ -2,46 +2,28 @@ require "test_helper"
|
|||||||
|
|
||||||
class Admin::PayoutsControllerTest < ActionDispatch::IntegrationTest
|
class Admin::PayoutsControllerTest < ActionDispatch::IntegrationTest
|
||||||
setup do
|
setup do
|
||||||
@admin_user = User.create!(email: "admin@example.com", password: "password123", password_confirmation: "password123", is_professionnal: true, stripe_customer_id: "cus_test_admin")
|
@admin_user = User.create!(email: "admin@example.com", password: "password123", password_confirmation: "password123", is_professionnal: true, stripe_customer_id: "cus_test_admin", onboarding_completed: true)
|
||||||
@payout = payouts(:one)
|
@payout = payouts(:one)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "process payout success for pending payout" do
|
test "approve payout requires admin authentication" do
|
||||||
sign_in @admin_user
|
post approve_admin_payout_url(@payout)
|
||||||
@payout.update(status: :pending)
|
|
||||||
|
|
||||||
# Mock service
|
|
||||||
PayoutService.any_instance.expects(:process!).returns(true)
|
|
||||||
|
|
||||||
patch admin_payout_url(@payout)
|
|
||||||
assert_redirected_to admin_payout_path(@payout)
|
|
||||||
assert_flash :notice, /Payout processed successfully/
|
|
||||||
assert_equal :completed, @payout.reload.status
|
|
||||||
end
|
|
||||||
|
|
||||||
test "process payout failure for non-pending" do
|
|
||||||
sign_in @admin_user
|
|
||||||
@payout.update(status: :completed)
|
|
||||||
|
|
||||||
patch admin_payout_url(@payout)
|
|
||||||
assert_redirected_to admin_payout_path(@payout)
|
|
||||||
assert_flash :alert, /Payout not in pending status/
|
|
||||||
end
|
|
||||||
|
|
||||||
test "process payout service error" do
|
|
||||||
sign_in @admin_user
|
|
||||||
@payout.update(status: :pending)
|
|
||||||
|
|
||||||
PayoutService.any_instance.expects(:process!).raises(StandardError.new("Stripe error"))
|
|
||||||
|
|
||||||
patch admin_payout_url(@payout)
|
|
||||||
assert_redirected_to admin_payout_path(@payout)
|
|
||||||
assert_flash :alert, /Failed to process payout/
|
|
||||||
assert_equal :failed, @payout.reload.status
|
|
||||||
end
|
|
||||||
|
|
||||||
test "requires admin authentication" do
|
|
||||||
patch admin_payout_url(@payout)
|
|
||||||
assert_redirected_to new_user_session_path
|
assert_redirected_to new_user_session_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "approve payout works for admin users" do
|
||||||
|
sign_in @admin_user
|
||||||
|
@payout.update(status: :pending)
|
||||||
|
|
||||||
|
# Ensure the payout user has complete banking info
|
||||||
|
@payout.user.update!(
|
||||||
|
iban: "FR1420041010050500013M02606",
|
||||||
|
bank_name: "Test Bank",
|
||||||
|
account_holder_name: "Test User"
|
||||||
|
)
|
||||||
|
|
||||||
|
post approve_admin_payout_url(@payout)
|
||||||
|
assert_redirected_to admin_payout_path(@payout)
|
||||||
|
assert_match /Payout approved successfully/, flash[:notice]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user