move_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. require 'rails_helper'
  2. RSpec.describe ActivityPub::Activity::Move do
  3. let(:follower) { Fabricate(:account) }
  4. let(:old_account) { Fabricate(:account) }
  5. let(:new_account) { Fabricate(:account) }
  6. before do
  7. follower.follow!(old_account)
  8. old_account.update!(uri: 'https://example.org/alice', domain: 'example.org', protocol: :activitypub, inbox_url: 'https://example.org/inbox')
  9. new_account.update!(uri: 'https://example.com/alice', domain: 'example.com', protocol: :activitypub, inbox_url: 'https://example.com/inbox', also_known_as: [old_account.uri])
  10. stub_request(:post, 'https://example.org/inbox').to_return(status: 200)
  11. stub_request(:post, 'https://example.com/inbox').to_return(status: 200)
  12. service_stub = double
  13. allow(ActivityPub::FetchRemoteAccountService).to receive(:new).and_return(service_stub)
  14. allow(service_stub).to receive(:call).and_return(new_account)
  15. end
  16. let(:json) do
  17. {
  18. '@context': 'https://www.w3.org/ns/activitystreams',
  19. id: 'foo',
  20. type: 'Move',
  21. actor: old_account.uri,
  22. object: old_account.uri,
  23. target: new_account.uri,
  24. }.with_indifferent_access
  25. end
  26. describe '#perform' do
  27. subject { described_class.new(json, old_account) }
  28. before do
  29. subject.perform
  30. end
  31. it 'sets moved account on old account' do
  32. expect(old_account.reload.moved_to_account_id).to eq new_account.id
  33. end
  34. it 'makes followers unfollow old account' do
  35. expect(follower.following?(old_account)).to be false
  36. end
  37. it 'makes followers follow-request the new account' do
  38. expect(follower.requested?(new_account)).to be true
  39. end
  40. end
  41. end