mirror of
https://github.com/mastodon/mastodon.git
synced 2025-01-08 19:35:11 +01:00
Convert admin/report_notes
spec controller->system (#33433)
This commit is contained in:
parent
a557f9bbaa
commit
1fbd106af9
@ -1,104 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::ReportNotesController do
|
||||
render_views
|
||||
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
before do
|
||||
sign_in user, scope: :user
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
subject { post :create, params: params }
|
||||
|
||||
let(:report) { Fabricate(:report, action_taken_at: action_taken, action_taken_by_account_id: account_id) }
|
||||
|
||||
context 'when parameter is valid' do
|
||||
context 'when report is unsolved' do
|
||||
let(:action_taken) { nil }
|
||||
let(:account_id) { nil }
|
||||
|
||||
context 'when create_and_resolve flag is on' do
|
||||
let(:params) { { report_note: { report_id: report.id, content: 'test content' }, create_and_resolve: nil } }
|
||||
|
||||
it 'creates a report note and resolves report' do
|
||||
expect { subject }.to change(ReportNote, :count).by(1)
|
||||
expect(report.reload).to be_action_taken
|
||||
expect(response).to redirect_to admin_reports_path
|
||||
end
|
||||
end
|
||||
|
||||
context 'when create_and_resolve flag is false' do
|
||||
let(:params) { { report_note: { report_id: report.id, content: 'test content' } } }
|
||||
|
||||
it 'creates a report note and does not resolve report' do
|
||||
expect { subject }.to change(ReportNote, :count).by(1)
|
||||
expect(report.reload).to_not be_action_taken
|
||||
expect(response).to redirect_to admin_report_path(report)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when report is resolved' do
|
||||
let(:action_taken) { Time.now.utc }
|
||||
let(:account_id) { user.account.id }
|
||||
|
||||
context 'when create_and_unresolve flag is on' do
|
||||
let(:params) { { report_note: { report_id: report.id, content: 'test content' }, create_and_unresolve: nil } }
|
||||
|
||||
it 'creates a report note and unresolves report' do
|
||||
expect { subject }.to change(ReportNote, :count).by(1)
|
||||
expect(report.reload).to_not be_action_taken
|
||||
expect(response).to redirect_to admin_report_path(report)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when create_and_unresolve flag is false' do
|
||||
let(:params) { { report_note: { report_id: report.id, content: 'test content' } } }
|
||||
|
||||
it 'creates a report note and does not unresolve report' do
|
||||
expect { subject }.to change(ReportNote, :count).by(1)
|
||||
expect(report.reload).to be_action_taken
|
||||
expect(response).to redirect_to admin_report_path(report)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when content is too short' do
|
||||
let(:params) { { report_note: { report_id: report.id, content: '' } } }
|
||||
let(:action_taken) { nil }
|
||||
let(:account_id) { nil }
|
||||
|
||||
it 'renders admin/reports/show' do
|
||||
expect { subject }.to_not change(ReportNote, :count)
|
||||
expect(subject).to render_template 'admin/reports/show'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when content is too long' do
|
||||
let(:params) { { report_note: { report_id: report.id, content: 'test' * ReportNote::CONTENT_SIZE_LIMIT } } }
|
||||
let(:action_taken) { nil }
|
||||
let(:account_id) { nil }
|
||||
|
||||
it 'renders admin/reports/show' do
|
||||
expect { subject }.to_not change(ReportNote, :count)
|
||||
expect(subject).to render_template 'admin/reports/show'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
subject { delete :destroy, params: { id: report_note.id } }
|
||||
|
||||
let!(:report_note) { Fabricate(:report_note) }
|
||||
|
||||
it 'deletes note' do
|
||||
expect { subject }.to change(ReportNote, :count).by(-1)
|
||||
expect(response).to redirect_to admin_report_path(report_note.report)
|
||||
end
|
||||
end
|
||||
end
|
130
spec/system/admin/report_notes_spec.rb
Normal file
130
spec/system/admin/report_notes_spec.rb
Normal file
@ -0,0 +1,130 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Admin Report Notes' do
|
||||
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||
|
||||
before { sign_in user }
|
||||
|
||||
describe 'Creating notes' do
|
||||
context 'when report is unresolved' do
|
||||
let(:report) { Fabricate(:report, action_taken_at: nil, action_taken_by_account_id: nil) }
|
||||
|
||||
context 'when resolve is selected' do
|
||||
it 'creates a report note and resolves report' do
|
||||
visit admin_report_path(report)
|
||||
|
||||
fill_in 'report_note_content', with: 'Report note text'
|
||||
expect { submit_form }
|
||||
.to change(ReportNote, :count).by(1)
|
||||
expect(report.reload)
|
||||
.to be_action_taken
|
||||
expect(page)
|
||||
.to have_content(success_message)
|
||||
end
|
||||
|
||||
def submit_form
|
||||
click_on I18n.t('admin.reports.notes.create_and_resolve')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when resolve is not selected' do
|
||||
it 'creates a report note and does not resolve report' do
|
||||
visit admin_report_path(report)
|
||||
|
||||
fill_in 'report_note_content', with: 'Report note text'
|
||||
expect { submit_form }
|
||||
.to change(ReportNote, :count).by(1)
|
||||
expect(report.reload)
|
||||
.to_not be_action_taken
|
||||
expect(page)
|
||||
.to have_content(success_message)
|
||||
end
|
||||
|
||||
def submit_form
|
||||
click_on I18n.t('admin.reports.notes.create')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when report is resolved' do
|
||||
let(:report) { Fabricate(:report, action_taken_at: Time.current, action_taken_by_account_id: user.account.id) }
|
||||
|
||||
context 'when create_and_unresolve flag is on' do
|
||||
it 'creates a report note and unresolves report' do
|
||||
visit admin_report_path(report)
|
||||
|
||||
fill_in 'report_note_content', with: 'Report note text'
|
||||
expect { submit_form }
|
||||
.to change(ReportNote, :count).by(1)
|
||||
expect(report.reload)
|
||||
.to_not be_action_taken
|
||||
expect(page)
|
||||
.to have_content(success_message)
|
||||
end
|
||||
|
||||
def submit_form
|
||||
click_on I18n.t('admin.reports.notes.create_and_unresolve')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when create_and_unresolve flag is false' do
|
||||
it 'creates a report note and does not unresolve report' do
|
||||
visit admin_report_path(report)
|
||||
|
||||
fill_in 'report_note_content', with: 'Report note text'
|
||||
expect { submit_form }
|
||||
.to change(ReportNote, :count).by(1)
|
||||
expect(report.reload)
|
||||
.to be_action_taken
|
||||
expect(page)
|
||||
.to have_content(success_message)
|
||||
end
|
||||
|
||||
def submit_form
|
||||
click_on I18n.t('admin.reports.notes.create')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when content is not valid' do
|
||||
let(:report) { Fabricate(:report) }
|
||||
|
||||
it 'does not create a note' do
|
||||
visit admin_report_path(report)
|
||||
|
||||
fill_in 'report_note_content', with: ''
|
||||
expect { submit_form }
|
||||
.to_not change(ReportNote, :count)
|
||||
expect(page)
|
||||
.to have_content(/error below/)
|
||||
end
|
||||
|
||||
def submit_form
|
||||
click_on I18n.t('admin.reports.notes.create')
|
||||
end
|
||||
end
|
||||
|
||||
def success_message
|
||||
I18n.t('admin.report_notes.created_msg')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Removing notes' do
|
||||
let!(:report_note) { Fabricate(:report_note) }
|
||||
|
||||
it 'deletes note' do
|
||||
visit admin_report_path(report_note.report)
|
||||
|
||||
expect { delete_note }
|
||||
.to change(ReportNote, :count).by(-1)
|
||||
expect(page)
|
||||
.to have_content(I18n.t('admin.report_notes.destroyed_msg'))
|
||||
end
|
||||
|
||||
def delete_note
|
||||
click_on I18n.t('admin.reports.notes.delete')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user