diff --git a/app/controllers/admin/payouts_controller.rb b/app/controllers/admin/payouts_controller.rb index 80240b8..f148fa6 100644 --- a/app/controllers/admin/payouts_controller.rb +++ b/app/controllers/admin/payouts_controller.rb @@ -60,12 +60,6 @@ class Admin::PayoutsController < ApplicationController 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 def set_payout diff --git a/config/routes.rb b/config/routes.rb index 12a53ec..8417c12 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,16 +1,4 @@ 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 # 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 + # === 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 namespace :api do namespace :v1 do diff --git a/test/controllers/admin/payouts_controller_test.rb b/test/controllers/admin/payouts_controller_test.rb index b549632..324981d 100644 --- a/test/controllers/admin/payouts_controller_test.rb +++ b/test/controllers/admin/payouts_controller_test.rb @@ -2,46 +2,28 @@ require "test_helper" class Admin::PayoutsControllerTest < ActionDispatch::IntegrationTest 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) end - test "process payout success for pending payout" do - sign_in @admin_user - @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) + test "approve payout requires admin authentication" do + post approve_admin_payout_url(@payout) assert_redirected_to new_user_session_path 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