diff options
author | Starfall <us@starfall.systems> | 2020-12-24 13:36:25 -0600 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2020-12-24 13:36:25 -0600 |
commit | 6ed4e874c5ace36344f77b3f096c4089d9b11e01 (patch) | |
tree | 83b2675d297f56a75b5e5dec33c644bc19f6cf1b /spec/services/delete_account_service_spec.rb | |
parent | ab127fd7941b7c84e6d6fe3071d41f52affb143c (diff) | |
parent | 225c934a1b66e2fcbedbda7936666c1ca3c9a04b (diff) |
Merge branch 'glitch' into main
Diffstat (limited to 'spec/services/delete_account_service_spec.rb')
-rw-r--r-- | spec/services/delete_account_service_spec.rb | 108 |
1 files changed, 60 insertions, 48 deletions
diff --git a/spec/services/delete_account_service_spec.rb b/spec/services/delete_account_service_spec.rb index d208b25b8..cd7d32d59 100644 --- a/spec/services/delete_account_service_spec.rb +++ b/spec/services/delete_account_service_spec.rb @@ -1,28 +1,31 @@ require 'rails_helper' RSpec.describe DeleteAccountService, type: :service do - describe '#call on local account' do - before do - stub_request(:post, "https://alice.com/inbox").to_return(status: 201) - stub_request(:post, "https://bob.com/inbox").to_return(status: 201) - end + shared_examples 'common behavior' do + 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) } subject do -> { described_class.new.call(account) } end - let!(:account) { Fabricate(:account) } - let!(:status) { Fabricate(:status, account: account) } - let!(:media_attachment) { Fabricate(:media_attachment, account: account) } - let!(:notification) { Fabricate(:notification, account: account) } - let!(:favourite) { Fabricate(:favourite, account: account) } - let!(:active_relationship) { Fabricate(:follow, account: account) } - let!(:passive_relationship) { Fabricate(:follow, target_account: account) } - 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) } - let!(:endorsment) { Fabricate(:account_pin, account: passive_relationship.account, target_account: account) } - - it 'deletes associated records' do + it 'deletes associated owned records' do is_expected.to change { [ account.statuses, @@ -31,54 +34,63 @@ RSpec.describe DeleteAccountService, type: :service do account.favourites, account.active_relationships, account.passive_relationships, + account.polls, + ].map(&:count) + }.from([2, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0]) + end + + it 'deletes associated target records' do + is_expected.to change { + [ AccountPin.where(target_account: account), ].map(&:count) - }.from([1, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0]) + }.from([1]).to([0]) end - it 'sends a delete actor activity to all known inboxes' do - subject.call - 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 + it 'deletes associated target notifications' do + is_expected.to change { + [ + 'poll', 'favourite', 'status', 'mention', 'follow' + ].map { |type| Notification.where(type: type).count } + }.from([1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0]) end end - describe '#call on remote account' do + describe '#call on local account' do before do stub_request(:post, "https://alice.com/inbox").to_return(status: 201) stub_request(:post, "https://bob.com/inbox").to_return(status: 201) end - subject do - -> { described_class.new.call(remote_bob) } - end - - let!(:account) { Fabricate(:account) } 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) } - let!(:status) { Fabricate(:status, account: remote_bob) } - let!(:media_attachment) { Fabricate(:media_attachment, account: remote_bob) } - let!(:notification) { Fabricate(:notification, account: remote_bob) } - let!(:favourite) { Fabricate(:favourite, account: remote_bob) } - let!(:active_relationship) { Fabricate(:follow, account: remote_bob, target_account: account) } - let!(:passive_relationship) { Fabricate(:follow, target_account: remote_bob) } - it 'deletes associated records' do - is_expected.to change { - [ - remote_bob.statuses, - remote_bob.media_attachments, - remote_bob.notifications, - remote_bob.favourites, - remote_bob.active_relationships, - remote_bob.passive_relationships, - ].map(&:count) - }.from([1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0]) + 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 + subject.call + 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 + end + end + end + + describe '#call on remote account' do + before do + stub_request(:post, "https://alice.com/inbox").to_return(status: 201) + stub_request(:post, "https://bob.com/inbox").to_return(status: 201) end - it 'sends a reject follow to follwer inboxes' do - subject.call - expect(a_request(:post, remote_bob.inbox_url)).to have_been_made.once + include_examples 'common behavior' do + let!(:account) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub) } + let!(:local_follower) { Fabricate(:account) } + + it 'sends a reject follow to follwer inboxes' do + subject.call + expect(a_request(:post, account.inbox_url)).to have_been_made.once + end end end end |