refactor: prepare for free ticket
This commit is contained in:
@@ -125,7 +125,7 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal "draft", new_order.status
|
||||
assert_equal @user, new_order.user
|
||||
assert_equal @event, new_order.event
|
||||
assert_equal @ticket_type.price_cents + 100, new_order.total_amount_cents # includes 1€ service fee
|
||||
assert_equal @ticket_type.price_cents, new_order.total_amount_cents # Service fee deducted from promoter payout, not added to customer
|
||||
|
||||
assert_redirected_to checkout_order_path(new_order)
|
||||
assert_equal new_order.id, session[:draft_order_id]
|
||||
|
||||
@@ -603,4 +603,22 @@ class OrderTest < ActiveSupport::TestCase
|
||||
result = order.stripe_invoice_pdf_url
|
||||
assert_nil result
|
||||
end
|
||||
|
||||
test "free? should return true for zero amount orders" do
|
||||
free_order = Order.create!(
|
||||
user: @user, event: @event, total_amount_cents: 0,
|
||||
status: "draft", payment_attempts: 0
|
||||
)
|
||||
|
||||
assert free_order.free?
|
||||
end
|
||||
|
||||
test "free? should return false for non-zero amount orders" do
|
||||
paid_order = Order.create!(
|
||||
user: @user, event: @event, total_amount_cents: 1000,
|
||||
status: "draft", payment_attempts: 0
|
||||
)
|
||||
|
||||
assert_not paid_order.free?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -244,4 +244,38 @@ class TicketTypeTest < ActiveSupport::TestCase
|
||||
)
|
||||
assert_not ticket_type.save
|
||||
end
|
||||
|
||||
test "should allow free tickets with zero price" do
|
||||
user = User.create!(
|
||||
email: "test@example.com",
|
||||
password: "password123",
|
||||
password_confirmation: "password123"
|
||||
)
|
||||
|
||||
event = Event.create!(
|
||||
name: "Test Event",
|
||||
slug: "test-event",
|
||||
description: "Valid description for the event that is long enough",
|
||||
latitude: 48.8566,
|
||||
longitude: 2.3522,
|
||||
venue_name: "Test Venue",
|
||||
venue_address: "123 Test Street",
|
||||
user: user
|
||||
)
|
||||
|
||||
ticket_type = TicketType.new(
|
||||
name: "Free Ticket",
|
||||
description: "Valid description for the free ticket type",
|
||||
price_cents: 0,
|
||||
quantity: 50,
|
||||
sale_start_at: Time.current,
|
||||
sale_end_at: Time.current + 1.day,
|
||||
event: event
|
||||
)
|
||||
|
||||
assert ticket_type.save
|
||||
assert ticket_type.free?
|
||||
assert_equal 0, ticket_type.price_cents
|
||||
assert_equal 0.0, ticket_type.price_euros
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user