1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 07:39:39 +02:00

Feat: Data "reset" button (#1913)

* feat: Allow admins to delete family data

* feat: Allow self-hosting users to delete cached data

* Remove system tests
This commit is contained in:
Tony Vincent 2025-02-28 13:49:12 +01:00 committed by GitHub
parent f7064fd4dd
commit 8208722247
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 206 additions and 16 deletions

View file

@ -45,4 +45,39 @@ class Settings::HostingsControllerTest < ActionDispatch::IntegrationTest
assert_equal NEW_RENDER_DEPLOY_HOOK, Setting.render_deploy_hook
end
end
test "can clear data cache when self hosting is enabled" do
account = accounts(:investment)
holding = account.holdings.first
exchange_rate = exchange_rates(:one)
security_price = holding.security.prices.first
account_balance = account.balances.create!(date: Date.current, balance: 1000, currency: "USD")
with_self_hosting do
perform_enqueued_jobs(only: DataCacheClearJob) do
delete clear_cache_settings_hosting_url
end
end
assert_redirected_to settings_hosting_url
assert_equal I18n.t("settings.hostings.clear_cache.cache_cleared"), flash[:notice]
assert_not ExchangeRate.exists?(exchange_rate.id)
assert_not Security::Price.exists?(security_price.id)
assert_not Account::Holding.exists?(holding.id)
assert_not Account::Balance.exists?(account_balance.id)
end
test "can clear data only when admin" do
with_self_hosting do
sign_in users(:family_member)
assert_no_enqueued_jobs do
delete clear_cache_settings_hosting_url
end
assert_redirected_to settings_hosting_url
assert_equal I18n.t("settings.hostings.not_authorized"), flash[:alert]
end
end
end

View file

@ -31,6 +31,41 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
assert_equal "Your profile has been updated.", flash[:notice]
end
test "admin can reset family data" do
account = accounts(:investment)
category = categories(:income)
tag = tags(:one)
merchant = merchants(:netflix)
import = imports(:transaction)
budget = budgets(:one)
plaid_item = plaid_items(:one)
perform_enqueued_jobs(only: FamilyResetJob) do
delete reset_user_url(@user)
end
assert_redirected_to settings_profile_url
assert_equal I18n.t("users.reset.success"), flash[:notice]
assert_not Account.exists?(account.id)
assert_not Category.exists?(category.id)
assert_not Tag.exists?(tag.id)
assert_not Merchant.exists?(merchant.id)
assert_not Import.exists?(import.id)
assert_not Budget.exists?(budget.id)
assert_not PlaidItem.exists?(plaid_item.id)
end
test "non-admin cannot reset family data" do
sign_in @member = users(:family_member)
delete reset_user_url(@member)
assert_redirected_to settings_profile_url
assert_equal I18n.t("users.reset.unauthorized"), flash[:alert]
assert_no_enqueued_jobs only: FamilyResetJob
end
test "member can deactivate their account" do
sign_in @member = users(:family_member)
delete user_url(@member)