followers_synchronizations_controller_spec.rb 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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(:remote_account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/instance') }
  29. it 'returns http success and cache control and activity json types and correct items' do
  30. expect(response).to have_http_status(200)
  31. expect(response.headers['Cache-Control']).to eq 'max-age=0, private'
  32. expect(response.media_type).to eq 'application/activity+json'
  33. expect(response.parsed_body[:orderedItems])
  34. .to be_an(Array)
  35. .and contain_exactly(
  36. follower_example_com_instance_actor.uri,
  37. follower_example_com_user_a.uri,
  38. follower_example_com_user_b.uri
  39. )
  40. end
  41. context 'when account is permanently suspended' do
  42. before do
  43. account.suspend!
  44. account.deletion_request.destroy
  45. end
  46. it 'returns http gone' do
  47. expect(response).to have_http_status(410)
  48. end
  49. end
  50. context 'when account is temporarily suspended' do
  51. before do
  52. account.suspend!
  53. end
  54. it 'returns http forbidden' do
  55. expect(response).to have_http_status(403)
  56. end
  57. end
  58. end
  59. end
  60. end