instance_spec.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Instances' do
  4. let(:user) { Fabricate(:user) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id) }
  6. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  7. describe 'GET /api/v2/instance' do
  8. context 'when logged out' do
  9. it 'returns http success and json' do
  10. get api_v2_instance_path
  11. expect(response)
  12. .to have_http_status(200)
  13. expect(response.content_type)
  14. .to start_with('application/json')
  15. expect(response.parsed_body)
  16. .to be_present
  17. .and include(title: 'Mastodon')
  18. .and include_api_versions
  19. .and include_configuration_limits
  20. end
  21. end
  22. context 'when logged in' do
  23. it 'returns http success and json' do
  24. get api_v2_instance_path, headers: headers
  25. expect(response)
  26. .to have_http_status(200)
  27. expect(response.content_type)
  28. .to start_with('application/json')
  29. expect(response.parsed_body)
  30. .to be_present
  31. .and include(title: 'Mastodon')
  32. .and include_api_versions
  33. .and include_configuration_limits
  34. end
  35. end
  36. def include_configuration_limits
  37. include(
  38. configuration: include(
  39. accounts: include(
  40. max_featured_tags: FeaturedTag::LIMIT,
  41. max_pinned_statuses: StatusPinValidator::PIN_LIMIT
  42. ),
  43. statuses: include(
  44. max_characters: StatusLengthValidator::MAX_CHARS,
  45. max_media_attachments: Status::MEDIA_ATTACHMENTS_LIMIT
  46. ),
  47. polls: include(
  48. max_options: PollValidator::MAX_OPTIONS
  49. )
  50. )
  51. )
  52. end
  53. def include_api_versions
  54. include(
  55. api_versions: include(
  56. mastodon: anything
  57. )
  58. )
  59. end
  60. end
  61. end