followers_synchronizations_controller_spec.rb 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::FollowersSynchronizationsController, type: :controller do
  3. let!(:account) { Fabricate(:account) }
  4. let!(:follower_1) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/users/a') }
  5. let!(:follower_2) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/users/b') }
  6. let!(:follower_3) { Fabricate(:account, domain: 'foo.com', uri: 'https://foo.com/users/a') }
  7. let!(:follower_4) { Fabricate(:account, username: 'instance-actor', domain: 'example.com', uri: 'https://example.com') }
  8. before do
  9. follower_1.follow!(account)
  10. follower_2.follow!(account)
  11. follower_3.follow!(account)
  12. follower_4.follow!(account)
  13. end
  14. before do
  15. allow(controller).to receive(:signed_request_actor).and_return(remote_account)
  16. end
  17. describe 'GET #show' do
  18. context 'without signature' do
  19. let(:remote_account) { nil }
  20. before do
  21. get :show, params: { account_username: account.username }
  22. end
  23. it 'returns http not authorized' do
  24. expect(response).to have_http_status(401)
  25. end
  26. end
  27. context 'with signature from example.com' do
  28. let(:remote_account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/instance') }
  29. subject(:response) { get :show, params: { account_username: account.username } }
  30. subject(:body) { body_as_json }
  31. it 'returns http success' do
  32. expect(response).to have_http_status(200)
  33. end
  34. it 'returns application/activity+json' do
  35. expect(response.media_type).to eq 'application/activity+json'
  36. end
  37. it 'returns orderedItems with followers from example.com' do
  38. expect(body[:orderedItems]).to be_an Array
  39. expect(body[:orderedItems]).to match_array([follower_4.uri, follower_1.uri, follower_2.uri])
  40. end
  41. it 'returns private Cache-Control header' do
  42. expect(response.headers['Cache-Control']).to eq 'max-age=0, private'
  43. end
  44. context 'when account is permanently suspended' do
  45. before do
  46. account.suspend!
  47. account.deletion_request.destroy
  48. end
  49. it 'returns http gone' do
  50. expect(response).to have_http_status(410)
  51. end
  52. end
  53. context 'when account is temporarily suspended' do
  54. before do
  55. account.suspend!
  56. end
  57. it 'returns http forbidden' do
  58. expect(response).to have_http_status(403)
  59. end
  60. end
  61. end
  62. end
  63. end