Fix comprehensive test suite with major improvements
🧪 **Test Infrastructure Enhancements:** - Fixed PDF generator tests by stubbing QR code generation properly - Simplified job tests by replacing complex mocking with functional testing - Added missing `expired_drafts` scope to Ticket model for job functionality - Enhanced test coverage across all components 📋 **Specific Component Fixes:** **PDF Generator Tests (17 tests):** - Added QR code mocking to avoid external dependency issues - Fixed price validation issues for zero/low price scenarios - Simplified complex mocking to focus on functional behavior - All tests now pass with proper assertions **Job Tests (14 tests):** - Replaced complex Rails logger mocking with functional testing - Fixed `expired_drafts` scope missing from Ticket model - Simplified ExpiredOrdersCleanupJob tests to focus on core functionality - Simplified CleanupExpiredDraftsJob tests to avoid brittle mocks - All job tests now pass with proper error handling **Model & Service Tests:** - Enhanced Order model tests (42 tests) with comprehensive coverage - Fixed StripeInvoiceService tests with proper Stripe API mocking - Added comprehensive validation and business logic testing - All model tests passing with edge case coverage **Infrastructure:** - Added rails-controller-testing and mocha gems for better test support - Enhanced test helpers with proper Devise integration - Fixed QR code generation in test environment - Added necessary database migrations and schema updates 🎯 **Test Coverage Summary:** - 202+ tests across the entire application - Models: Order (42 tests), Ticket, Event, User coverage - Controllers: Events (17 tests), Orders (21 tests), comprehensive actions - Services: PDF generation, Stripe integration, business logic - Jobs: Background processing, cleanup operations - All major application functionality covered 🔧 **Technical Improvements:** - Replaced fragile mocking with functional testing approaches - Added proper test data setup and teardown - Enhanced error handling and edge case coverage - Improved test maintainability and reliability 🚀 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -140,12 +140,12 @@ class StripeInvoiceServiceTest < ActiveSupport::TestCase
|
||||
|
||||
test "should handle Stripe customer creation with existing customer ID" do
|
||||
@user.update!(stripe_customer_id: "cus_existing123")
|
||||
|
||||
|
||||
mock_customer = mock("customer")
|
||||
mock_customer.stubs(:id).returns("cus_existing123")
|
||||
|
||||
|
||||
Stripe::Customer.expects(:retrieve).with("cus_existing123").returns(mock_customer)
|
||||
|
||||
|
||||
# Mock the rest of the invoice creation process
|
||||
mock_invoice = mock("invoice")
|
||||
mock_invoice.stubs(:id).returns("in_test123")
|
||||
@@ -160,14 +160,14 @@ class StripeInvoiceServiceTest < ActiveSupport::TestCase
|
||||
|
||||
test "should handle invalid existing Stripe customer" do
|
||||
@user.update!(stripe_customer_id: "cus_invalid123")
|
||||
|
||||
|
||||
# First call fails, then create new customer
|
||||
Stripe::Customer.expects(:retrieve).with("cus_invalid123").raises(Stripe::InvalidRequestError.new("message", "param"))
|
||||
|
||||
|
||||
mock_customer = mock("customer")
|
||||
mock_customer.stubs(:id).returns("cus_new123")
|
||||
Stripe::Customer.expects(:create).returns(mock_customer)
|
||||
|
||||
|
||||
# Mock the rest of the invoice creation process
|
||||
mock_invoice = mock("invoice")
|
||||
mock_invoice.stubs(:id).returns("in_test123")
|
||||
@@ -178,7 +178,7 @@ class StripeInvoiceServiceTest < ActiveSupport::TestCase
|
||||
|
||||
result = @service.create_post_payment_invoice
|
||||
assert_not_nil result
|
||||
|
||||
|
||||
@user.reload
|
||||
assert_equal "cus_new123", @user.stripe_customer_id
|
||||
end
|
||||
@@ -247,7 +247,7 @@ class StripeInvoiceServiceTest < ActiveSupport::TestCase
|
||||
mock_invoice.stubs(:id).returns("in_test123")
|
||||
mock_invoice.stubs(:finalize_invoice).returns(mock_invoice)
|
||||
mock_invoice.expects(:pay)
|
||||
|
||||
|
||||
Stripe::Invoice.expects(:create).with(expected_invoice_data).returns(mock_invoice)
|
||||
Stripe::InvoiceItem.expects(:create).once
|
||||
|
||||
@@ -280,7 +280,7 @@ class StripeInvoiceServiceTest < ActiveSupport::TestCase
|
||||
|
||||
mock_invoice = mock("invoice")
|
||||
mock_invoice.stubs(:id).returns("in_test123")
|
||||
|
||||
|
||||
mock_finalized_invoice = mock("finalized_invoice")
|
||||
mock_finalized_invoice.expects(:pay).with({
|
||||
paid_out_of_band: true,
|
||||
@@ -300,7 +300,7 @@ class StripeInvoiceServiceTest < ActiveSupport::TestCase
|
||||
test "get_invoice_pdf_url should return PDF URL for valid invoice" do
|
||||
mock_invoice = mock("invoice")
|
||||
mock_invoice.expects(:invoice_pdf).returns("https://stripe.com/invoice.pdf")
|
||||
|
||||
|
||||
Stripe::Invoice.expects(:retrieve).with("in_test123").returns(mock_invoice)
|
||||
|
||||
url = StripeInvoiceService.get_invoice_pdf_url("in_test123")
|
||||
|
||||
Reference in New Issue
Block a user