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.

46 lines
1.8 KiB

  1. require 'rails_helper'
  2. RSpec.describe SuspendAccountService, type: :service do
  3. describe '#call' 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. end