list_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. 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. end
  21. end
  22. end
  23. context 'with the wrong user context' do
  24. let(:other_user) { Fabricate(:user) }
  25. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: other_user.id, scopes: 'read') }
  26. describe 'GET #show' do
  27. it 'returns http not found' do
  28. get "/api/v1/timelines/list/#{list.id}", headers: headers
  29. expect(response).to have_http_status(404)
  30. end
  31. end
  32. end
  33. context 'without a user context' do
  34. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: nil, scopes: 'read') }
  35. describe 'GET #show' do
  36. it 'returns http unprocessable entity' do
  37. get "/api/v1/timelines/list/#{list.id}", headers: headers
  38. expect(response).to have_http_status(422)
  39. expect(response.headers['Link']).to be_nil
  40. end
  41. end
  42. end
  43. end