1
0

sources_spec.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Sources' do
  4. let(:user) { Fabricate(:user) }
  5. let(:scopes) { 'read:statuses' }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  7. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. describe 'GET /api/v1/statuses/:status_id/source' do
  9. subject do
  10. get "/api/v1/statuses/#{status.id}/source", headers: headers
  11. end
  12. let(:status) { Fabricate(:status) }
  13. it_behaves_like 'forbidden for wrong scope', 'write write:statuses'
  14. context 'with public status' do
  15. it 'returns the source properties of the status', :aggregate_failures do
  16. subject
  17. expect(response).to have_http_status(200)
  18. expect(response.content_type)
  19. .to start_with('application/json')
  20. expect(response.parsed_body).to match({
  21. id: status.id.to_s,
  22. text: status.text,
  23. spoiler_text: status.spoiler_text,
  24. })
  25. end
  26. end
  27. context 'with private status of non-followed account' do
  28. let(:status) { Fabricate(:status, visibility: :private) }
  29. it 'returns http not found' do
  30. subject
  31. expect(response).to have_http_status(404)
  32. expect(response.content_type)
  33. .to start_with('application/json')
  34. end
  35. end
  36. context 'with private status of followed account' do
  37. let(:status) { Fabricate(:status, visibility: :private) }
  38. before do
  39. user.account.follow!(status.account)
  40. end
  41. it 'returns the source properties of the status', :aggregate_failures do
  42. subject
  43. expect(response).to have_http_status(200)
  44. expect(response.content_type)
  45. .to start_with('application/json')
  46. expect(response.parsed_body).to match({
  47. id: status.id.to_s,
  48. text: status.text,
  49. spoiler_text: status.spoiler_text,
  50. })
  51. end
  52. end
  53. context 'without an authorization header' do
  54. let(:headers) { {} }
  55. it 'returns http unauthorized' do
  56. subject
  57. expect(response).to have_http_status(401)
  58. expect(response.content_type)
  59. .to start_with('application/json')
  60. end
  61. end
  62. end
  63. end