move_spec.rb 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Move do
  3. let(:follower) { Fabricate(:account) }
  4. let(:old_account) { Fabricate(:account, uri: 'https://example.org/alice', domain: 'example.org', protocol: :activitypub, inbox_url: 'https://example.org/inbox') }
  5. let(:new_account) { Fabricate(:account, uri: 'https://example.com/alice', domain: 'example.com', protocol: :activitypub, inbox_url: 'https://example.com/inbox', also_known_as: also_known_as) }
  6. let(:also_known_as) { [old_account.uri] }
  7. let(:returned_account) { new_account }
  8. let(:json) do
  9. {
  10. '@context': 'https://www.w3.org/ns/activitystreams',
  11. id: 'foo',
  12. type: 'Move',
  13. actor: old_account.uri,
  14. object: old_account.uri,
  15. target: new_account.uri,
  16. }.with_indifferent_access
  17. end
  18. before do
  19. follower.follow!(old_account)
  20. stub_request(:post, old_account.inbox_url).to_return(status: 200)
  21. stub_request(:post, new_account.inbox_url).to_return(status: 200)
  22. service_stub = double
  23. allow(ActivityPub::FetchRemoteAccountService).to receive(:new).and_return(service_stub)
  24. allow(service_stub).to receive(:call).and_return(returned_account)
  25. end
  26. describe '#perform' do
  27. subject { described_class.new(json, old_account) }
  28. before do
  29. subject.perform
  30. end
  31. context 'when all conditions are met' do
  32. it 'sets moved account on old account' do
  33. expect(old_account.reload.moved_to_account_id).to eq new_account.id
  34. end
  35. it 'makes followers unfollow old account' do
  36. expect(follower.following?(old_account)).to be false
  37. end
  38. it 'makes followers follow-request the new account' do
  39. expect(follower.requested?(new_account)).to be true
  40. end
  41. end
  42. context "when the new account can't be resolved" do
  43. let(:returned_account) { nil }
  44. it 'does not set moved account on old account' do
  45. expect(old_account.reload.moved_to_account_id).to be_nil
  46. end
  47. it 'does not make followers unfollow old account' do
  48. expect(follower.following?(old_account)).to be true
  49. end
  50. it 'does not make followers follow-request the new account' do
  51. expect(follower.requested?(new_account)).to be false
  52. end
  53. end
  54. context 'when the new account does not references the old account' do
  55. let(:also_known_as) { [] }
  56. it 'does not set moved account on old account' do
  57. expect(old_account.reload.moved_to_account_id).to be_nil
  58. end
  59. it 'does not make followers unfollow old account' do
  60. expect(follower.following?(old_account)).to be true
  61. end
  62. it 'does not make followers follow-request the new account' do
  63. expect(follower.requested?(new_account)).to be false
  64. end
  65. end
  66. context 'when a Move has been recently processed' do
  67. around do |example|
  68. redis.set("move_in_progress:#{old_account.id}", true, nx: true, ex: 7.days.seconds)
  69. example.run
  70. redis.del("move_in_progress:#{old_account.id}")
  71. end
  72. it 'does not set moved account on old account' do
  73. expect(old_account.reload.moved_to_account_id).to be_nil
  74. end
  75. it 'does not make followers unfollow old account' do
  76. expect(follower.following?(old_account)).to be true
  77. end
  78. it 'does not make followers follow-request the new account' do
  79. expect(follower.requested?(new_account)).to be false
  80. end
  81. end
  82. end
  83. end