followers_synchronizations_controller_spec.rb 2.7 KB

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