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.

67 lines
2.5 KiB

  1. require 'rails_helper'
  2. RSpec.describe BatchedRemoveStatusService 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(: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, 'Hello @bob@example.com') }
  9. let(:status2) { PostStatusService.new.call(alice, 'Another status') }
  10. before do
  11. allow(Redis.current).to receive_messages(publish: nil)
  12. stub_request(:post, 'http://example.com/push').to_return(status: 200, body: '', headers: {})
  13. stub_request(:post, 'http://example.com/salmon').to_return(status: 200, body: '', headers: {})
  14. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  15. Fabricate(:subscription, account: alice, callback_url: 'http://example.com/push', confirmed: true, expires_at: 30.days.from_now)
  16. jeff.follow!(alice)
  17. hank.follow!(alice)
  18. status1
  19. status2
  20. subject.call([status1, status2])
  21. end
  22. it 'removes statuses from author\'s home feed' do
  23. expect(Feed.new(:home, alice).get(10)).to_not include([status1.id, status2.id])
  24. end
  25. it 'removes statuses from local follower\'s home feed' do
  26. expect(Feed.new(:home, jeff).get(10)).to_not include([status1.id, status2.id])
  27. end
  28. it 'notifies streaming API of followers' do
  29. expect(Redis.current).to have_received(:publish).with("timeline:#{jeff.id}", any_args).at_least(:once)
  30. end
  31. it 'notifies streaming API of author' do
  32. expect(Redis.current).to have_received(:publish).with("timeline:#{alice.id}", any_args).at_least(:once)
  33. end
  34. it 'notifies streaming API of public timeline' do
  35. expect(Redis.current).to have_received(:publish).with('timeline:public', any_args).at_least(:once)
  36. end
  37. it 'sends PuSH update to PuSH subscribers' do
  38. expect(a_request(:post, 'http://example.com/push').with { |req|
  39. matches = req.body.match(TagManager::VERBS[:delete])
  40. }).to have_been_made.at_least_once
  41. end
  42. it 'sends Salmon slap to previously mentioned users' do
  43. expect(a_request(:post, "http://example.com/salmon").with { |req|
  44. xml = OStatus2::Salmon.new.unpack(req.body)
  45. xml.match(TagManager::VERBS[:delete])
  46. }).to have_been_made.once
  47. end
  48. it 'sends delete activity to followers' do
  49. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.at_least_once
  50. end
  51. end