You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.2 KiB

  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: scopes) }
  7. before do
  8. allow(controller).to receive(:doorkeeper_token) { token }
  9. end
  10. describe 'GET #index' do
  11. let(:scopes) { 'read:reports' }
  12. it 'returns http success' do
  13. get :index
  14. expect(response).to have_http_status(200)
  15. end
  16. end
  17. describe 'POST #create' do
  18. let(:scopes) { 'write:reports' }
  19. let!(:status) { Fabricate(:status) }
  20. let!(:admin) { Fabricate(:user, admin: true) }
  21. before do
  22. allow(AdminMailer).to receive(:new_report).and_return(double('email', deliver_later: nil))
  23. post :create, params: { status_ids: [status.id], account_id: status.account.id, comment: 'reasons' }
  24. end
  25. it 'creates a report' do
  26. expect(status.reload.account.targeted_reports).not_to be_empty
  27. expect(response).to have_http_status(200)
  28. end
  29. it 'sends e-mails to admins' do
  30. expect(AdminMailer).to have_received(:new_report).with(admin.account, Report)
  31. end
  32. end
  33. end