logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

reports_controller_spec.rb (1199B)


  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Api::V1::ReportsController, type: :controller do
  4. render_views
  5. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read write') }
  7. before do
  8. allow(controller).to receive(:doorkeeper_token) { token }
  9. end
  10. describe 'GET #index' do
  11. it 'returns http success' do
  12. get :index
  13. expect(response).to have_http_status(:success)
  14. end
  15. end
  16. describe 'POST #create' do
  17. let!(:status) { Fabricate(:status) }
  18. let!(:admin) { Fabricate(:user, admin: true) }
  19. before do
  20. allow(AdminMailer).to receive(:new_report).and_return(double('email', deliver_later: nil))
  21. post :create, params: { status_ids: [status.id], account_id: status.account.id, comment: 'reasons' }
  22. end
  23. it 'creates a report' do
  24. expect(status.reload.account.targeted_reports).not_to be_empty
  25. expect(response).to have_http_status(:success)
  26. end
  27. it 'sends e-mails to admins' do
  28. expect(AdminMailer).to have_received(:new_report).with(admin.account, Report)
  29. end
  30. end
  31. end