闭社主体 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.

80 lines
2.7 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', hub_url: 'http://hub.example.com')).account }
  44. before do
  45. stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
  46. stub_request(:post, "http://hub.example.com/").to_return(status: 202)
  47. subject.call(sender, bob.acct)
  48. end
  49. it 'creates a following relation' do
  50. expect(sender.following?(bob)).to be true
  51. end
  52. it 'sends a follow salmon slap' do
  53. expect(a_request(:post, "http://salmon.example.com/").with { |req|
  54. xml = OStatus2::Salmon.new.unpack(req.body)
  55. xml.match(TagManager::VERBS[:follow])
  56. }).to have_been_made.once
  57. end
  58. it 'subscribes to PuSH' do
  59. expect(a_request(:post, "http://hub.example.com/")).to have_been_made.once
  60. end
  61. end
  62. end
  63. end