sources_spec.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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(body_as_json).to eq({
  19. id: status.id.to_s,
  20. text: status.text,
  21. spoiler_text: status.spoiler_text,
  22. })
  23. end
  24. end
  25. context 'with private status of non-followed account' do
  26. let(:status) { Fabricate(:status, visibility: :private) }
  27. it 'returns http not found' do
  28. subject
  29. expect(response).to have_http_status(404)
  30. end
  31. end
  32. context 'with private status of followed account' do
  33. let(:status) { Fabricate(:status, visibility: :private) }
  34. before do
  35. user.account.follow!(status.account)
  36. end
  37. it 'returns the source properties of the status', :aggregate_failures do
  38. subject
  39. expect(response).to have_http_status(200)
  40. expect(body_as_json).to eq({
  41. id: status.id.to_s,
  42. text: status.text,
  43. spoiler_text: status.spoiler_text,
  44. })
  45. end
  46. end
  47. context 'without an authorization header' do
  48. let(:headers) { {} }
  49. it 'returns http unauthorized' do
  50. subject
  51. expect(response).to have_http_status(401)
  52. end
  53. end
  54. end
  55. end