2023-02-22 11:55:31 +11:00
# frozen_string_literal: true
2018-06-10 06:46:54 +10:00
require 'rails_helper'
2024-03-13 19:39:26 +11:00
RSpec . describe AfterBlockDomainFromAccountService do
2023-06-06 21:58:33 +10:00
subject { described_class . new }
2023-02-20 15:24:14 +11:00
2024-03-21 02:37:21 +11: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-10 06:46:54 +10:00
before do
2024-03-27 01:46:38 +11:00
NotificationPermission . create! ( account : alice , from_account : wolf )
2024-03-21 02:37:21 +11:00
wolf . follow! ( alice )
alice . follow! ( dog )
2018-06-10 06:46:54 +10:00
end
2024-03-27 01:46:38 +11:00
it 'purge followers from blocked domain, remove notification permissions, sends `Reject->Follow`, and records severed relationships' , :aggregate_failures do
expect { subject . call ( alice , 'evil.org' ) }
. to change { wolf . following? ( alice ) } . from ( true ) . to ( false )
. and change { NotificationPermission . exists? ( account : alice , from_account : wolf ) } . from ( true ) . to ( false )
2024-03-21 02:37:21 +11:00
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-10 06:46:54 +10:00
end
end