list_spec.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'API V1 Timelines List' 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. let(:list) { Fabricate(:list, account: user.account) }
  9. context 'with a user context' do
  10. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:lists') }
  11. describe 'GET /api/v1/timelines/list/:id' do
  12. before do
  13. follow = Fabricate(:follow, account: user.account)
  14. list.accounts << follow.target_account
  15. PostStatusService.new.call(follow.target_account, text: 'New status for user home timeline.')
  16. end
  17. it 'returns http success' do
  18. get "/api/v1/timelines/list/#{list.id}", headers: headers
  19. expect(response).to have_http_status(200)
  20. expect(response.content_type)
  21. .to start_with('application/json')
  22. end
  23. end
  24. end
  25. context 'with the wrong user context' do
  26. let(:other_user) { Fabricate(:user) }
  27. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: other_user.id, scopes: 'read') }
  28. describe 'GET #show' do
  29. it 'returns http not found' do
  30. get "/api/v1/timelines/list/#{list.id}", headers: headers
  31. expect(response).to have_http_status(404)
  32. expect(response.content_type)
  33. .to start_with('application/json')
  34. end
  35. end
  36. end
  37. context 'without a user context' do
  38. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: nil, scopes: 'read') }
  39. describe 'GET #show' do
  40. it 'returns http unprocessable entity' do
  41. get "/api/v1/timelines/list/#{list.id}", headers: headers
  42. expect(response)
  43. .to have_http_status(422)
  44. .and not_have_http_link_header
  45. end
  46. end
  47. end
  48. end