suggestions_spec.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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' do
  20. subject
  21. expect(response).to have_http_status(200)
  22. end
  23. it 'returns accounts' do
  24. subject
  25. body = body_as_json
  26. expect(body.size).to eq 2
  27. expect(body.pluck(:id)).to match_array([bob, jeff].map { |i| i.id.to_s })
  28. end
  29. context 'with limit param' do
  30. let(:params) { { limit: 1 } }
  31. it 'returns only the requested number of accounts' do
  32. subject
  33. expect(body_as_json.size).to eq 1
  34. end
  35. end
  36. context 'without an authorization header' do
  37. let(:headers) { {} }
  38. it 'returns http unauthorized' do
  39. subject
  40. expect(response).to have_http_status(401)
  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' do
  56. subject
  57. expect(response).to have_http_status(200)
  58. end
  59. it 'removes the specified suggestion' do
  60. subject
  61. expect(FollowRecommendationMute.exists?(account: user.account, target_account: jeff)).to be true
  62. end
  63. context 'without an authorization header' do
  64. let(:headers) { {} }
  65. it 'returns http unauthorized' do
  66. subject
  67. expect(response).to have_http_status(401)
  68. end
  69. end
  70. end
  71. end