report_notes_controller_spec.rb 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::ReportNotesController do
  4. render_views
  5. let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  6. before do
  7. sign_in user, scope: :user
  8. end
  9. describe 'POST #create' do
  10. subject { post :create, params: params }
  11. let(:report) { Fabricate(:report, action_taken_at: action_taken, action_taken_by_account_id: account_id) }
  12. context 'when parameter is valid' do
  13. context 'when report is unsolved' do
  14. let(:action_taken) { nil }
  15. let(:account_id) { nil }
  16. context 'when create_and_resolve flag is on' do
  17. let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_resolve: nil } }
  18. it 'creates a report note and resolves report' do
  19. expect { subject }.to change(ReportNote, :count).by(1)
  20. expect(report.reload).to be_action_taken
  21. expect(subject).to redirect_to admin_reports_path
  22. end
  23. end
  24. context 'when create_and_resolve flag is false' do
  25. let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
  26. it 'creates a report note and does not resolve report' do
  27. expect { subject }.to change(ReportNote, :count).by(1)
  28. expect(report.reload).to_not be_action_taken
  29. expect(subject).to redirect_to admin_report_path(report)
  30. end
  31. end
  32. end
  33. context 'when report is resolved' do
  34. let(:action_taken) { Time.now.utc }
  35. let(:account_id) { user.account.id }
  36. context 'when create_and_unresolve flag is on' do
  37. let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_unresolve: nil } }
  38. it 'creates a report note and unresolves report' do
  39. expect { subject }.to change(ReportNote, :count).by(1)
  40. expect(report.reload).to_not be_action_taken
  41. expect(subject).to redirect_to admin_report_path(report)
  42. end
  43. end
  44. context 'when create_and_unresolve flag is false' do
  45. let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
  46. it 'creates a report note and does not unresolve report' do
  47. expect { subject }.to change(ReportNote, :count).by(1)
  48. expect(report.reload).to be_action_taken
  49. expect(subject).to redirect_to admin_report_path(report)
  50. end
  51. end
  52. end
  53. end
  54. context 'when parameter is invalid' do
  55. let(:params) { { report_note: { content: '', report_id: report.id } } }
  56. let(:action_taken) { nil }
  57. let(:account_id) { nil }
  58. it 'renders admin/reports/show' do
  59. expect(subject).to render_template 'admin/reports/show'
  60. end
  61. end
  62. end
  63. describe 'DELETE #destroy' do
  64. subject { delete :destroy, params: { id: report_note.id } }
  65. let!(:report_note) { Fabricate(:report_note) }
  66. it 'deletes note' do
  67. expect { subject }.to change(ReportNote, :count).by(-1)
  68. expect(subject).to redirect_to admin_report_path(report_note.report)
  69. end
  70. end
  71. end