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.

57 lines
1.6 KiB

  1. require 'rails_helper'
  2. RSpec.describe Api::V1::Admin::AccountActionsController, type: :controller do
  3. render_views
  4. let(:role) { 'moderator' }
  5. let(:user) { Fabricate(:user, role: role, account: Fabricate(:account, username: 'alice')) }
  6. let(:scopes) { 'admin:read admin:write' }
  7. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  8. let(:account) { Fabricate(:user).account }
  9. before do
  10. allow(controller).to receive(:doorkeeper_token) { token }
  11. end
  12. shared_examples 'forbidden for wrong scope' do |wrong_scope|
  13. let(:scopes) { wrong_scope }
  14. it 'returns http forbidden' do
  15. expect(response).to have_http_status(403)
  16. end
  17. end
  18. shared_examples 'forbidden for wrong role' do |wrong_role|
  19. let(:role) { wrong_role }
  20. it 'returns http forbidden' do
  21. expect(response).to have_http_status(403)
  22. end
  23. end
  24. describe 'POST #create' do
  25. before do
  26. post :create, params: { account_id: account.id, type: 'disable' }
  27. end
  28. it_behaves_like 'forbidden for wrong scope', 'write:statuses'
  29. it_behaves_like 'forbidden for wrong role', 'user'
  30. it 'returns http success' do
  31. expect(response).to have_http_status(200)
  32. end
  33. it 'performs action against account' do
  34. expect(account.reload.user_disabled?).to be true
  35. end
  36. it 'logs action' do
  37. log_item = Admin::ActionLog.last
  38. expect(log_item).to_not be_nil
  39. expect(log_item.action).to eq :disable
  40. expect(log_item.account_id).to eq user.account_id
  41. expect(log_item.target_id).to eq account.user.id
  42. end
  43. end
  44. end