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.

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