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.

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