batched_remove_status_service_spec.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe BatchedRemoveStatusService, :inline_jobs do
  4. subject { described_class.new }
  5. let!(:alice) { Fabricate(:account) }
  6. let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  7. let!(:jeff) { Fabricate(:account) }
  8. let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  9. let(:status_alice_hello) { PostStatusService.new.call(alice, text: "Hello @#{bob.pretty_acct}") }
  10. let(:status_alice_other) { PostStatusService.new.call(alice, text: 'Another status') }
  11. before do
  12. allow(redis).to receive_messages(publish: nil)
  13. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  14. jeff.user.update(current_sign_in_at: Time.zone.now)
  15. jeff.follow!(alice)
  16. hank.follow!(alice)
  17. status_alice_hello
  18. status_alice_other
  19. end
  20. it 'removes status records, removes from author and local follower feeds, notifies stream, sends delete' do
  21. subject.call([status_alice_hello, status_alice_other])
  22. expect { Status.find(status_alice_hello.id) }
  23. .to raise_error ActiveRecord::RecordNotFound
  24. expect { Status.find(status_alice_other.id) }
  25. .to raise_error ActiveRecord::RecordNotFound
  26. expect(feed_ids_for(alice))
  27. .to_not include(status_alice_hello.id, status_alice_other.id)
  28. expect(feed_ids_for(jeff))
  29. .to_not include(status_alice_hello.id, status_alice_other.id)
  30. expect(redis)
  31. .to have_received(:publish)
  32. .with("timeline:#{jeff.id}", any_args).at_least(:once)
  33. expect(redis)
  34. .to have_received(:publish)
  35. .with('timeline:public', any_args).at_least(:once)
  36. expect(a_request(:post, 'http://example.com/inbox'))
  37. .to have_been_made.at_least_once
  38. end
  39. def feed_ids_for(account)
  40. HomeFeed
  41. .new(account)
  42. .get(10)
  43. .pluck(:id)
  44. end
  45. end