batched_remove_status_service_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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') }
  6. let!(:jeff) { Fabricate(: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).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' do
  21. expect { Status.find(status1.id) }.to raise_error ActiveRecord::RecordNotFound
  22. expect { Status.find(status2.id) }.to raise_error ActiveRecord::RecordNotFound
  23. end
  24. it 'removes statuses from author\'s home feed' do
  25. expect(HomeFeed.new(alice).get(10)).to_not include([status1.id, status2.id])
  26. end
  27. it 'removes statuses from local follower\'s home feed' do
  28. expect(HomeFeed.new(jeff).get(10)).to_not include([status1.id, status2.id])
  29. end
  30. it 'notifies streaming API of followers' do
  31. expect(redis).to have_received(:publish).with("timeline:#{jeff.id}", any_args).at_least(:once)
  32. end
  33. it 'notifies streaming API of public timeline' do
  34. expect(redis).to have_received(:publish).with('timeline:public', any_args).at_least(:once)
  35. end
  36. it 'sends delete activity to followers' do
  37. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.at_least_once
  38. end
  39. end