authorize_follow_service_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AuthorizeFollowService 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. FollowRequest.create(account: bob, target_account: sender)
  10. end
  11. it 'removes follow request and creates follow relation' do
  12. subject.call(bob, sender)
  13. expect(bob)
  14. .to_not be_requested(sender)
  15. expect(bob)
  16. .to be_following(sender)
  17. end
  18. end
  19. describe 'remote ActivityPub' do
  20. let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') }
  21. before do
  22. FollowRequest.create(account: bob, target_account: sender)
  23. stub_request(:post, bob.inbox_url).to_return(status: 200)
  24. end
  25. it 'removes follow request, creates follow relation, send accept activity', :inline_jobs do
  26. subject.call(bob, sender)
  27. expect(bob)
  28. .to_not be_requested(sender)
  29. expect(bob)
  30. .to be_following(sender)
  31. expect(a_request(:post, bob.inbox_url))
  32. .to have_been_made.once
  33. end
  34. end
  35. end