You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
4.0 KiB

  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. subject do
  21. -> { described_class.new.call(account) }
  22. end
  23. it 'deletes associated owned records' do
  24. is_expected.to change {
  25. [
  26. account.statuses,
  27. account.media_attachments,
  28. account.notifications,
  29. account.favourites,
  30. account.active_relationships,
  31. account.passive_relationships,
  32. account.polls,
  33. ].map(&:count)
  34. }.from([2, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0])
  35. end
  36. it 'deletes associated target records' do
  37. is_expected.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. is_expected.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.call
  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 follwer inboxes' do
  77. subject.call
  78. expect(a_request(:post, account.inbox_url)).to have_been_made.once
  79. end
  80. end
  81. end
  82. end