1
0

delete_account_service_spec.rb 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. require 'rails_helper'
  2. RSpec.describe DeleteAccountService, type: :service do
  3. shared_examples 'common behavior' do
  4. let!(:status) { Fabricate(:status, account: account) }
  5. let!(:mention) { Fabricate(:mention, account: local_follower) }
  6. let!(:status_with_mention) { Fabricate(:status, account: account, mentions: [mention]) }
  7. let!(:media_attachment) { Fabricate(:media_attachment, account: account) }
  8. let!(:notification) { Fabricate(:notification, account: account) }
  9. let!(:favourite) { Fabricate(:favourite, account: account, status: Fabricate(:status, account: local_follower)) }
  10. let!(:poll) { Fabricate(:poll, account: account) }
  11. let!(:poll_vote) { Fabricate(:poll_vote, account: local_follower, poll: poll) }
  12. let!(:active_relationship) { Fabricate(:follow, account: account, target_account: local_follower) }
  13. let!(:passive_relationship) { Fabricate(:follow, account: local_follower, target_account: account) }
  14. let!(:endorsement) { Fabricate(:account_pin, account: local_follower, target_account: account) }
  15. let!(:mention_notification) { Fabricate(:notification, account: local_follower, activity: mention, type: :mention) }
  16. let!(:status_notification) { Fabricate(:notification, account: local_follower, activity: status, type: :status) }
  17. let!(:poll_notification) { Fabricate(:notification, account: local_follower, activity: poll, type: :poll) }
  18. let!(:favourite_notification) { Fabricate(:notification, account: local_follower, activity: favourite, type: :favourite) }
  19. let!(:follow_notification) { Fabricate(:notification, account: local_follower, activity: active_relationship, type: :follow) }
  20. let!(:account_note) { Fabricate(:account_note, account: account) }
  21. subject { described_class.new.call(account) }
  22. it 'deletes associated owned records' do
  23. expect { subject }.to change {
  24. [
  25. account.statuses,
  26. account.media_attachments,
  27. account.notifications,
  28. account.favourites,
  29. account.active_relationships,
  30. account.passive_relationships,
  31. account.polls,
  32. account.account_notes,
  33. ].map(&:count)
  34. }.from([2, 1, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0, 0])
  35. end
  36. it 'deletes associated target records' do
  37. expect { subject }.to change {
  38. [
  39. AccountPin.where(target_account: account),
  40. ].map(&:count)
  41. }.from([1]).to([0])
  42. end
  43. it 'deletes associated target notifications' do
  44. expect { subject }.to change {
  45. [
  46. 'poll', 'favourite', 'status', 'mention', 'follow'
  47. ].map { |type| Notification.where(type: type).count }
  48. }.from([1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0])
  49. end
  50. end
  51. describe '#call on local account' do
  52. before do
  53. stub_request(:post, "https://alice.com/inbox").to_return(status: 201)
  54. stub_request(:post, "https://bob.com/inbox").to_return(status: 201)
  55. end
  56. let!(:remote_alice) { Fabricate(:account, inbox_url: 'https://alice.com/inbox', protocol: :activitypub) }
  57. let!(:remote_bob) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
  58. include_examples 'common behavior' do
  59. let!(:account) { Fabricate(:account) }
  60. let!(:local_follower) { Fabricate(:account) }
  61. it 'sends a delete actor activity to all known inboxes' do
  62. subject
  63. expect(a_request(:post, "https://alice.com/inbox")).to have_been_made.once
  64. expect(a_request(:post, "https://bob.com/inbox")).to have_been_made.once
  65. end
  66. end
  67. end
  68. describe '#call on remote account' do
  69. before do
  70. stub_request(:post, "https://alice.com/inbox").to_return(status: 201)
  71. stub_request(:post, "https://bob.com/inbox").to_return(status: 201)
  72. end
  73. include_examples 'common behavior' do
  74. let!(:account) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
  75. let!(:local_follower) { Fabricate(:account) }
  76. it 'sends a reject follow to follower inboxes' do
  77. subject
  78. expect(a_request(:post, account.inbox_url)).to have_been_made.once
  79. end
  80. end
  81. end
  82. end