2023-02-22 09:55:31 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-22 21:45:10 +09:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Admin::ReportNotesController do
|
|
|
|
render_views
|
|
|
|
|
2022-07-05 09:41:40 +09:00
|
|
|
let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
2018-05-22 21:45:10 +09:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user, scope: :user
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #create' do
|
|
|
|
subject { post :create, params: params }
|
|
|
|
|
2022-01-17 17:41:33 +09:00
|
|
|
let(:report) { Fabricate(:report, action_taken_at: action_taken, action_taken_by_account_id: account_id) }
|
2018-05-22 21:45:10 +09:00
|
|
|
|
|
|
|
context 'when parameter is valid' do
|
|
|
|
context 'when report is unsolved' do
|
2022-01-17 17:41:33 +09:00
|
|
|
let(:action_taken) { nil }
|
2018-05-22 21:45:10 +09:00
|
|
|
let(:account_id) { nil }
|
|
|
|
|
|
|
|
context 'when create_and_resolve flag is on' do
|
2024-05-15 22:38:36 +09:00
|
|
|
let(:params) { { report_note: { report_id: report.id, content: 'test content' }, create_and_resolve: nil } }
|
2018-05-22 21:45:10 +09:00
|
|
|
|
|
|
|
it 'creates a report note and resolves report' do
|
2023-05-24 18:23:40 +09:00
|
|
|
expect { subject }.to change(ReportNote, :count).by(1)
|
2018-05-22 21:45:10 +09:00
|
|
|
expect(report.reload).to be_action_taken
|
2023-12-01 19:38:15 +09:00
|
|
|
expect(response).to redirect_to admin_reports_path
|
2018-05-22 21:45:10 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when create_and_resolve flag is false' do
|
2024-05-15 22:38:36 +09:00
|
|
|
let(:params) { { report_note: { report_id: report.id, content: 'test content' } } }
|
2018-05-22 21:45:10 +09:00
|
|
|
|
|
|
|
it 'creates a report note and does not resolve report' do
|
2023-05-24 18:23:40 +09:00
|
|
|
expect { subject }.to change(ReportNote, :count).by(1)
|
2023-02-20 10:33:27 +09:00
|
|
|
expect(report.reload).to_not be_action_taken
|
2023-12-01 19:38:15 +09:00
|
|
|
expect(response).to redirect_to admin_report_path(report)
|
2018-05-22 21:45:10 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when report is resolved' do
|
2022-01-17 17:41:33 +09:00
|
|
|
let(:action_taken) { Time.now.utc }
|
2018-05-22 21:45:10 +09:00
|
|
|
let(:account_id) { user.account.id }
|
|
|
|
|
|
|
|
context 'when create_and_unresolve flag is on' do
|
2024-05-15 22:38:36 +09:00
|
|
|
let(:params) { { report_note: { report_id: report.id, content: 'test content' }, create_and_unresolve: nil } }
|
2018-05-22 21:45:10 +09:00
|
|
|
|
|
|
|
it 'creates a report note and unresolves report' do
|
2023-05-24 18:23:40 +09:00
|
|
|
expect { subject }.to change(ReportNote, :count).by(1)
|
2023-02-20 10:33:27 +09:00
|
|
|
expect(report.reload).to_not be_action_taken
|
2023-12-01 19:38:15 +09:00
|
|
|
expect(response).to redirect_to admin_report_path(report)
|
2018-05-22 21:45:10 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when create_and_unresolve flag is false' do
|
2024-05-15 22:38:36 +09:00
|
|
|
let(:params) { { report_note: { report_id: report.id, content: 'test content' } } }
|
2018-05-22 21:45:10 +09:00
|
|
|
|
|
|
|
it 'creates a report note and does not unresolve report' do
|
2023-05-24 18:23:40 +09:00
|
|
|
expect { subject }.to change(ReportNote, :count).by(1)
|
2018-05-22 21:45:10 +09:00
|
|
|
expect(report.reload).to be_action_taken
|
2023-12-01 19:38:15 +09:00
|
|
|
expect(response).to redirect_to admin_report_path(report)
|
2018-05-22 21:45:10 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-15 22:38:36 +09:00
|
|
|
context 'when content is too short' do
|
|
|
|
let(:params) { { report_note: { report_id: report.id, content: '' } } }
|
2022-01-17 17:41:33 +09:00
|
|
|
let(:action_taken) { nil }
|
2018-05-22 21:45:10 +09:00
|
|
|
let(:account_id) { nil }
|
|
|
|
|
|
|
|
it 'renders admin/reports/show' do
|
2024-05-15 22:38:36 +09:00
|
|
|
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)
|
2018-05-22 21:45:10 +09:00
|
|
|
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
|
2023-05-24 18:23:40 +09:00
|
|
|
expect { subject }.to change(ReportNote, :count).by(-1)
|
2023-12-01 19:38:15 +09:00
|
|
|
expect(response).to redirect_to admin_report_path(report_note.report)
|
2018-05-22 21:45:10 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|