129 lines
4.9 KiB
Ruby
129 lines
4.9 KiB
Ruby
require "test_helper"
|
|
|
|
class Promoter::EventsControllerTest < ActionDispatch::IntegrationTest
|
|
setup do
|
|
@promoter = User.create!(email: "promoter@example.com", password: "password123", password_confirmation: "password123", is_professionnal: true, onboarding_completed: true)
|
|
@event = Event.create!(name: "Test Event", slug: "test-event", description: "A valid description for the test event that is long enough to meet the minimum character requirement", latitude: 48.8566, longitude: 2.3522, venue_name: "Venue", venue_address: "Address", user: @promoter, start_time: 1.week.from_now, end_time: 1.week.from_now + 3.hours, state: :draft)
|
|
end
|
|
|
|
test "should require authentication for index" do
|
|
get promoter_events_path
|
|
assert_redirected_to new_user_session_path
|
|
end
|
|
|
|
test "should get index for authenticated promoter" do
|
|
sign_in @promoter
|
|
get promoter_events_path
|
|
assert_response :success
|
|
end
|
|
|
|
test "should show promoter's events only" do
|
|
sign_in @promoter
|
|
other_event = Event.create!(name: "Other Event", slug: "other", description: "Valid description for the event", latitude: 48.0, longitude: 2.0, venue_name: "V", venue_address: "A", user_id: users(:one).id, start_time: 1.day.from_now, end_time: 2.days.from_now, state: :draft)
|
|
get promoter_events_path
|
|
assert_response :success
|
|
assert_includes assigns(:events), @event
|
|
assert_not_includes assigns(:events), other_event
|
|
end
|
|
|
|
test "should duplicate an event with ticket types" do
|
|
sign_in @promoter
|
|
|
|
# Create ticket types for the event
|
|
ticket_type1 = TicketType.create!(
|
|
name: "Standard Ticket",
|
|
description: "A standard ticket for the event with all the basic access",
|
|
price_cents: 2000,
|
|
quantity: 100,
|
|
sale_start_at: 1.day.ago,
|
|
sale_end_at: @event.start_time - 1.hour,
|
|
event: @event
|
|
)
|
|
|
|
ticket_type2 = TicketType.create!(
|
|
name: "VIP Ticket",
|
|
description: "A VIP ticket for the event with special access",
|
|
price_cents: 5000,
|
|
quantity: 50,
|
|
sale_start_at: 1.day.ago,
|
|
sale_end_at: @event.start_time - 1.hour,
|
|
event: @event
|
|
)
|
|
|
|
# Verify that ticket types were created successfully
|
|
assert ticket_type1.valid?
|
|
assert ticket_type2.valid?
|
|
|
|
# Duplicate the event
|
|
assert_difference("Event.count", 1) do
|
|
post duplicate_promoter_event_path(@event), params: { clone_ticket_types: "true" }
|
|
end
|
|
|
|
# Check that the new event was created
|
|
assert_redirected_to edit_promoter_event_path(Event.last)
|
|
assert_equal "Événement dupliqué avec succès! Vous pouvez maintenant modifier les détails de l'événement copié.", flash[:notice]
|
|
|
|
# Check that the new event has the correct attributes
|
|
new_event = Event.last
|
|
assert_equal "Copie de #{@event.name}", new_event.name
|
|
assert_equal "draft", new_event.state
|
|
assert_equal @event.venue_name, new_event.venue_name
|
|
assert_equal @event.venue_address, new_event.venue_address
|
|
|
|
# Check that ticket types were duplicated
|
|
assert_equal 2, new_event.ticket_types.count
|
|
assert_equal "Standard Ticket", new_event.ticket_types.find_by(name: "Standard Ticket").name
|
|
assert_equal "VIP Ticket", new_event.ticket_types.find_by(name: "VIP Ticket").name
|
|
end
|
|
|
|
test "should duplicate an event without ticket types" do
|
|
sign_in @promoter
|
|
|
|
# Create ticket types for the event
|
|
ticket_type1 = TicketType.create!(
|
|
name: "Standard Ticket",
|
|
description: "A standard ticket for the event with all the basic access",
|
|
price_cents: 2000,
|
|
quantity: 100,
|
|
sale_start_at: 1.day.ago,
|
|
sale_end_at: @event.start_time - 1.hour,
|
|
event: @event
|
|
)
|
|
|
|
ticket_type2 = TicketType.create!(
|
|
name: "VIP Ticket",
|
|
description: "A VIP ticket for the event with special access",
|
|
price_cents: 5000,
|
|
quantity: 50,
|
|
sale_start_at: 1.day.ago,
|
|
sale_end_at: @event.start_time - 1.hour,
|
|
event: @event
|
|
)
|
|
|
|
# Verify that ticket types were created successfully
|
|
assert ticket_type1.valid?
|
|
assert ticket_type2.valid?
|
|
|
|
# Duplicate the event without ticket types
|
|
assert_difference("Event.count", 1) do
|
|
post duplicate_promoter_event_path(@event), params: { clone_ticket_types: "false" }
|
|
end
|
|
|
|
# Check that the new event was created
|
|
assert_redirected_to edit_promoter_event_path(Event.last)
|
|
assert_equal "Événement dupliqué avec succès! Vous pouvez maintenant modifier les détails de l'événement copié.", flash[:notice]
|
|
|
|
# Check that the new event has the correct attributes
|
|
new_event = Event.last
|
|
assert_equal "Copie de #{@event.name}", new_event.name
|
|
assert_equal "draft", new_event.state
|
|
assert_equal @event.venue_name, new_event.venue_name
|
|
assert_equal @event.venue_address, new_event.venue_address
|
|
|
|
# Check that ticket types were NOT duplicated
|
|
assert_equal 0, new_event.ticket_types.count
|
|
end
|
|
|
|
# Add tests for new, create, etc. as needed
|
|
end
|