闭社主体 forked from https://github.com/tootsuite/mastodon
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.

75 lines
2.5 KiB

  1. require 'rails_helper'
  2. RSpec.describe FollowService do
  3. let(:sender) { Fabricate(:account, username: 'alice') }
  4. subject { FollowService.new }
  5. context 'local account' do
  6. describe 'locked account' do
  7. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, locked: true, username: 'bob')).account }
  8. before do
  9. subject.call(sender, bob.acct)
  10. end
  11. it 'creates a follow request' do
  12. expect(FollowRequest.find_by(account: sender, target_account: bob)).to_not be_nil
  13. end
  14. end
  15. describe 'unlocked account' do
  16. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  17. before do
  18. subject.call(sender, bob.acct)
  19. end
  20. it 'creates a following relation' do
  21. expect(sender.following?(bob)).to be true
  22. end
  23. end
  24. end
  25. context 'remote account' do
  26. describe 'locked account' do
  27. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, locked: true, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
  28. before do
  29. stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
  30. subject.call(sender, bob.acct)
  31. end
  32. it 'creates a follow request' do
  33. expect(FollowRequest.find_by(account: sender, target_account: bob)).to_not be_nil
  34. end
  35. it 'sends a follow request salmon slap' do
  36. expect(a_request(:post, "http://salmon.example.com/").with { |req|
  37. xml = OStatus2::Salmon.new.unpack(req.body)
  38. xml.match(TagManager::VERBS[:request_friend])
  39. }).to have_been_made.once
  40. end
  41. end
  42. describe 'unlocked account' do
  43. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
  44. before do
  45. stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
  46. subject.call(sender, bob.acct)
  47. end
  48. it 'creates a following relation' do
  49. expect(sender.following?(bob)).to be true
  50. end
  51. it 'sends a follow salmon slap' do
  52. expect(a_request(:post, "http://salmon.example.com/").with { |req|
  53. xml = OStatus2::Salmon.new.unpack(req.body)
  54. xml.match(TagManager::VERBS[:follow])
  55. }).to have_been_made.once
  56. end
  57. end
  58. end
  59. end