unfollow_service_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe UnfollowService, type: :service do
  4. subject { described_class.new }
  5. let(:sender) { Fabricate(:account, username: 'alice') }
  6. describe 'local' do
  7. let(:bob) { Fabricate(:account, username: 'bob') }
  8. before do
  9. sender.follow!(bob)
  10. subject.call(sender, bob)
  11. end
  12. it 'destroys the following relation' do
  13. expect(sender.following?(bob)).to be false
  14. end
  15. end
  16. describe 'remote ActivityPub', :sidekiq_inline do
  17. let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  18. before do
  19. sender.follow!(bob)
  20. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  21. subject.call(sender, bob)
  22. end
  23. it 'destroys the following relation' do
  24. expect(sender.following?(bob)).to be false
  25. end
  26. it 'sends an unfollow activity' do
  27. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
  28. end
  29. end
  30. describe 'remote ActivityPub (reverse)', :sidekiq_inline do
  31. let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  32. before do
  33. bob.follow!(sender)
  34. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  35. subject.call(bob, sender)
  36. end
  37. it 'destroys the following relation' do
  38. expect(bob.following?(sender)).to be false
  39. end
  40. it 'sends a reject activity' do
  41. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
  42. end
  43. end
  44. end