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.

70 lines
2.3 KiB

  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. end
  26. describe 'remote ActivityPub' do
  27. 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 }
  28. before do
  29. sender.follow!(bob)
  30. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  31. subject.call(sender, bob)
  32. end
  33. it 'destroys the following relation' do
  34. expect(sender.following?(bob)).to be false
  35. end
  36. it 'sends an unfollow activity' do
  37. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
  38. end
  39. end
  40. describe 'remote ActivityPub (reverse)' do
  41. 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 }
  42. before do
  43. bob.follow!(sender)
  44. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  45. subject.call(bob, sender)
  46. end
  47. it 'destroys the following relation' do
  48. expect(bob.following?(sender)).to be false
  49. end
  50. it 'sends a reject activity' do
  51. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
  52. end
  53. end
  54. end