measures_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe 'Admin Measures' do
  4. let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  7. let(:account) { Fabricate(:account) }
  8. let(:params) do
  9. {
  10. keys: %w(instance_accounts instance_follows instance_followers),
  11. instance_accounts: {
  12. domain: 'mastodon.social',
  13. include_subdomains: true,
  14. },
  15. instance_follows: {
  16. domain: 'mastodon.social',
  17. include_subdomains: true,
  18. },
  19. instance_followers: {
  20. domain: 'mastodon.social',
  21. include_subdomains: true,
  22. },
  23. }
  24. end
  25. describe 'GET /api/v1/admin/measures' do
  26. context 'when not authorized' do
  27. it 'returns http forbidden' do
  28. post '/api/v1/admin/measures', params: params
  29. expect(response)
  30. .to have_http_status(403)
  31. end
  32. end
  33. context 'with correct scope' do
  34. let(:scopes) { 'admin:read' }
  35. it 'returns http success and status json' do
  36. post '/api/v1/admin/measures', params: params, headers: headers
  37. expect(response)
  38. .to have_http_status(200)
  39. expect(body_as_json)
  40. .to be_an(Array)
  41. end
  42. end
  43. end
  44. end