You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.5 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe MoveWorker do
  4. let(:local_follower) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  5. let(:source_account) { Fabricate(:account, protocol: :activitypub, domain: 'example.com') }
  6. let(:target_account) { Fabricate(:account, protocol: :activitypub, domain: 'example.com') }
  7. subject { described_class.new }
  8. before do
  9. local_follower.follow!(source_account)
  10. end
  11. context 'both accounts are distant' do
  12. describe 'perform' do
  13. it 'calls UnfollowFollowWorker' do
  14. allow(UnfollowFollowWorker).to receive(:push_bulk)
  15. subject.perform(source_account.id, target_account.id)
  16. expect(UnfollowFollowWorker).to have_received(:push_bulk).with([local_follower.id])
  17. end
  18. end
  19. end
  20. context 'target account is local' do
  21. let(:target_account) { Fabricate(:user, email: 'alice@example.com', account: Fabricate(:account, username: 'alice')).account }
  22. describe 'perform' do
  23. it 'calls UnfollowFollowWorker' do
  24. allow(UnfollowFollowWorker).to receive(:push_bulk)
  25. subject.perform(source_account.id, target_account.id)
  26. expect(UnfollowFollowWorker).to have_received(:push_bulk).with([local_follower.id])
  27. end
  28. end
  29. end
  30. context 'both target and source accounts are local' do
  31. let(:target_account) { Fabricate(:user, email: 'alice@example.com', account: Fabricate(:account, username: 'alice')).account }
  32. let(:source_account) { Fabricate(:user, email: 'alice_@example.com', account: Fabricate(:account, username: 'alice_')).account }
  33. describe 'perform' do
  34. it 'calls makes local followers follow the target account' do
  35. subject.perform(source_account.id, target_account.id)
  36. expect(local_follower.following?(target_account)).to be true
  37. end
  38. it 'does not fail when a local user is already following both accounts' do
  39. double_follower = Fabricate(:user, email: 'eve@example.com', account: Fabricate(:account, username: 'eve')).account
  40. double_follower.follow!(source_account)
  41. double_follower.follow!(target_account)
  42. subject.perform(source_account.id, target_account.id)
  43. expect(local_follower.following?(target_account)).to be true
  44. end
  45. it 'does not allow the moved account to follow themselves' do
  46. source_account.follow!(target_account)
  47. subject.perform(source_account.id, target_account.id)
  48. expect(target_account.following?(target_account)).to be false
  49. end
  50. end
  51. end
  52. end