after_block_domain_from_account_service_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AfterBlockDomainFromAccountService do
  4. subject { described_class.new }
  5. let(:wolf) { Fabricate(:account, username: 'wolf', domain: 'evil.org', inbox_url: 'https://evil.org/wolf/inbox', protocol: :activitypub) }
  6. let(:dog) { Fabricate(:account, username: 'dog', domain: 'evil.org', inbox_url: 'https://evil.org/dog/inbox', protocol: :activitypub) }
  7. let(:alice) { Fabricate(:account, username: 'alice') }
  8. before do
  9. NotificationPermission.create!(account: alice, from_account: wolf)
  10. wolf.follow!(alice)
  11. alice.follow!(dog)
  12. end
  13. it 'purge followers from blocked domain, remove notification permissions, sends `Reject->Follow`, and records severed relationships', :aggregate_failures do
  14. expect { subject.call(alice, 'evil.org') }
  15. .to change { wolf.following?(alice) }.from(true).to(false)
  16. .and change { NotificationPermission.exists?(account: alice, from_account: wolf) }.from(true).to(false)
  17. expect(ActivityPub::DeliveryWorker.jobs.pluck('args')).to contain_exactly(
  18. [a_string_including('"type":"Reject"'), alice.id, wolf.inbox_url],
  19. [a_string_including('"type":"Undo"'), alice.id, dog.inbox_url]
  20. )
  21. severed_relationships = alice.severed_relationships.to_a
  22. expect(severed_relationships.count).to eq 2
  23. expect(severed_relationships[0].relationship_severance_event).to eq severed_relationships[1].relationship_severance_event
  24. expect(severed_relationships.map { |rel| [rel.account, rel.target_account] }).to contain_exactly([wolf, alice], [alice, dog])
  25. end
  26. end