authorize_follow_service_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AuthorizeFollowService, 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. FollowRequest.create(account: bob, target_account: sender)
  10. subject.call(bob, sender)
  11. end
  12. it 'removes follow request' do
  13. expect(bob.requested?(sender)).to be false
  14. end
  15. it 'creates follow relation' do
  16. expect(bob.following?(sender)).to be true
  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. subject.call(bob, sender)
  25. end
  26. it 'removes follow request' do
  27. expect(bob.requested?(sender)).to be false
  28. end
  29. it 'creates follow relation' do
  30. expect(bob.following?(sender)).to be true
  31. end
  32. it 'sends an accept activity' do
  33. expect(a_request(:post, bob.inbox_url)).to have_been_made.once
  34. end
  35. end
  36. end