Add event duplication feature with ticket types cloning
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -271,4 +271,28 @@ class EventTest < ActiveSupport::TestCase
|
||||
event = Event.new
|
||||
assert_not event.allow_booking_during_event?
|
||||
end
|
||||
|
||||
test "should duplicate event with ticket types" do
|
||||
user = User.create!(email: "test@example.com", password: "password123", password_confirmation: "password123")
|
||||
event = Event.create!(name: "Original Event", slug: "original", description: "A description that is sufficiently long", venue_name: "v", venue_address: "a", user: user, latitude: 48.0, longitude: 2.0, start_time: 1.week.from_now, state: :published)
|
||||
|
||||
# Create ticket types
|
||||
ticket_type1 = TicketType.create!(name: "Standard", description: "A standard ticket for the event", 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", description: "A VIP ticket for the event", price_cents: 5000, quantity: 50, sale_start_at: 1.day.ago, sale_end_at: event.start_time - 1.hour, event: event)
|
||||
|
||||
# Duplicate the event
|
||||
duplicated_event = event.duplicate
|
||||
|
||||
# Check that duplication was successful
|
||||
assert_not_nil duplicated_event
|
||||
assert_equal "Copie de #{event.name}", duplicated_event.name
|
||||
assert_equal "draft", duplicated_event.state
|
||||
assert_equal event.venue_name, duplicated_event.venue_name
|
||||
assert_equal event.venue_address, duplicated_event.venue_address
|
||||
|
||||
# Check that ticket types were duplicated
|
||||
assert_equal 2, duplicated_event.ticket_types.count
|
||||
assert_equal "Standard", duplicated_event.ticket_types.find_by(name: "Standard").name
|
||||
assert_equal "VIP", duplicated_event.ticket_types.find_by(name: "VIP").name
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user