2017-05-04 14:44:39 -07:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2020-09-15 05:37:58 -07:00
|
|
|
RSpec.describe DeleteAccountService, type: :service 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) }
|
|
|
|
|
2020-12-21 09:22:17 -08:00
|
|
|
it 'deletes associated owned records' do
|
2022-03-28 03:43:58 -07:00
|
|
|
expect { subject }.to change {
|
2017-05-04 14:44:39 -07:00
|
|
|
[
|
|
|
|
account.statuses,
|
|
|
|
account.media_attachments,
|
|
|
|
account.notifications,
|
|
|
|
account.favourites,
|
|
|
|
account.active_relationships,
|
|
|
|
account.passive_relationships,
|
2020-12-21 09:22:17 -08:00
|
|
|
account.polls,
|
2021-08-08 06:29:57 -07:00
|
|
|
account.account_notes,
|
2020-12-21 09:22:17 -08:00
|
|
|
].map(&:count)
|
2021-08-08 06:29:57 -07:00
|
|
|
}.from([2, 1, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0, 0])
|
2020-12-21 09:22:17 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'deletes associated target records' do
|
2022-03-28 03:43:58 -07:00
|
|
|
expect { subject }.to change {
|
2020-12-21 09:22:17 -08:00
|
|
|
[
|
2020-07-06 17:01:13 -07:00
|
|
|
AccountPin.where(target_account: account),
|
2017-05-04 14:44:39 -07:00
|
|
|
].map(&:count)
|
2020-12-21 09:22:17 -08:00
|
|
|
}.from([1]).to([0])
|
2017-05-04 14:44:39 -07:00
|
|
|
end
|
2018-08-20 04:28:05 -07:00
|
|
|
|
2020-12-21 09:22:17 -08:00
|
|
|
it 'deletes associated target notifications' do
|
2022-03-28 03:43:58 -07:00
|
|
|
expect { subject }.to change {
|
2023-02-19 21:14:10 -08:00
|
|
|
%w(
|
|
|
|
poll favourite status mention follow
|
|
|
|
).map { |type| Notification.where(type: type).count }
|
2020-12-21 09:22:17 -08:00
|
|
|
}.from([1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0])
|
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
|
|
|
|
2020-12-21 09:22:17 -08:00
|
|
|
describe '#call on local account' do
|
2019-03-10 08:18:58 -07:00
|
|
|
before do
|
2023-02-18 14:38:14 -08:00
|
|
|
stub_request(:post, 'https://alice.com/inbox').to_return(status: 201)
|
|
|
|
stub_request(:post, 'https://bob.com/inbox').to_return(status: 201)
|
2019-03-10 08:18:58 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:remote_alice) { Fabricate(:account, inbox_url: 'https://alice.com/inbox', protocol: :activitypub) }
|
|
|
|
let!(:remote_bob) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
|
|
|
|
|
2020-12-21 09:22:17 -08:00
|
|
|
include_examples 'common behavior' do
|
|
|
|
let!(:account) { Fabricate(:account) }
|
|
|
|
let!(:local_follower) { Fabricate(:account) }
|
|
|
|
|
|
|
|
it 'sends a delete actor activity to all known inboxes' do
|
2022-03-28 03:43:58 -07:00
|
|
|
subject
|
2023-02-18 14:38:14 -08:00
|
|
|
expect(a_request(:post, 'https://alice.com/inbox')).to have_been_made.once
|
|
|
|
expect(a_request(:post, 'https://bob.com/inbox')).to have_been_made.once
|
2020-12-21 09:22:17 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#call on remote account' do
|
|
|
|
before do
|
2023-02-18 14:38:14 -08:00
|
|
|
stub_request(:post, 'https://alice.com/inbox').to_return(status: 201)
|
|
|
|
stub_request(:post, 'https://bob.com/inbox').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
|
|
|
|
let!(:account) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
|
|
|
|
let!(:local_follower) { Fabricate(:account) }
|
|
|
|
|
2022-02-22 11:14:17 -08:00
|
|
|
it 'sends a reject follow to follower inboxes' do
|
2022-03-28 03:43:58 -07:00
|
|
|
subject
|
2020-12-21 09:22:17 -08:00
|
|
|
expect(a_request(:post, account.inbox_url)).to have_been_made.once
|
|
|
|
end
|
2019-03-10 08:18:58 -07:00
|
|
|
end
|
|
|
|
end
|
2017-05-04 14:44:39 -07:00
|
|
|
end
|