logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

follow_service_spec.rb (6448B)


  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 with reblogs' do
  12. expect(FollowRequest.find_by(account: sender, target_account: bob, show_reblogs: true)).to_not be_nil
  13. end
  14. end
  15. describe 'locked account, no reblogs' do
  16. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, locked: true, username: 'bob')).account }
  17. before do
  18. subject.call(sender, bob.acct, reblogs: false)
  19. end
  20. it 'creates a follow request without reblogs' do
  21. expect(FollowRequest.find_by(account: sender, target_account: bob, show_reblogs: false)).to_not be_nil
  22. end
  23. end
  24. describe 'unlocked account' do
  25. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  26. before do
  27. subject.call(sender, bob.acct)
  28. end
  29. it 'creates a following relation with reblogs' do
  30. expect(sender.following?(bob)).to be true
  31. expect(sender.muting_reblogs?(bob)).to be false
  32. end
  33. end
  34. describe 'unlocked account, no reblogs' do
  35. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  36. before do
  37. subject.call(sender, bob.acct, reblogs: false)
  38. end
  39. it 'creates a following relation without reblogs' do
  40. expect(sender.following?(bob)).to be true
  41. expect(sender.muting_reblogs?(bob)).to be true
  42. end
  43. end
  44. describe 'already followed account' do
  45. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  46. before do
  47. sender.follow!(bob)
  48. subject.call(sender, bob.acct)
  49. end
  50. it 'keeps a following relation' do
  51. expect(sender.following?(bob)).to be true
  52. end
  53. end
  54. describe 'already followed account, turning reblogs off' do
  55. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  56. before do
  57. sender.follow!(bob, reblogs: true)
  58. subject.call(sender, bob.acct, reblogs: false)
  59. end
  60. it 'disables reblogs' do
  61. expect(sender.muting_reblogs?(bob)).to be true
  62. end
  63. end
  64. describe 'already followed account, turning reblogs on' do
  65. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
  66. before do
  67. sender.follow!(bob, reblogs: false)
  68. subject.call(sender, bob.acct, reblogs: true)
  69. end
  70. it 'disables reblogs' do
  71. expect(sender.muting_reblogs?(bob)).to be false
  72. end
  73. end
  74. end
  75. context 'remote OStatus account' do
  76. describe 'locked account' do
  77. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, protocol: :ostatus, locked: true, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com')).account }
  78. before do
  79. stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
  80. subject.call(sender, bob.acct)
  81. end
  82. it 'creates a follow request' do
  83. expect(FollowRequest.find_by(account: sender, target_account: bob)).to_not be_nil
  84. end
  85. it 'sends a follow request salmon slap' do
  86. expect(a_request(:post, "http://salmon.example.com/").with { |req|
  87. xml = OStatus2::Salmon.new.unpack(req.body)
  88. xml.match(OStatus::TagManager::VERBS[:request_friend])
  89. }).to have_been_made.once
  90. end
  91. end
  92. describe 'unlocked account' do
  93. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, protocol: :ostatus, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com', hub_url: 'http://hub.example.com')).account }
  94. before do
  95. stub_request(:post, "http://salmon.example.com/").to_return(:status => 200, :body => "", :headers => {})
  96. stub_request(:post, "http://hub.example.com/").to_return(status: 202)
  97. subject.call(sender, bob.acct)
  98. end
  99. it 'creates a following relation' do
  100. expect(sender.following?(bob)).to be true
  101. end
  102. it 'sends a follow salmon slap' do
  103. expect(a_request(:post, "http://salmon.example.com/").with { |req|
  104. xml = OStatus2::Salmon.new.unpack(req.body)
  105. xml.match(OStatus::TagManager::VERBS[:follow])
  106. }).to have_been_made.once
  107. end
  108. it 'subscribes to PuSH' do
  109. expect(a_request(:post, "http://hub.example.com/")).to have_been_made.once
  110. end
  111. end
  112. describe 'already followed account' do
  113. let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, protocol: :ostatus, username: 'bob', domain: 'example.com', salmon_url: 'http://salmon.example.com', hub_url: 'http://hub.example.com')).account }
  114. before do
  115. sender.follow!(bob)
  116. subject.call(sender, bob.acct)
  117. end
  118. it 'keeps a following relation' do
  119. expect(sender.following?(bob)).to be true
  120. end
  121. it 'does not send a follow salmon slap' do
  122. expect(a_request(:post, "http://salmon.example.com/")).not_to have_been_made
  123. end
  124. it 'does not subscribe to PuSH' do
  125. expect(a_request(:post, "http://hub.example.com/")).not_to have_been_made
  126. end
  127. end
  128. end
  129. context 'remote ActivityPub account' do
  130. let(:bob) { Fabricate(:user, account: Fabricate(:account, username: 'bob', domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox')).account }
  131. before do
  132. stub_request(:post, "http://example.com/inbox").to_return(:status => 200, :body => "", :headers => {})
  133. subject.call(sender, bob.acct)
  134. end
  135. it 'creates follow request' do
  136. expect(FollowRequest.find_by(account: sender, target_account: bob)).to_not be_nil
  137. end
  138. it 'sends a follow activity to the inbox' do
  139. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
  140. end
  141. end
  142. end