unfollow_service_spec.rb 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. require 'rails_helper'
  2. RSpec.describe UnfollowService, type: :service do
  3. let(:sender) { Fabricate(:account, username: 'alice') }
  4. subject { UnfollowService.new }
  5. describe 'local' do
  6. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  7. before do
  8. sender.follow!(bob)
  9. subject.call(sender, bob)
  10. end
  11. it 'destroys the following relation' do
  12. expect(sender.following?(bob)).to be false
  13. end
  14. end
  15. describe 'remote OStatus' do
  16. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', protocol: :ostatus, domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
  17. before do
  18. sender.follow!(bob)
  19. stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
  20. subject.call(sender, bob)
  21. end
  22. it 'destroys the following relation' do
  23. expect(sender.following?(bob)).to be false
  24. end
  25. it 'sends an unfollow salmon slap' do
  26. expect(a_request(:post, "http://salmon.example.com/").with { |req|
  27. xml = OStatus2::Salmon.new.unpack(req.body)
  28. xml.match(OStatus::TagManager::VERBS[:unfollow])
  29. }).to have_been_made.once
  30. end
  31. end
  32. describe 'remote ActivityPub' do
  33. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox')).account }
  34. before do
  35. sender.follow!(bob)
  36. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  37. subject.call(sender, bob)
  38. end
  39. it 'destroys the following relation' do
  40. expect(sender.following?(bob)).to be false
  41. end
  42. it 'sends an unfollow activity' do
  43. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
  44. end
  45. end
  46. describe 'remote ActivityPub (reverse)' do
  47. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox')).account }
  48. before do
  49. bob.follow!(sender)
  50. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  51. subject.call(bob, sender)
  52. end
  53. it 'destroys the following relation' do
  54. expect(bob.following?(sender)).to be false
  55. end
  56. it 'sends a reject activity' do
  57. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
  58. end
  59. end
  60. end