feat: allow superadmins to reset cache keys for IndexedDB (#7180)
Allows super admins to reset the cache for an account. This will force the front end to fetch the data again on the next load. fixes: https://linear.app/chatwoot/issue/CW-1817 Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
@@ -15,8 +15,6 @@ RSpec.describe 'Super Admin accounts API', type: :request do
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let!(:account) { create(:account) }
|
||||
|
||||
it 'shows the list of accounts' do
|
||||
sign_in(super_admin, scope: :super_admin)
|
||||
get '/super_admin/accounts'
|
||||
@@ -27,6 +25,32 @@ RSpec.describe 'Super Admin accounts API', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /super_admin/accounts/{account_id}/reset_cache' do
|
||||
before do
|
||||
create(:label, account: account)
|
||||
create(:inbox, account: account)
|
||||
create(:team, account: account)
|
||||
end
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post "/super_admin/accounts/#{account.id}/reset_cache"
|
||||
expect(response).to have_http_status(:redirect)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
it 'shows the list of accounts' do
|
||||
expect(account.cache_keys.keys).to contain_exactly(:inbox, :label, :team)
|
||||
sign_in(super_admin, scope: :super_admin)
|
||||
post "/super_admin/accounts/#{account.id}/reset_cache"
|
||||
expect(response).to have_http_status(:redirect)
|
||||
expect(flash[:notice]).to eq('Cache keys cleared')
|
||||
expect(account.reload.cache_keys.values.map(&:to_i)).to eq([0, 0, 0])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE /super_admin/accounts/{account_id}' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
|
||||
Reference in New Issue
Block a user