batched_remove_status_service_spec.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe BatchedRemoveStatusService, type: :service 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@example.com') }
  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. subject.call([status_alice_hello, status_alice_other])
  20. end
  21. it 'removes statuses' do
  22. expect { Status.find(status_alice_hello.id) }.to raise_error ActiveRecord::RecordNotFound
  23. expect { Status.find(status_alice_other.id) }.to raise_error ActiveRecord::RecordNotFound
  24. end
  25. it 'removes statuses from author\'s home feed' do
  26. expect(HomeFeed.new(alice).get(10).pluck(:id)).to_not include(status_alice_hello.id, status_alice_other.id)
  27. end
  28. it 'removes statuses from local follower\'s home feed' do
  29. expect(HomeFeed.new(jeff).get(10).pluck(:id)).to_not include(status_alice_hello.id, status_alice_other.id)
  30. end
  31. it 'notifies streaming API of followers' do
  32. expect(redis).to have_received(:publish).with("timeline:#{jeff.id}", any_args).at_least(:once)
  33. end
  34. it 'notifies streaming API of public timeline' do
  35. expect(redis).to have_received(:publish).with('timeline:public', any_args).at_least(:once)
  36. end
  37. it 'sends delete activity to followers' do
  38. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.at_least_once
  39. end
  40. end