suggestions_spec.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Suggestions' do
  4. let(:user) { Fabricate(:user) }
  5. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  6. let(:scopes) { 'read' }
  7. let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
  8. describe 'GET /api/v1/suggestions' do
  9. subject do
  10. get '/api/v1/suggestions', headers: headers, params: params
  11. end
  12. let(:bob) { Fabricate(:account) }
  13. let(:jeff) { Fabricate(:account) }
  14. let(:params) { {} }
  15. before do
  16. Setting.bootstrap_timeline_accounts = [bob, jeff].map(&:acct).join(',')
  17. end
  18. it_behaves_like 'forbidden for wrong scope', 'write'
  19. it 'returns http success with accounts' do
  20. subject
  21. expect(response).to have_http_status(200)
  22. expect(response.content_type)
  23. .to start_with('application/json')
  24. expect(response.parsed_body)
  25. .to contain_exactly(include(id: bob.id.to_s), include(id: jeff.id.to_s))
  26. end
  27. context 'with limit param' do
  28. let(:params) { { limit: 1 } }
  29. it 'returns only the requested number of accounts' do
  30. subject
  31. expect(response.parsed_body.size).to eq 1
  32. end
  33. end
  34. context 'without an authorization header' do
  35. let(:headers) { {} }
  36. it 'returns http unauthorized' do
  37. subject
  38. expect(response).to have_http_status(401)
  39. expect(response.content_type)
  40. .to start_with('application/json')
  41. end
  42. end
  43. end
  44. describe 'DELETE /api/v1/suggestions/:id' do
  45. subject do
  46. delete "/api/v1/suggestions/#{jeff.id}", headers: headers
  47. end
  48. let(:bob) { Fabricate(:account) }
  49. let(:jeff) { Fabricate(:account) }
  50. let(:scopes) { 'write' }
  51. before do
  52. Setting.bootstrap_timeline_accounts = [bob, jeff].map(&:acct).join(',')
  53. end
  54. it_behaves_like 'forbidden for wrong scope', 'read'
  55. it 'returns http success and removes suggestion' do
  56. subject
  57. expect(response).to have_http_status(200)
  58. expect(response.content_type)
  59. .to start_with('application/json')
  60. expect(FollowRecommendationMute.exists?(account: user.account, target_account: jeff)).to be true
  61. end
  62. context 'without an authorization header' do
  63. let(:headers) { {} }
  64. it 'returns http unauthorized' do
  65. subject
  66. expect(response).to have_http_status(401)
  67. end
  68. end
  69. end
  70. end