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.

88 lines
3.5 KiB

  1. require 'rails_helper'
  2. RSpec.describe SuspendAccountService, 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!(:subscription) { Fabricate(:subscription, account: account) }
  19. let!(:remote_alice) { Fabricate(:account, inbox_url: 'https://alice.com/inbox', protocol: :activitypub) }
  20. let!(:remote_bob) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
  21. it 'deletes associated records' do
  22. is_expected.to change {
  23. [
  24. account.statuses,
  25. account.media_attachments,
  26. account.stream_entries,
  27. account.notifications,
  28. account.favourites,
  29. account.active_relationships,
  30. account.passive_relationships,
  31. account.subscriptions
  32. ].map(&:count)
  33. }.from([1, 1, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0, 0])
  34. end
  35. it 'sends a delete actor activity to all known inboxes' do
  36. subject.call
  37. expect(a_request(:post, "https://alice.com/inbox")).to have_been_made.once
  38. expect(a_request(:post, "https://bob.com/inbox")).to have_been_made.once
  39. end
  40. end
  41. describe '#call on remote account' do
  42. before do
  43. stub_request(:post, "https://alice.com/inbox").to_return(status: 201)
  44. stub_request(:post, "https://bob.com/inbox").to_return(status: 201)
  45. end
  46. subject do
  47. -> { described_class.new.call(remote_bob) }
  48. end
  49. let!(:account) { Fabricate(:account) }
  50. let!(:remote_alice) { Fabricate(:account, inbox_url: 'https://alice.com/inbox', protocol: :activitypub) }
  51. let!(:remote_bob) { Fabricate(:account, inbox_url: 'https://bob.com/inbox', protocol: :activitypub) }
  52. let!(:status) { Fabricate(:status, account: remote_bob) }
  53. let!(:media_attachment) { Fabricate(:media_attachment, account: remote_bob) }
  54. let!(:notification) { Fabricate(:notification, account: remote_bob) }
  55. let!(:favourite) { Fabricate(:favourite, account: remote_bob) }
  56. let!(:active_relationship) { Fabricate(:follow, account: remote_bob, target_account: account) }
  57. let!(:passive_relationship) { Fabricate(:follow, target_account: remote_bob) }
  58. let!(:subscription) { Fabricate(:subscription, account: remote_bob) }
  59. it 'deletes associated records' do
  60. is_expected.to change {
  61. [
  62. remote_bob.statuses,
  63. remote_bob.media_attachments,
  64. remote_bob.stream_entries,
  65. remote_bob.notifications,
  66. remote_bob.favourites,
  67. remote_bob.active_relationships,
  68. remote_bob.passive_relationships,
  69. remote_bob.subscriptions
  70. ].map(&:count)
  71. }.from([1, 1, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0, 0])
  72. end
  73. it 'sends a reject follow to follwer inboxes' do
  74. subject.call
  75. expect(a_request(:post, remote_bob.inbox_url)).to have_been_made.once
  76. end
  77. end
  78. end