Files
fizzy/saas/test/models/account/limited_test.rb
T
Jorge Manrubia 3ef5e4eeef Add record to track overridden limits
Before, we were relying on just changing the cards_count in account, but this
could create problems where the system to calculate the next card number fails due
to the unique constraint.
2025-12-16 12:00:23 +01:00

52 lines
1.7 KiB
Ruby

require "test_helper"
class Account::LimitedTest < ActiveSupport::TestCase
test "detect nearing card limit" do
# Paid plans are never limited
accounts(:"37s").update_column(:cards_count, 1_000_000)
assert_not accounts(:"37s").nearing_plan_cards_limit?
# Free plan not near limit
accounts(:initech).update_column(:cards_count, 899)
assert_not accounts(:initech).nearing_plan_cards_limit?
# Free plan near limit
accounts(:initech).update_column(:cards_count, 900)
assert_not accounts(:initech).nearing_plan_cards_limit?
accounts(:initech).update_column(:cards_count, 901)
assert accounts(:initech).nearing_plan_cards_limit?
end
test "detect exceeding card limit" do
# Paid plans are never limited
accounts(:"37s").update_column(:cards_count, 1_000_000)
assert_not accounts(:"37s").exceeding_card_limit?
# Free plan under limit
accounts(:initech).update_column(:cards_count, 999)
assert_not accounts(:initech).exceeding_card_limit?
# Free plan over limit
accounts(:initech).update_column(:cards_count, 1001)
assert accounts(:initech).exceeding_card_limit?
end
test "override limits" do
account = accounts(:initech)
account.update_column(:cards_count, 1001)
assert account.exceeding_card_limit?
assert_equal 1001, account.billed_cards_count
account.override_limits card_count: 500
assert_not account.exceeding_card_limit?
assert_equal 500, account.billed_cards_count
assert_equal 1001, account.cards_count # original unchanged
account.reset_overridden_limits
assert account.exceeding_card_limit?
assert_equal 1001, account.billed_cards_count
end
end