delete_account_service_spec.rb 3.3 KB

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