2023-02-21 16:55:31 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-04 14:44:39 -07:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-03-13 01:39:26 -07:00
|
|
|
RSpec.describe DeleteAccountService do
|
2020-12-21 09:22:17 -08:00
|
|
|
shared_examples 'common behavior' do
|
2023-02-19 20:24:14 -08:00
|
|
|
subject { described_class.new.call(account) }
|
|
|
|
|
2020-12-21 09:22:17 -08:00
|
|
|
let!(:status) { Fabricate(:status, account: account) }
|
|
|
|
let!(:mention) { Fabricate(:mention, account: local_follower) }
|
|
|
|
let!(:status_with_mention) { Fabricate(:status, account: account, mentions: [mention]) }
|
|
|
|
let!(:media_attachment) { Fabricate(:media_attachment, account: account) }
|
|
|
|
let!(:notification) { Fabricate(:notification, account: account) }
|
|
|
|
let!(:favourite) { Fabricate(:favourite, account: account, status: Fabricate(:status, account: local_follower)) }
|
|
|
|
let!(:poll) { Fabricate(:poll, account: account) }
|
|
|
|
let!(:poll_vote) { Fabricate(:poll_vote, account: local_follower, poll: poll) }
|
|
|
|
|
|
|
|
let!(:active_relationship) { Fabricate(:follow, account: account, target_account: local_follower) }
|
|
|
|
let!(:passive_relationship) { Fabricate(:follow, account: local_follower, target_account: account) }
|
|
|
|
let!(:endorsement) { Fabricate(:account_pin, account: local_follower, target_account: account) }
|
|
|
|
|
|
|
|
let!(:mention_notification) { Fabricate(:notification, account: local_follower, activity: mention, type: :mention) }
|
|
|
|
let!(:status_notification) { Fabricate(:notification, account: local_follower, activity: status, type: :status) }
|
|
|
|
let!(:poll_notification) { Fabricate(:notification, account: local_follower, activity: poll, type: :poll) }
|
|
|
|
let!(:favourite_notification) { Fabricate(:notification, account: local_follower, activity: favourite, type: :favourite) }
|
|
|
|
let!(:follow_notification) { Fabricate(:notification, account: local_follower, activity: active_relationship, type: :follow) }
|
2018-08-20 04:28:05 -07:00
|
|
|
|
2021-08-08 06:29:57 -07:00
|
|
|
let!(:account_note) { Fabricate(:account_note, account: account) }
|
|
|
|
|
2023-12-06 00:51:09 -08:00
|
|
|
it 'deletes associated owned and target records and target notifications' do
|
2023-12-21 06:23:53 -08:00
|
|
|
subject
|
2023-12-06 00:51:09 -08:00
|
|
|
|
2023-12-21 06:23:53 -08:00
|
|
|
expect_deletion_of_associated_owned_records
|
|
|
|
expect_deletion_of_associated_target_records
|
|
|
|
expect_deletion_of_associated_target_notifications
|
2020-12-21 09:22:17 -08:00
|
|
|
end
|
|
|
|
|
2023-12-21 06:23:53 -08:00
|
|
|
def expect_deletion_of_associated_owned_records
|
|
|
|
expect { status.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { status_with_mention.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { mention.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { media_attachment.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { favourite.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { active_relationship.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { passive_relationship.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { poll.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { poll_vote.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { account_note.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
2023-12-14 06:07:54 -08:00
|
|
|
end
|
|
|
|
|
2023-12-21 06:23:53 -08:00
|
|
|
def expect_deletion_of_associated_target_records
|
|
|
|
expect { endorsement.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
2017-05-04 14:44:39 -07:00
|
|
|
end
|
2018-08-20 04:28:05 -07:00
|
|
|
|
2023-12-21 06:23:53 -08:00
|
|
|
def expect_deletion_of_associated_target_notifications
|
|
|
|
expect { favourite_notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { follow_notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { mention_notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { poll_notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
expect { status_notification.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
2018-08-20 04:28:05 -07:00
|
|
|
end
|
2017-05-04 14:44:39 -07:00
|
|
|
end
|
2019-03-10 08:18:58 -07:00
|
|
|
|
2024-07-08 09:01:08 -07:00
|
|
|
describe '#call on local account', :inline_jobs do
|
2019-03-10 08:18:58 -07:00
|
|
|
before do
|
2023-12-21 06:23:53 -08:00
|
|
|
stub_request(:post, remote_alice.inbox_url).to_return(status: 201)
|
|
|
|
stub_request(:post, remote_bob.inbox_url).to_return(status: 201)
|
2019-03-10 08:18:58 -07:00
|
|
|
end
|
|
|
|
|
2023-07-20 09:23:48 -07:00
|
|
|
let!(:remote_alice) { Fabricate(:account, inbox_url: 'https://alice.com/inbox', domain: 'alice.com', protocol: :activitypub) }
|
|
|
|
let!(:remote_bob) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', domain: 'bob.com', protocol: :activitypub) }
|
2019-03-10 08:18:58 -07:00
|
|
|
|
2020-12-21 09:22:17 -08:00
|
|
|
include_examples 'common behavior' do
|
2023-12-21 06:23:53 -08:00
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
let(:local_follower) { Fabricate(:account) }
|
2020-12-21 09:22:17 -08:00
|
|
|
|
|
|
|
it 'sends a delete actor activity to all known inboxes' do
|
2022-03-28 03:43:58 -07:00
|
|
|
subject
|
2023-12-21 06:23:53 -08:00
|
|
|
expect(a_request(:post, remote_alice.inbox_url)).to have_been_made.once
|
|
|
|
expect(a_request(:post, remote_bob.inbox_url)).to have_been_made.once
|
2020-12-21 09:22:17 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-07-08 09:01:08 -07:00
|
|
|
describe '#call on remote account', :inline_jobs do
|
2020-12-21 09:22:17 -08:00
|
|
|
before do
|
2023-12-21 06:23:53 -08:00
|
|
|
stub_request(:post, account.inbox_url).to_return(status: 201)
|
2019-03-10 08:18:58 -07:00
|
|
|
end
|
|
|
|
|
2020-12-21 09:22:17 -08:00
|
|
|
include_examples 'common behavior' do
|
2023-12-21 06:23:53 -08:00
|
|
|
let(:account) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub, domain: 'bob.com') }
|
|
|
|
let(:local_follower) { Fabricate(:account) }
|
2020-12-21 09:22:17 -08:00
|
|
|
|
2023-07-20 09:23:48 -07:00
|
|
|
it 'sends expected activities to followed and follower inboxes' do
|
2022-03-28 03:43:58 -07:00
|
|
|
subject
|
2023-07-20 09:23:48 -07:00
|
|
|
|
2023-12-14 06:07:54 -08:00
|
|
|
expect(post_to_inbox_with_reject).to have_been_made.once
|
|
|
|
expect(post_to_inbox_with_undo).to have_been_made.once
|
|
|
|
end
|
|
|
|
|
|
|
|
def post_to_inbox_with_undo
|
|
|
|
a_request(:post, account.inbox_url).with(
|
|
|
|
body: hash_including({
|
|
|
|
'type' => 'Undo',
|
|
|
|
'object' => hash_including({
|
|
|
|
'type' => 'Follow',
|
|
|
|
'actor' => ActivityPub::TagManager.instance.uri_for(local_follower),
|
|
|
|
'object' => account.uri,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def post_to_inbox_with_reject
|
|
|
|
a_request(:post, account.inbox_url).with(
|
|
|
|
body: hash_including({
|
|
|
|
'type' => 'Reject',
|
|
|
|
'object' => hash_including({
|
|
|
|
'type' => 'Follow',
|
|
|
|
'actor' => account.uri,
|
|
|
|
'object' => ActivityPub::TagManager.instance.uri_for(local_follower),
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
)
|
2020-12-21 09:22:17 -08:00
|
|
|
end
|
2019-03-10 08:18:58 -07:00
|
|
|
end
|
|
|
|
end
|
2017-05-04 14:44:39 -07:00
|
|
|
end
|