2023-02-21 16:55:31 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-09 13:46:54 -07:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-03-13 01:39:26 -07:00
|
|
|
RSpec.describe AfterBlockDomainFromAccountService do
|
2023-06-06 04:58:33 -07:00
|
|
|
subject { described_class.new }
|
2023-02-19 20:24:14 -08:00
|
|
|
|
2024-03-20 08:37:21 -07:00
|
|
|
let(:wolf) { Fabricate(:account, username: 'wolf', domain: 'evil.org', inbox_url: 'https://evil.org/wolf/inbox', protocol: :activitypub) }
|
|
|
|
let(:dog) { Fabricate(:account, username: 'dog', domain: 'evil.org', inbox_url: 'https://evil.org/dog/inbox', protocol: :activitypub) }
|
|
|
|
let(:alice) { Fabricate(:account, username: 'alice') }
|
2018-06-09 13:46:54 -07:00
|
|
|
|
|
|
|
before do
|
2024-03-20 08:37:21 -07:00
|
|
|
wolf.follow!(alice)
|
|
|
|
alice.follow!(dog)
|
2018-06-09 13:46:54 -07:00
|
|
|
end
|
|
|
|
|
2024-03-20 08:37:21 -07:00
|
|
|
around do |example|
|
|
|
|
Sidekiq::Testing.fake! do
|
|
|
|
example.run
|
|
|
|
end
|
2018-06-09 13:46:54 -07:00
|
|
|
end
|
|
|
|
|
2024-03-20 08:37:21 -07:00
|
|
|
it 'purges followers from blocked domain, sends them Reject->Follow, and records severed relationships', :aggregate_failures do
|
2018-06-09 13:46:54 -07:00
|
|
|
subject.call(alice, 'evil.org')
|
2024-03-20 08:37:21 -07:00
|
|
|
|
|
|
|
expect(wolf.following?(alice)).to be false
|
|
|
|
expect(ActivityPub::DeliveryWorker.jobs.pluck('args')).to contain_exactly(
|
|
|
|
[a_string_including('"type":"Reject"'), alice.id, wolf.inbox_url],
|
|
|
|
[a_string_including('"type":"Undo"'), alice.id, dog.inbox_url]
|
|
|
|
)
|
|
|
|
|
|
|
|
severed_relationships = alice.severed_relationships.to_a
|
|
|
|
expect(severed_relationships.count).to eq 2
|
|
|
|
expect(severed_relationships[0].relationship_severance_event).to eq severed_relationships[1].relationship_severance_event
|
|
|
|
expect(severed_relationships.map { |rel| [rel.account, rel.target_account] }).to contain_exactly([wolf, alice], [alice, dog])
|
2018-06-09 13:46:54 -07:00
|
|
|
end
|
|
|
|
end
|