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.
This commit is contained in:
Jorge Manrubia
2025-12-15 14:49:47 +01:00
parent 725e850802
commit 3ef5e4eeef
19 changed files with 196 additions and 80 deletions
@@ -1,10 +1,6 @@
require "test_helper"
class Admin::AccountsControllerTest < ActionDispatch::IntegrationTest
def saas
Fizzy::Saas::Engine.routes.url_helpers
end
test "staff can access index" do
sign_in_as :david
@@ -34,15 +30,15 @@ class Admin::AccountsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
test "staff can update cards_count" do
test "staff can override card count" do
sign_in_as :david
untenanted do
patch saas.admin_account_path(accounts(:"37s").external_account_id), params: { account: { cards_count: 500 } }
patch saas.admin_account_path(accounts(:"37s").external_account_id), params: { account: { overridden_card_count: 500 } }
assert_redirected_to saas.edit_admin_account_path(accounts(:"37s").external_account_id)
end
assert_equal 500, accounts(:"37s").reload.cards_count
assert_equal 500, accounts(:"37s").reload.billed_cards_count
end
test "non-staff cannot access accounts" do
@@ -0,0 +1,22 @@
require "test_helper"
class Admin::OverriddenLimitsControllerTest < ActionDispatch::IntegrationTest
test "staff can reset overridden limits" do
sign_in_as :david
account = accounts(:"37s")
# First set an override
account.override_limits(card_count: 500)
assert_equal 500, account.reload.billed_cards_count
# Then reset it
untenanted do
delete saas.admin_account_overridden_limits_path(account.external_account_id)
assert_redirected_to saas.edit_admin_account_path(account.external_account_id)
end
# Verify override was removed
assert_nil account.reload.overridden_limits
assert_equal account.cards_count, account.billed_cards_count
end
end
@@ -1,10 +1,6 @@
require "test_helper"
class Admin::StatsControllerTest < ActionDispatch::IntegrationTest
def saas
Fizzy::Saas::Engine.routes.url_helpers
end
test "staff can access stats" do
sign_in_as :david