mirror of
https://github.com/mastodon/mastodon.git
synced 2025-11-28 02:20:47 +00:00
Update specs
This commit is contained in:
parent
891faa5d74
commit
b348ca25c4
|
|
@ -54,17 +54,22 @@ class ReportFilter
|
||||||
def updated_filter
|
def updated_filter
|
||||||
updated_params = @params.to_hash
|
updated_params = @params.to_hash
|
||||||
|
|
||||||
resolved = updated_params.delete('resolved')
|
|
||||||
status_filter = if resolved.present?
|
|
||||||
resolved == '1' ? 'resolved' : 'unresolved'
|
|
||||||
else
|
|
||||||
'all'
|
|
||||||
end
|
|
||||||
|
|
||||||
# Old parameters:
|
# Old parameters:
|
||||||
by_target_domain = updated_params.delete('by_target_domain')
|
by_target_domain = updated_params.delete('by_target_domain')
|
||||||
account_id = updated_params.delete('account_id')
|
account_id = updated_params.delete('account_id')
|
||||||
target_account_id = updated_params.delete('target_account_id')
|
target_account_id = updated_params.delete('target_account_id')
|
||||||
|
resolved = updated_params.delete('resolved')
|
||||||
|
existing_status = updated_params.delete('status')
|
||||||
|
|
||||||
|
status_filter = if existing_status
|
||||||
|
existing_status
|
||||||
|
elsif resolved.present?
|
||||||
|
resolved == '1' ? 'resolved' : 'unresolved'
|
||||||
|
elsif by_target_domain || target_account_id || account_id
|
||||||
|
'all'
|
||||||
|
else
|
||||||
|
'unresolved'
|
||||||
|
end
|
||||||
|
|
||||||
updated_params['status'] = status_filter
|
updated_params['status'] = status_filter
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
require 'debug'
|
||||||
|
|
||||||
describe Admin::ReportsController do
|
RSpec.describe Admin::ReportsController do
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||||
|
|
@ -27,10 +28,11 @@ describe Admin::ReportsController do
|
||||||
|
|
||||||
get :index, params: { status: 'unresolved' }
|
get :index, params: { status: 'unresolved' }
|
||||||
|
|
||||||
reports = assigns(:reports).to_a
|
|
||||||
expect(reports.size).to eq 1
|
|
||||||
expect(reports[0]).to eq specified
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
|
|
||||||
|
expect(report_groups.size).to eq 1
|
||||||
|
expect(report_groups[0][:reports].size).to eq 1
|
||||||
|
expect(report_groups[0][:reports][0][:link]).to include specified.id.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success with status filter of resolved' do
|
it 'returns http success with status filter of resolved' do
|
||||||
|
|
@ -39,43 +41,61 @@ describe Admin::ReportsController do
|
||||||
|
|
||||||
get :index, params: { status: 'resolved' }
|
get :index, params: { status: 'resolved' }
|
||||||
|
|
||||||
reports = assigns(:reports).to_a
|
|
||||||
expect(reports.size).to eq 1
|
|
||||||
expect(reports[0]).to eq specified
|
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
|
|
||||||
|
expect(report_groups.size).to eq 1
|
||||||
|
expect(report_groups[0][:reports].size).to eq 1
|
||||||
|
expect(report_groups[0][:reports][0][:link]).to include specified.id.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success with status filter of all' do
|
it 'returns http success with status filter of all' do
|
||||||
resolved = Fabricate(:report, action_taken_at: Time.now.utc)
|
targeted_account = Fabricate(:account)
|
||||||
unresolved = Fabricate(:report, action_taken_at: nil)
|
resolved = Fabricate(:report, target_account: targeted_account, action_taken_at: Time.now.utc)
|
||||||
|
unresolved = Fabricate(:report, target_account: targeted_account, action_taken_at: nil)
|
||||||
|
|
||||||
get :index, params: { status: 'all' }
|
get :index, params: { status: 'all' }
|
||||||
|
|
||||||
reports = assigns(:reports).to_a
|
|
||||||
expect(reports.size).to eq 2
|
|
||||||
|
|
||||||
# unresolved is the most recently created report, so it's first:
|
|
||||||
expect(reports[0]).to eq unresolved
|
|
||||||
expect(reports[1]).to eq resolved
|
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
|
|
||||||
|
expect(report_groups.size).to eq 1
|
||||||
|
expect(report_groups[0][:target_account_link]).to include targeted_account.id.to_s
|
||||||
|
expect(report_groups[0][:reports].size).to eq 2
|
||||||
|
expect(report_groups[0][:reports][0][:link]).to include unresolved.id.to_s
|
||||||
|
expect(report_groups[0][:reports][1][:link]).to include resolved.id.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success with target_account_id filter' do
|
it 'returns the correct results with a search filter about an account' do
|
||||||
targeted_account = Fabricate(:account)
|
targeted_account = Fabricate(:account)
|
||||||
not_targeted_account = Fabricate(:account)
|
not_targeted_account = Fabricate(:account)
|
||||||
|
|
||||||
targeted = Fabricate(:report, action_taken_at: nil, target_account: targeted_account)
|
targeted = Fabricate(:report, action_taken_at: nil, target_account: targeted_account)
|
||||||
Fabricate(:report, action_taken_at: nil, target_account: not_targeted_account)
|
Fabricate(:report, action_taken_at: nil, target_account: not_targeted_account)
|
||||||
|
|
||||||
get :index, params: { target_account_id: targeted_account.id }
|
get :index, params: { search_type: 'target', search_term: "@#{targeted_account.acct}", status: 'all' }
|
||||||
|
|
||||||
reports = assigns(:reports).to_a
|
|
||||||
expect(reports.size).to eq 1
|
|
||||||
expect(reports[0]).to eq targeted
|
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
|
|
||||||
|
expect(report_groups.size).to eq 1
|
||||||
|
expect(report_groups[0][:target_account_link]).to include targeted_account.id.to_s
|
||||||
|
expect(report_groups[0][:reports].size).to eq 1
|
||||||
|
expect(report_groups[0][:reports][0][:link]).to include targeted.id.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def report_groups
|
||||||
|
response.parsed_body.css('.report-card').map do |card|
|
||||||
|
target_account_link = card.css('.report-card__profile a.account__display-name').attr('href').value
|
||||||
|
reports = card.css('.report-card__summary__item').map do |report|
|
||||||
|
{
|
||||||
|
reported_by: report.css('.report-card__summary__item__reported-by').first.text.strip,
|
||||||
|
link: report.css('.report-card__summary__item__content > a').attr('href').value,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
{
|
||||||
|
target_account_link: target_account_link,
|
||||||
|
reports: reports,
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'outdated filters' do
|
describe 'outdated filters' do
|
||||||
|
|
@ -85,14 +105,14 @@ describe Admin::ReportsController do
|
||||||
get :index, params: { by_target_domain: 'social.example' }
|
get :index, params: { by_target_domain: 'social.example' }
|
||||||
|
|
||||||
expect(response)
|
expect(response)
|
||||||
.to redirect_to admin_reports_path({ search_type: 'target', search_term: 'social.example', status: 'unresolved' })
|
.to redirect_to admin_reports_path({ search_type: 'target', search_term: 'social.example', status: 'all' })
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects if resolved is used' do
|
it 'redirects if resolved is used' do
|
||||||
get :index, params: { resolved: '1' }
|
get :index, params: { resolved: '1' }
|
||||||
|
|
||||||
expect(response)
|
expect(response)
|
||||||
.to redirect_to admin_reports_path({ search_type: 'target', search_term: nil, status: 'resolved' })
|
.to redirect_to admin_reports_path({ status: 'resolved' })
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects if resolved and by_target_domain are used' do
|
it 'redirects if resolved and by_target_domain are used' do
|
||||||
|
|
@ -104,6 +124,38 @@ describe Admin::ReportsController do
|
||||||
status: 'resolved',
|
status: 'resolved',
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'redirects if resolved is false and by_target_domain is used' do
|
||||||
|
get :index, params: { resolved: '0', by_target_domain: 'social.example' }
|
||||||
|
|
||||||
|
expect(response).to redirect_to admin_reports_path({
|
||||||
|
search_type: 'target',
|
||||||
|
search_term: 'social.example',
|
||||||
|
status: 'unresolved',
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects if target_account_id filter is used' do
|
||||||
|
account = Fabricate(:account)
|
||||||
|
get :index, params: { target_account_id: account.id }
|
||||||
|
|
||||||
|
expect(response).to redirect_to admin_reports_path({
|
||||||
|
search_type: 'target',
|
||||||
|
search_term: "@#{account.acct}",
|
||||||
|
status: 'all',
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects if account_id filter is used' do
|
||||||
|
account = Fabricate(:account)
|
||||||
|
get :index, params: { account_id: account.id }
|
||||||
|
|
||||||
|
expect(response).to redirect_to admin_reports_path({
|
||||||
|
search_type: 'source',
|
||||||
|
search_term: "@#{account.acct}",
|
||||||
|
status: 'all',
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -113,8 +165,8 @@ describe Admin::ReportsController do
|
||||||
|
|
||||||
get :show, params: { id: report }
|
get :show, params: { id: report }
|
||||||
|
|
||||||
expect(assigns(:report)).to eq report
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
|
expect(response.body).to include(report.target_account.acct)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user