Use the `Admin::ActionLog` fabricator in admin/action_logs spec (#28194)

This commit is contained in:
Matt Jankowski 2023-12-04 07:56:28 -05:00 committed by GitHub
parent b3b009e6aa
commit cca19f5fbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 34 deletions

View File

@ -161,12 +161,13 @@ RSpec.describe Admin::AccountsController do
it 'logs action' do it 'logs action' do
expect(subject).to have_http_status 302 expect(subject).to have_http_status 302
log_item = Admin::ActionLog.last expect(latest_admin_action_log)
.to be_present
expect(log_item).to_not be_nil .and have_attributes(
expect(log_item.action).to eq :approve action: eq(:approve),
expect(log_item.account_id).to eq current_user.account_id account_id: eq(current_user.account_id),
expect(log_item.target_id).to eq account.user.id target_id: eq(account.user.id)
)
end end
end end
@ -201,12 +202,13 @@ RSpec.describe Admin::AccountsController do
it 'logs action' do it 'logs action' do
expect(subject).to have_http_status 302 expect(subject).to have_http_status 302
log_item = Admin::ActionLog.last expect(latest_admin_action_log)
.to be_present
expect(log_item).to_not be_nil .and have_attributes(
expect(log_item.action).to eq :reject action: eq(:reject),
expect(log_item.account_id).to eq current_user.account_id account_id: eq(current_user.account_id),
expect(log_item.target_id).to eq account.user.id target_id: eq(account.user.id)
)
end end
end end
@ -427,4 +429,10 @@ RSpec.describe Admin::AccountsController do
end end
end end
end end
private
def latest_admin_action_log
Admin::ActionLog.last
end
end end

View File

@ -9,11 +9,9 @@ describe Admin::ActionLogsController do
let!(:account) { Fabricate(:account) } let!(:account) { Fabricate(:account) }
before do before do
_orphaned_logs = %w( orphaned_log_types.map do |type|
Account User UserRole Report DomainBlock DomainAllow Fabricate(:action_log, account: account, action: 'destroy', target_type: type, target_id: 1312)
EmailDomainBlock UnavailableDomain Status AccountWarning end
Announcement IpBlock Instance CustomEmoji CanonicalEmailBlock Appeal
).map { |type| Admin::ActionLog.new(account: account, action: 'destroy', target_type: type, target_id: 1312).save! }
end end
describe 'GET #index' do describe 'GET #index' do
@ -24,4 +22,27 @@ describe Admin::ActionLogsController do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
end end
private
def orphaned_log_types
%w(
Account
AccountWarning
Announcement
Appeal
CanonicalEmailBlock
CustomEmoji
DomainAllow
DomainBlock
EmailDomainBlock
Instance
IpBlock
Report
Status
UnavailableDomain
User
UserRole
)
end
end end

View File

@ -21,12 +21,19 @@ RSpec.describe 'Account actions' do
it 'logs action' do it 'logs action' do
subject subject
log_item = Admin::ActionLog.last expect(latest_admin_action_log)
.to be_present
.and have_attributes(
action: eq(action_type),
account_id: eq(user.account_id),
target_id: eq(target_type == :user ? target_account.user.id : target_account.id)
)
end
expect(log_item).to be_present private
expect(log_item.action).to eq(action_type)
expect(log_item.account_id).to eq(user.account_id) def latest_admin_action_log
expect(log_item.target_id).to eq(target_type == :user ? target_account.user.id : target_account.id) Admin::ActionLog.last
end end
end end

View File

@ -151,12 +151,13 @@ RSpec.describe 'Accounts' do
it 'logs action', :aggregate_failures do it 'logs action', :aggregate_failures do
subject subject
log_item = Admin::ActionLog.last expect(latest_admin_action_log)
.to be_present
expect(log_item).to be_present .and have_attributes(
expect(log_item.action).to eq :approve action: eq(:approve),
expect(log_item.account_id).to eq user.account_id account_id: eq(user.account_id),
expect(log_item.target_id).to eq account.user.id target_id: eq(account.user.id)
)
end end
end end
@ -202,12 +203,13 @@ RSpec.describe 'Accounts' do
it 'logs action', :aggregate_failures do it 'logs action', :aggregate_failures do
subject subject
log_item = Admin::ActionLog.last expect(latest_admin_action_log)
.to be_present
expect(log_item).to be_present .and have_attributes(
expect(log_item.action).to eq :reject action: eq(:reject),
expect(log_item.account_id).to eq user.account_id account_id: eq(user.account_id),
expect(log_item.target_id).to eq account.user.id target_id: eq(account.user.id)
)
end end
end end
@ -398,4 +400,10 @@ RSpec.describe 'Accounts' do
end end
end end
end end
private
def latest_admin_action_log
Admin::ActionLog.last
end
end end