1
0

unfollow_service_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe UnfollowService 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 { sender.follow!(bob) }
  9. it 'destroys the following relation' do
  10. subject.call(sender, bob)
  11. expect(sender)
  12. .to_not be_following(bob)
  13. end
  14. end
  15. describe 'remote ActivityPub', :inline_jobs do
  16. let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  17. before do
  18. sender.follow!(bob)
  19. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  20. end
  21. it 'destroys the following relation and sends unfollow activity' do
  22. subject.call(sender, bob)
  23. expect(sender)
  24. .to_not be_following(bob)
  25. expect(a_request(:post, 'http://example.com/inbox'))
  26. .to have_been_made.once
  27. end
  28. end
  29. describe 'remote ActivityPub (reverse)', :inline_jobs do
  30. let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  31. before do
  32. bob.follow!(sender)
  33. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  34. end
  35. it 'destroys the following relation and sends a reject activity' do
  36. subject.call(bob, sender)
  37. expect(sender)
  38. .to_not be_following(bob)
  39. expect(a_request(:post, 'http://example.com/inbox'))
  40. .to have_been_made.once
  41. end
  42. end
  43. end