Files
aperonight/test/controllers/tickets_controller_test.rb
kbe ed5ff4b8fd Add comprehensive test suite for all application components
## Test Coverage Added:
- **Order Model**: 42 tests covering validations, associations, scopes, business logic, callbacks, and payment handling
- **Events Controller**: 17 tests covering index/show actions, pagination, authentication, template rendering, and edge cases
- **Orders Controller**: 21 tests covering authentication, cart handling, order creation, checkout, payment retry, and error scenarios
- **Service Classes**:
  - TicketPdfGenerator: 15 tests for PDF generation, QR codes, error handling
  - StripeInvoiceService: Enhanced existing tests with 18 total tests for Stripe integration, customer handling, invoice creation
- **Background Jobs**:
  - ExpiredOrdersCleanupJob: 10 tests for order expiration, error handling, logging
  - CleanupExpiredDraftsJob: 8 tests for ticket cleanup logic

## Test Infrastructure:
- Added rails-controller-testing gem for assigns() and assert_template
- Added mocha gem for mocking and stubbing
- Enhanced test_helper.rb with Devise integration helpers
- Fixed existing failing ticket test for QR code generation

## Test Statistics:
- **Total**: 202 tests, 338 assertions
- **Core Models/Controllers**: All major functionality tested
- **Services**: Comprehensive mocking of Stripe integration
- **Jobs**: Full workflow testing with error scenarios
- **Coverage**: Critical business logic, validations, associations, and user flows

Some advanced integration scenarios may need refinement but core application functionality is thoroughly tested.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-05 13:39:20 +02:00

64 lines
1.5 KiB
Ruby

require "test_helper"
class TicketsControllerTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
setup 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
)
@order = Order.create!(
user: @user,
event: @event,
total_amount_cents: 1000
)
@ticket = Ticket.create!(
order: @order,
ticket_type: TicketType.create!(
name: "Test Ticket",
description: "Valid description for the ticket type that is long enough",
price_cents: 1000,
quantity: 50,
sale_start_at: Time.current,
sale_end_at: Time.current + 1.day,
requires_id: false,
event: @event
),
first_name: "Test",
last_name: "User",
qr_code: "test-qr-code"
)
sign_in @user
end
test "should redirect to checkout" do
get ticket_checkout_path(@event.slug, @event)
assert_response :redirect
end
test "should get payment success" do
get payment_success_path(session_id: "test_session")
assert_response :redirect
end
test "should get payment cancel" do
get payment_cancel_path
assert_response :redirect
end
end