feat: Add promotion code functionality to ticket orders

This commit is contained in:
kbe
2025-09-28 20:20:22 +02:00
parent e5ed1a34dd
commit a69ddb4012
10 changed files with 258 additions and 22 deletions

View File

@@ -0,0 +1,66 @@
require "test_helper"
class OrdersControllerPromotionTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
# Setup test data
def setup
@user = users(:one)
@event = events(:one)
@order = orders(:one)
sign_in @user
end
# Test applying a valid promotion code
def test_apply_valid_promotion_code
promotion_code = PromotionCode.create(
code: "TESTDISCOUNT",
discount_amount_cents: 1000, # €10.00
expires_at: 1.month.from_now,
active: true
)
get checkout_order_path(@order), params: { promotion_code: "TESTDISCOUNT" }
assert_response :success
assert_not_nil flash[:notice]
assert_match /Code promotionnel appliqué: TESTDISCOUNT/, flash[:notice]
end
# Test applying an invalid promotion code
def test_apply_invalid_promotion_code
get checkout_order_path(@order), params: { promotion_code: "INVALIDCODE" }
assert_response :success
assert_not_nil flash[:alert]
assert_equal "Code promotionnel invalide", flash[:alert]
end
# Test applying an expired promotion code
def test_apply_expired_promotion_code
promotion_code = PromotionCode.create(
code: "EXPIREDCODE",
discount_amount_cents: 1000,
expires_at: 1.day.ago,
active: true
)
get checkout_order_path(@order), params: { promotion_code: "EXPIREDCODE" }
assert_response :success
assert_not_nil flash[:alert]
assert_equal "Code promotionnel invalide", flash[:alert]
end
# Test applying an inactive promotion code
def test_apply_inactive_promotion_code
promotion_code = PromotionCode.create(
code: "INACTIVECODE",
discount_amount_cents: 1000,
expires_at: 1.month.from_now,
active: false
)
get checkout_order_path(@order), params: { promotion_code: "INACTIVECODE" }
assert_response :success
assert_not_nil flash[:alert]
assert_equal "Code promotionnel invalide", flash[:alert]
end
end