batched_remove_status_service_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. require 'rails_helper'
  2. RSpec.describe BatchedRemoveStatusService, type: :service do
  3. subject { BatchedRemoveStatusService.new }
  4. let!(:alice) { Fabricate(:account) }
  5. let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://example.com/salmon') }
  6. let!(:jeff) { Fabricate(:user).account }
  7. let!(:hank) { Fabricate(:account, username: 'hank', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  8. let(:status1) { PostStatusService.new.call(alice, text: 'Hello @bob@example.com') }
  9. let(:status2) { PostStatusService.new.call(alice, text: 'Another status') }
  10. before do
  11. allow(Redis.current).to receive_messages(publish: nil)
  12. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  13. jeff.user.update(current_sign_in_at: Time.zone.now)
  14. jeff.follow!(alice)
  15. hank.follow!(alice)
  16. status1
  17. status2
  18. subject.call([status1, status2])
  19. end
  20. it 'removes statuses from author\'s home feed' do
  21. expect(HomeFeed.new(alice).get(10)).to_not include([status1.id, status2.id])
  22. end
  23. it 'removes statuses from local follower\'s home feed' do
  24. expect(HomeFeed.new(jeff).get(10)).to_not include([status1.id, status2.id])
  25. end
  26. it 'notifies streaming API of followers' do
  27. expect(Redis.current).to have_received(:publish).with("timeline:#{jeff.id}", any_args).at_least(:once)
  28. end
  29. it 'notifies streaming API of author' do
  30. expect(Redis.current).to have_received(:publish).with("timeline:#{alice.id}", any_args).at_least(:once)
  31. end
  32. it 'notifies streaming API of public timeline' do
  33. expect(Redis.current).to have_received(:publish).with('timeline:public', any_args).at_least(:once)
  34. end
  35. it 'sends delete activity to followers' do
  36. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.at_least_once
  37. end
  38. end