feat: Add promotion code functionality to ticket orders
This commit is contained in:
66
test/controllers/orders_controller_promotion_test.rb
Normal file
66
test/controllers/orders_controller_promotion_test.rb
Normal 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
|
||||
Reference in New Issue
Block a user