followers_synchronizations_controller_spec.rb 2.5 KB

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