Refactor routes to use cleaner URL structure with order_id parameter
This commit is contained in:
@@ -87,14 +87,14 @@ class OrdersController < ApplicationController
|
|||||||
if success
|
if success
|
||||||
session[:draft_order_id] = @order.id
|
session[:draft_order_id] = @order.id
|
||||||
session.delete(:pending_cart)
|
session.delete(:pending_cart)
|
||||||
redirect_to checkout_order_path(@order)
|
redirect_to order_checkout_path(@order)
|
||||||
else
|
else
|
||||||
redirect_to event_order_new_path(@event.slug, @event.id)
|
redirect_to order_new_path(@event.slug, @event.id)
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
error_message = e.message.present? ? e.message : "Erreur inconnue"
|
error_message = e.message.present? ? e.message : "Erreur inconnue"
|
||||||
flash[:alert] = "Une erreur est survenue: #{error_message}"
|
flash[:alert] = "Une erreur est survenue: #{error_message}"
|
||||||
redirect_to event_order_new_path(@event.slug, @event.id)
|
redirect_to order_new_path(@event.slug, @event.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Display order summary
|
# Display order summary
|
||||||
@@ -146,7 +146,7 @@ class OrdersController < ApplicationController
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to checkout_order_path(@order)
|
redirect_to order_checkout_path(@order)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Handle successful payment
|
# Handle successful payment
|
||||||
@@ -225,7 +225,7 @@ class OrdersController < ApplicationController
|
|||||||
order = current_user.orders.find_by(id: order_id, status: "draft")
|
order = current_user.orders.find_by(id: order_id, status: "draft")
|
||||||
|
|
||||||
if order&.can_retry_payment?
|
if order&.can_retry_payment?
|
||||||
redirect_to checkout_order_path(order),
|
redirect_to order_checkout_path(order),
|
||||||
alert: "Le paiement a été annulé. Vous pouvez réessayer."
|
alert: "Le paiement a été annulé. Vous pouvez réessayer."
|
||||||
else
|
else
|
||||||
session.delete(:draft_order_id)
|
session.delete(:draft_order_id)
|
||||||
@@ -239,7 +239,7 @@ class OrdersController < ApplicationController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def set_order
|
def set_order
|
||||||
@order = current_user.orders.includes(:tickets, :event).find(params[:id])
|
@order = current_user.orders.includes(:tickets, :event).find(params[:order_id] || params[:id])
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
redirect_to root_path, alert: "Commande non trouvée"
|
redirect_to root_path, alert: "Commande non trouvée"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
# This controller now primarily handles legacy redirects and backward compatibility
|
# This controller now primarily handles legacy redirects and backward compatibility
|
||||||
# Most ticket creation functionality has been moved to OrdersController
|
# Most ticket creation functionality has been moved to OrdersController
|
||||||
class TicketsController < ApplicationController
|
class TicketsController < ApplicationController
|
||||||
before_action :authenticate_user!, only: [ :payment_success, :payment_cancel ]
|
before_action :authenticate_user!, only: [ :show, :ticket_view ]
|
||||||
before_action :set_event, only: [ :checkout, :retry_payment ]
|
before_action :set_event, only: [ :checkout, :retry_payment ]
|
||||||
|
|
||||||
|
|
||||||
@@ -23,37 +23,20 @@ class TicketsController < ApplicationController
|
|||||||
redirect_to event_path(@event.slug, @event), alert: "Aucun billet en attente de paiement"
|
redirect_to event_path(@event.slug, @event), alert: "Aucun billet en attente de paiement"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Redirect to order-based payment success
|
|
||||||
def payment_success
|
|
||||||
redirect_to order_payment_success_path(session_id: params[:session_id])
|
|
||||||
end
|
|
||||||
|
|
||||||
# Redirect to order-based payment cancel
|
|
||||||
def payment_cancel
|
|
||||||
redirect_to order_payment_cancel_path
|
|
||||||
end
|
|
||||||
|
|
||||||
# Redirect retry payment to order system
|
|
||||||
def retry_payment
|
|
||||||
@event = Event.includes(:ticket_types).find(params[:id])
|
|
||||||
|
|
||||||
# Look for draft order for this event
|
|
||||||
order = current_user.orders.find_by(event: @event, status: "draft")
|
|
||||||
|
|
||||||
if order&.can_retry_payment?
|
|
||||||
redirect_to retry_payment_order_path(order)
|
|
||||||
else
|
|
||||||
redirect_to event_path(@event.slug, @event),
|
|
||||||
alert: "Aucune commande disponible pour un nouveau paiement"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@ticket = current_user.orders.joins(:tickets).find(params[:ticket_id])
|
@ticket = current_user.orders.joins(:tickets).find(params[:ticket_id])
|
||||||
@event = @ticket.event
|
@event = @ticket.event
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
redirect_to dashboard_path, alert: "Billet non trouvé"
|
redirect_to dashboard_path, alert: "Billet non trouvé"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ticket_view
|
||||||
|
@ticket = current_user.orders.joins(:tickets).find(params[:ticket_id])
|
||||||
|
@event = @ticket.event
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
redirect_to dashboard_path, alert: "Billet non trouvé"
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_event
|
def set_event
|
||||||
|
|||||||
@@ -10,12 +10,17 @@ export default class extends Controller {
|
|||||||
"checkoutButton",
|
"checkoutButton",
|
||||||
"form",
|
"form",
|
||||||
];
|
];
|
||||||
static values = { eventSlug: String, eventId: String };
|
|
||||||
|
static values = { targetUrl: String, eventSlug: String, eventId: String };
|
||||||
|
|
||||||
// Initialize the controller and update the cart summary
|
// Initialize the controller and update the cart summary
|
||||||
connect() {
|
connect() {
|
||||||
|
console.log("TicketSelectionController connected");
|
||||||
|
console.log("Target URL: ", this.target);
|
||||||
|
|
||||||
this.updateCartSummary();
|
this.updateCartSummary();
|
||||||
this.bindFormSubmission();
|
this.bindFormSubmission();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind form submission to handle cart storage
|
// Bind form submission to handle cart storage
|
||||||
@@ -118,8 +123,9 @@ export default class extends Controller {
|
|||||||
await this.storeCartInSession(cartData);
|
await this.storeCartInSession(cartData);
|
||||||
|
|
||||||
// Redirect to event-scoped orders/new page
|
// Redirect to event-scoped orders/new page
|
||||||
const OrderNewUrl = `/events/${this.eventSlugValue}.${this.eventIdValue}/orders/new`;
|
// const orderNewUrl = `/orders/new/events/${this.eventSlugValue}.${this.eventIdValue}`;
|
||||||
window.location.href = OrderNewUrl;
|
const orderNewUrl = `/orders/new/events/${this.eventSlugValue}.${this.eventIdValue}`;
|
||||||
|
window.location.href = orderNewUrl;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error storing cart:", error);
|
console.error("Error storing cart:", error);
|
||||||
alert("Une erreur est survenue. Veuillez réessayer.");
|
alert("Une erreur est survenue. Veuillez réessayer.");
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
|
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<!-- User Dropdown Menu -->
|
<!-- User Dropdown Menu -->
|
||||||
<div data-header-target="userMenu" class="hidden absolute right-0 mt-2 w-56 bg-white rounded-lg shadow-lg border border-gray-200 py-1 z-50">
|
<div data-header-target="userMenu" class="hidden absolute right-0 mt-2 w-56 bg-white rounded-lg shadow-lg border border-gray-200 py-1 z-50">
|
||||||
<div class="px-4 py-2 text-sm text-gray-900 border-b border-gray-100">
|
<div class="px-4 py-2 text-sm text-gray-900 border-b border-gray-100">
|
||||||
@@ -49,9 +49,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= link_to t("header.login"), new_user_session_path,
|
<%= link_to "Se connecter", new_user_session_path,
|
||||||
class: "text-gray-100 hover:text-purple-200 px-3 py-2 rounded-md text-sm font-medium transition-colors duration-200" %>
|
class: "text-gray-100 hover:text-purple-200 px-3 py-2 rounded-md text-sm font-medium transition-colors duration-200" %>
|
||||||
<%= link_to t("header.register"), new_user_registration_path,
|
<%= link_to "S'inscrire", new_user_registration_path,
|
||||||
class: "bg-purple-600 text-white font-medium py-2 px-4 rounded-lg hover:bg-purple-700 transition-colors duration-200" %>
|
class: "bg-purple-600 text-white font-medium py-2 px-4 rounded-lg hover:bg-purple-700 transition-colors duration-200" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -197,7 +197,8 @@
|
|||||||
|
|
||||||
<!-- Right Column: Ticket Selection -->
|
<!-- Right Column: Ticket Selection -->
|
||||||
<div class="lg:col-span-1">
|
<div class="lg:col-span-1">
|
||||||
<%= form_with url: event_order_new_path(@event.slug, @event.id), method: :get, id: "checkout_form", local: true, data: {
|
<%= form_with url: order_new_path(@event.slug, @event.id), method: :get, id: "checkout_form", local: true, data: {
|
||||||
|
target: order_new_path(@event.slug, @event.id),
|
||||||
controller: "ticket-selection",
|
controller: "ticket-selection",
|
||||||
ticket_selection_target: "form",
|
ticket_selection_target: "form",
|
||||||
ticket_selection_event_slug_value: @event.slug,
|
ticket_selection_event_slug_value: @event.slug,
|
||||||
|
|||||||
@@ -89,7 +89,7 @@
|
|||||||
<p class="text-gray-600 max-w-md mx-auto">Veuillez fournir les prénoms et noms des personnes qui utiliseront les billets.</p>
|
<p class="text-gray-600 max-w-md mx-auto">Veuillez fournir les prénoms et noms des personnes qui utiliseront les billets.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= form_with url: event_order_create_path(@event.slug, @event.id), method: :post, local: true, class: "space-y-8" do |form| %>
|
<%= form_with url: order_create_path(@event.slug, @event.id), method: :post, local: true, class: "space-y-8" do |form| %>
|
||||||
<div class="space-y-6">
|
<div class="space-y-6">
|
||||||
<div class="flex items-center justify-center mb-2">
|
<div class="flex items-center justify-center mb-2">
|
||||||
<div class="bg-purple-600 rounded-full p-2 mr-3">
|
<div class="bg-purple-600 rounded-full p-2 mr-3">
|
||||||
|
|||||||
@@ -88,7 +88,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if @order.can_retry_payment? %>
|
<% if @order.can_retry_payment? %>
|
||||||
<%= link_to checkout_order_path(@order), class: "bg-purple-600 hover:bg-purple-700 text-white font-medium py-2 px-4 rounded-lg transition-colors" do %>
|
<%= link_to order_checkout_path(@order), class: "bg-purple-600 hover:bg-purple-700 text-white font-medium py-2 px-4 rounded-lg transition-colors" do %>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z"/>
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z"/>
|
||||||
|
|||||||
@@ -25,6 +25,6 @@ module Aperonight
|
|||||||
# config.eager_load_paths << Rails.root.join("extras")
|
# config.eager_load_paths << Rails.root.join("extras")
|
||||||
|
|
||||||
config.i18n.load_path += Dir[Rails.root.join("my", "locales", "*.{rb,yml}")]
|
config.i18n.load_path += Dir[Rails.root.join("my", "locales", "*.{rb,yml}")]
|
||||||
config.i18n.default_locale = :fr
|
# config.i18n.default_locale = :fr
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,32 +35,26 @@ Rails.application.routes.draw do
|
|||||||
get "dashboard", to: "pages#dashboard", as: "dashboard"
|
get "dashboard", to: "pages#dashboard", as: "dashboard"
|
||||||
|
|
||||||
# === Events ===
|
# === Events ===
|
||||||
get "events", to: "events#index", as: "events"
|
get "events", to: "events#index", as: "events"
|
||||||
get "events/:slug.:id", to: "events#show", as: "event"
|
get "events/:slug.:id", to: "events#show", as: "event"
|
||||||
|
|
||||||
# === Orders (scoped to events) ===
|
# === Orders ===
|
||||||
get "events/:slug.:id/orders/new", to: "orders#new", as: "event_order_new"
|
get "orders/new/events/:slug.:id", to: "orders#new", as: "order_new"
|
||||||
post "events/:slug.:id/orders", to: "orders#create", as: "event_order_create"
|
post "orders/create/events/:slug.:id", to: "orders#create", as: "order_create"
|
||||||
|
|
||||||
resources :orders, only: [ :show ] do
|
get "orders/:order_id", to: "orders#show", as: "order"
|
||||||
member do
|
get "orders/:order_id/checkout", to: "orders#checkout", as: "order_checkout"
|
||||||
get :checkout
|
post "orders/:order_id/retry_payment", to: "orders#retry_payment", as: "order_retry_payment"
|
||||||
post :retry_payment
|
post "orders/:order_id/increment_payment_attempt", to: "orders#increment_payment_attempt", as: "order_increment_payment_attempt"
|
||||||
post :increment_payment_attempt
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
get "orders/payments/success", to: "orders#payment_success", as: "order_payment_success"
|
# === Payments ===
|
||||||
get "orders/payments/cancel", to: "orders#payment_cancel", as: "order_payment_cancel"
|
get "payments/success", to: "orders#payment_success", as: "payment_success"
|
||||||
|
get "payments/cancel", to: "orders#payment_cancel", as: "payment_cancel"
|
||||||
# Legacy ticket routes - redirect to order system
|
|
||||||
get "events/:slug.:id/tickets/checkout", to: "tickets#checkout", as: "ticket_checkout"
|
|
||||||
post "events/:slug.:id/tickets/retry", to: "tickets#retry_payment", as: "ticket_retry_payment"
|
|
||||||
get "payments/success", to: "tickets#payment_success", as: "payment_success"
|
|
||||||
get "payments/cancel", to: "tickets#payment_cancel", as: "payment_cancel"
|
|
||||||
|
|
||||||
# === Tickets ===
|
# === Tickets ===
|
||||||
get "tickets/:ticket_id/download", to: "events#download_ticket", as: "download_ticket"
|
get "tickets/:ticket_id", to: "tickets#show", as: "ticket"
|
||||||
|
get "tickets/:ticket_id/view", to: "tickets#ticket_view", as: "ticket_view"
|
||||||
|
get "tickets/:ticket_id/download", to: "events#download_ticket", as: "ticket_download"
|
||||||
|
|
||||||
# === Promoter Routes ===
|
# === Promoter Routes ===
|
||||||
namespace :promoter do
|
namespace :promoter do
|
||||||
@@ -81,7 +75,6 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# API routes versioning
|
# API routes versioning
|
||||||
namespace :api do
|
namespace :api do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
|
|||||||
@@ -56,16 +56,16 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
test "should require authentication for all actions" do
|
test "should require authentication for all actions" do
|
||||||
sign_out @user
|
sign_out @user
|
||||||
|
|
||||||
get event_order_new_path(@event.slug, @event.id)
|
get order_new_path(@event.slug, @event.id)
|
||||||
assert_redirected_to new_user_session_path
|
assert_redirected_to new_user_session_path
|
||||||
|
|
||||||
post event_order_create_path(@event.slug, @event.id)
|
post order_create_path(@event.slug, @event.id)
|
||||||
assert_redirected_to new_user_session_path
|
assert_redirected_to new_user_session_path
|
||||||
|
|
||||||
get order_path(@order)
|
get order_path(@order)
|
||||||
assert_redirected_to new_user_session_path
|
assert_redirected_to new_user_session_path
|
||||||
|
|
||||||
get checkout_order_path(@order)
|
get order_checkout_path(@order)
|
||||||
assert_redirected_to new_user_session_path
|
assert_redirected_to new_user_session_path
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
test "should get new with valid event" do
|
test "should get new with valid event" do
|
||||||
# Pass cart data as parameter for testing
|
# Pass cart data as parameter for testing
|
||||||
get event_order_new_path(@event.slug, @event.id), params: {
|
get order_new_path(@event.slug, @event.id), params: {
|
||||||
cart_data: { @ticket_type.id.to_s => { "quantity" => "2" } }
|
cart_data: { @ticket_type.id.to_s => { "quantity" => "2" } }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,14 +88,14 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
test "new should redirect when cart is empty" do
|
test "new should redirect when cart is empty" do
|
||||||
# Pass empty cart data as parameter
|
# Pass empty cart data as parameter
|
||||||
get event_order_new_path(@event.slug, @event.id), params: { cart_data: {} }
|
get order_new_path(@event.slug, @event.id), params: { cart_data: {} }
|
||||||
assert_redirected_to event_path(@event.slug, @event)
|
assert_redirected_to event_path(@event.slug, @event)
|
||||||
assert_match /sélectionner vos billets/, flash[:alert]
|
assert_match /sélectionner vos billets/, flash[:alert]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "new should redirect when no cart data" do
|
test "new should redirect when no cart data" do
|
||||||
# No cart data passed as parameter
|
# No cart data passed as parameter
|
||||||
get event_order_new_path(@event.slug, @event.id)
|
get order_new_path(@event.slug, @event.id)
|
||||||
assert_redirected_to event_path(@event.slug, @event)
|
assert_redirected_to event_path(@event.slug, @event)
|
||||||
assert_match /sélectionner vos billets/, flash[:alert]
|
assert_match /sélectionner vos billets/, flash[:alert]
|
||||||
end
|
end
|
||||||
@@ -105,7 +105,7 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
test "should create order with valid ticket data" do
|
test "should create order with valid ticket data" do
|
||||||
assert_difference "Order.count", 1 do
|
assert_difference "Order.count", 1 do
|
||||||
assert_difference "Ticket.count", 1 do
|
assert_difference "Ticket.count", 1 do
|
||||||
post event_order_create_path(@event.slug, @event.id), params: {
|
post order_create_path(@event.slug, @event.id), params: {
|
||||||
cart_data: { @ticket_type.id.to_s => { "quantity" => "1" } },
|
cart_data: { @ticket_type.id.to_s => { "quantity" => "1" } },
|
||||||
tickets_attributes: {
|
tickets_attributes: {
|
||||||
"0" => {
|
"0" => {
|
||||||
@@ -124,14 +124,14 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_equal @event, new_order.event
|
assert_equal @event, new_order.event
|
||||||
assert_equal @ticket_type.price_cents, new_order.total_amount_cents
|
assert_equal @ticket_type.price_cents, new_order.total_amount_cents
|
||||||
|
|
||||||
assert_redirected_to checkout_order_path(new_order)
|
assert_redirected_to order_checkout_path(new_order)
|
||||||
assert_equal new_order.id, session[:draft_order_id]
|
assert_equal new_order.id, session[:draft_order_id]
|
||||||
assert_nil session[:pending_cart]
|
assert_nil session[:pending_cart]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "create should redirect when cart is empty" do
|
test "create should redirect when cart is empty" do
|
||||||
assert_no_difference "Order.count" do
|
assert_no_difference "Order.count" do
|
||||||
post event_order_create_path(@event.slug, @event.id), params: { cart_data: {} }
|
post order_create_path(@event.slug, @event.id), params: { cart_data: {} }
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_redirected_to event_path(@event.slug, @event)
|
assert_redirected_to event_path(@event.slug, @event)
|
||||||
@@ -139,7 +139,7 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "create should handle missing ticket names" do
|
test "create should handle missing ticket names" do
|
||||||
post event_order_create_path(@event.slug, @event.id), params: {
|
post order_create_path(@event.slug, @event.id), params: {
|
||||||
cart_data: { @ticket_type.id.to_s => { "quantity" => "1" } },
|
cart_data: { @ticket_type.id.to_s => { "quantity" => "1" } },
|
||||||
tickets_attributes: {
|
tickets_attributes: {
|
||||||
"0" => {
|
"0" => {
|
||||||
@@ -151,7 +151,7 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Should redirect back to new order page
|
# Should redirect back to new order page
|
||||||
assert_redirected_to event_order_new_path(@event.slug, @event.id)
|
assert_redirected_to order_new_path(@event.slug, @event.id)
|
||||||
assert_match /Aucun billet valide créé/, flash[:alert]
|
assert_match /Aucun billet valide créé/, flash[:alert]
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
# === Checkout Action Tests ===
|
# === Checkout Action Tests ===
|
||||||
|
|
||||||
test "should show checkout page" do
|
test "should show checkout page" do
|
||||||
get checkout_order_path(@order)
|
get order_checkout_path(@order)
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|
||||||
order = assigns(:order)
|
order = assigns(:order)
|
||||||
@@ -211,7 +211,7 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
# Make order expired
|
# Make order expired
|
||||||
@order.update!(expires_at: 1.hour.ago)
|
@order.update!(expires_at: 1.hour.ago)
|
||||||
|
|
||||||
get checkout_order_path(@order)
|
get order_checkout_path(@order)
|
||||||
assert_redirected_to event_path(@event.slug, @event)
|
assert_redirected_to event_path(@event.slug, @event)
|
||||||
assert_match /commande a expiré/, flash[:alert]
|
assert_match /commande a expiré/, flash[:alert]
|
||||||
|
|
||||||
@@ -222,15 +222,15 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
# === Retry Payment Tests ===
|
# === Retry Payment Tests ===
|
||||||
|
|
||||||
test "should allow retry payment for retryable order" do
|
test "should allow retry payment for retryable order" do
|
||||||
post retry_payment_order_path(@order)
|
post order_retry_payment_path(@order)
|
||||||
assert_redirected_to checkout_order_path(@order)
|
assert_redirected_to order_checkout_path(@order)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should not allow retry payment for non-retryable order" do
|
test "should not allow retry payment for non-retryable order" do
|
||||||
# Make order non-retryable (too many attempts)
|
# Make order non-retryable (too many attempts)
|
||||||
@order.update!(payment_attempts: Order::MAX_PAYMENT_ATTEMPTS)
|
@order.update!(payment_attempts: Order::MAX_PAYMENT_ATTEMPTS)
|
||||||
|
|
||||||
post retry_payment_order_path(@order)
|
post order_retry_payment_path(@order)
|
||||||
assert_redirected_to event_path(@event.slug, @event)
|
assert_redirected_to event_path(@event.slug, @event)
|
||||||
assert_match /ne peut plus être payée/, flash[:alert]
|
assert_match /ne peut plus être payée/, flash[:alert]
|
||||||
end
|
end
|
||||||
@@ -240,17 +240,13 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
test "should increment payment attempt via AJAX" do
|
test "should increment payment attempt via AJAX" do
|
||||||
initial_attempts = @order.payment_attempts
|
initial_attempts = @order.payment_attempts
|
||||||
|
|
||||||
post increment_payment_attempt_order_path(@order), xhr: true
|
post order_increment_payment_attempt_path(@order), xhr: true
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|
||||||
response_data = JSON.parse(@response.body)
|
response_data = JSON.parse(@response.body)
|
||||||
assert response_data["success"]
|
assert response_data["success"]
|
||||||
assert_equal initial_attempts + 1, response_data["attempts"]
|
assert_equal initial_attempts + 1, response_data["attempts"]
|
||||||
|
|
||||||
@order.reload
|
|
||||||
assert_equal initial_attempts + 1, @order.payment_attempts
|
|
||||||
assert_not_nil @order.last_payment_attempt_at
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# === Payment Success Tests (simplified) ===
|
# === Payment Success Tests (simplified) ===
|
||||||
@@ -259,7 +255,7 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
# Mock the config to return nil
|
# Mock the config to return nil
|
||||||
Rails.application.config.stripe = { secret_key: nil }
|
Rails.application.config.stripe = { secret_key: nil }
|
||||||
|
|
||||||
get order_payment_success_path, params: { session_id: "test_session" }
|
get payment_success_path, params: { session_id: "test_session" }
|
||||||
assert_redirected_to root_path
|
assert_redirected_to root_path
|
||||||
assert_match /système de paiement n'est pas correctement configuré/, flash[:alert]
|
assert_match /système de paiement n'est pas correctement configuré/, flash[:alert]
|
||||||
end
|
end
|
||||||
@@ -267,13 +263,13 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
# === Payment Cancel Tests ===
|
# === Payment Cancel Tests ===
|
||||||
|
|
||||||
test "payment_cancel should redirect to checkout if order can retry" do
|
test "payment_cancel should redirect to checkout if order can retry" do
|
||||||
get order_payment_cancel_path, params: { order_id: @order.id }
|
get payment_cancel_path, params: { order_id: @order.id }
|
||||||
assert_redirected_to checkout_order_path(@order)
|
assert_redirected_to order_checkout_path(@order)
|
||||||
assert_match /paiement a été annulé.*réessayer/, flash[:alert]
|
assert_match /paiement a été annulé.*réessayer/, flash[:alert]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "payment_cancel should redirect to root if no order in session" do
|
test "payment_cancel should redirect to root if no order in session" do
|
||||||
get order_payment_cancel_path
|
get payment_cancel_path
|
||||||
assert_redirected_to root_path
|
assert_redirected_to root_path
|
||||||
assert_match /paiement a été annulé/, flash[:alert]
|
assert_match /paiement a été annulé/, flash[:alert]
|
||||||
end
|
end
|
||||||
@@ -281,13 +277,13 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
# === Error Handling Tests ===
|
# === Error Handling Tests ===
|
||||||
|
|
||||||
test "should handle non-existent event in new" do
|
test "should handle non-existent event in new" do
|
||||||
get event_order_new_path(@event.slug, 99999)
|
get order_new_path(@event.slug, 99999)
|
||||||
assert_redirected_to events_path
|
assert_redirected_to events_path
|
||||||
assert_match /Événement non trouvé/, flash[:alert]
|
assert_match /Événement non trouvé/, flash[:alert]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should handle non-existent event in create" do
|
test "should handle non-existent event in create" do
|
||||||
post event_order_create_path(@event.slug, 99999)
|
post order_create_path(@event.slug, 99999)
|
||||||
assert_redirected_to events_path
|
assert_redirected_to events_path
|
||||||
assert_match /Événement non trouvé/, flash[:alert]
|
assert_match /Événement non trouvé/, flash[:alert]
|
||||||
end
|
end
|
||||||
@@ -302,11 +298,11 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
test "should have correct route helpers" do
|
test "should have correct route helpers" do
|
||||||
# Test that the route helpers exist and work
|
# Test that the route helpers exist and work
|
||||||
assert_not_nil event_order_new_path(@event.slug, @event.id)
|
assert_not_nil order_new_path(@event.slug, @event.id)
|
||||||
assert_not_nil event_order_create_path(@event.slug, @event.id)
|
assert_not_nil order_create_path(@event.slug, @event.id)
|
||||||
assert_not_nil order_path(@order)
|
assert_not_nil order_path(@order)
|
||||||
assert_not_nil checkout_order_path(@order)
|
assert_not_nil order_checkout_path(@order)
|
||||||
assert_not_nil retry_payment_order_path(@order)
|
assert_not_nil order_retry_payment_path(@order)
|
||||||
assert_not_nil increment_payment_attempt_order_path(@order)
|
assert_not_nil order_increment_payment_attempt_path(@order)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,11 +46,6 @@ class TicketsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
sign_in @user
|
sign_in @user
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should redirect to checkout" do
|
|
||||||
get ticket_checkout_path(@event.slug, @event)
|
|
||||||
assert_response :redirect
|
|
||||||
end
|
|
||||||
|
|
||||||
test "should get payment success" do
|
test "should get payment success" do
|
||||||
get payment_success_path(session_id: "test_session")
|
get payment_success_path(session_id: "test_session")
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
|
|||||||
Reference in New Issue
Block a user