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.

171 lines
7.1 KiB

  1. require 'rails_helper'
  2. RSpec.describe ImportService, type: :service do
  3. let!(:account) { Fabricate(:account, locked: false) }
  4. let!(:bob) { Fabricate(:account, username: 'bob', locked: false) }
  5. let!(:eve) { Fabricate(:account, username: 'eve', domain: 'example.com', locked: false, protocol: :activitypub, inbox_url: 'https://example.com/inbox') }
  6. before do
  7. stub_request(:post, "https://example.com/inbox").to_return(status: 200)
  8. end
  9. context 'import old-style list of muted users' do
  10. subject { ImportService.new }
  11. let(:csv) { attachment_fixture('mute-imports.txt') }
  12. describe 'when no accounts are muted' do
  13. let(:import) { Import.create(account: account, type: 'muting', data: csv) }
  14. it 'mutes the listed accounts, including notifications' do
  15. subject.call(import)
  16. expect(account.muting.count).to eq 2
  17. expect(Mute.find_by(account: account, target_account: bob).hide_notifications).to be true
  18. end
  19. end
  20. describe 'when some accounts are muted and overwrite is not set' do
  21. let(:import) { Import.create(account: account, type: 'muting', data: csv) }
  22. it 'mutes the listed accounts, including notifications' do
  23. account.mute!(bob, notifications: false)
  24. subject.call(import)
  25. expect(account.muting.count).to eq 2
  26. expect(Mute.find_by(account: account, target_account: bob).hide_notifications).to be true
  27. end
  28. end
  29. describe 'when some accounts are muted and overwrite is set' do
  30. let(:import) { Import.create(account: account, type: 'muting', data: csv, overwrite: true) }
  31. it 'mutes the listed accounts, including notifications' do
  32. account.mute!(bob, notifications: false)
  33. subject.call(import)
  34. expect(account.muting.count).to eq 2
  35. expect(Mute.find_by(account: account, target_account: bob).hide_notifications).to be true
  36. end
  37. end
  38. end
  39. context 'import new-style list of muted users' do
  40. subject { ImportService.new }
  41. let(:csv) { attachment_fixture('new-mute-imports.txt') }
  42. describe 'when no accounts are muted' do
  43. let(:import) { Import.create(account: account, type: 'muting', data: csv) }
  44. it 'mutes the listed accounts, respecting notifications' do
  45. subject.call(import)
  46. expect(account.muting.count).to eq 2
  47. expect(Mute.find_by(account: account, target_account: bob).hide_notifications).to be true
  48. expect(Mute.find_by(account: account, target_account: eve).hide_notifications).to be false
  49. end
  50. end
  51. describe 'when some accounts are muted and overwrite is not set' do
  52. let(:import) { Import.create(account: account, type: 'muting', data: csv) }
  53. it 'mutes the listed accounts, respecting notifications' do
  54. account.mute!(bob, notifications: true)
  55. subject.call(import)
  56. expect(account.muting.count).to eq 2
  57. expect(Mute.find_by(account: account, target_account: bob).hide_notifications).to be true
  58. expect(Mute.find_by(account: account, target_account: eve).hide_notifications).to be false
  59. end
  60. end
  61. describe 'when some accounts are muted and overwrite is set' do
  62. let(:import) { Import.create(account: account, type: 'muting', data: csv, overwrite: true) }
  63. it 'mutes the listed accounts, respecting notifications' do
  64. account.mute!(bob, notifications: true)
  65. subject.call(import)
  66. expect(account.muting.count).to eq 2
  67. expect(Mute.find_by(account: account, target_account: bob).hide_notifications).to be true
  68. expect(Mute.find_by(account: account, target_account: eve).hide_notifications).to be false
  69. end
  70. end
  71. end
  72. context 'import old-style list of followed users' do
  73. subject { ImportService.new }
  74. let(:csv) { attachment_fixture('mute-imports.txt') }
  75. describe 'when no accounts are followed' do
  76. let(:import) { Import.create(account: account, type: 'following', data: csv) }
  77. it 'follows the listed accounts, including boosts' do
  78. subject.call(import)
  79. expect(account.following.count).to eq 1
  80. expect(account.follow_requests.count).to eq 1
  81. expect(Follow.find_by(account: account, target_account: bob).show_reblogs).to be true
  82. end
  83. end
  84. describe 'when some accounts are already followed and overwrite is not set' do
  85. let(:import) { Import.create(account: account, type: 'following', data: csv) }
  86. it 'follows the listed accounts, including notifications' do
  87. account.follow!(bob, reblogs: false)
  88. subject.call(import)
  89. expect(account.following.count).to eq 1
  90. expect(account.follow_requests.count).to eq 1
  91. expect(Follow.find_by(account: account, target_account: bob).show_reblogs).to be true
  92. end
  93. end
  94. describe 'when some accounts are already followed and overwrite is set' do
  95. let(:import) { Import.create(account: account, type: 'following', data: csv, overwrite: true) }
  96. it 'mutes the listed accounts, including notifications' do
  97. account.follow!(bob, reblogs: false)
  98. subject.call(import)
  99. expect(account.following.count).to eq 1
  100. expect(account.follow_requests.count).to eq 1
  101. expect(Follow.find_by(account: account, target_account: bob).show_reblogs).to be true
  102. end
  103. end
  104. end
  105. context 'import new-style list of followed users' do
  106. subject { ImportService.new }
  107. let(:csv) { attachment_fixture('new-following-imports.txt') }
  108. describe 'when no accounts are followed' do
  109. let(:import) { Import.create(account: account, type: 'following', data: csv) }
  110. it 'follows the listed accounts, respecting boosts' do
  111. subject.call(import)
  112. expect(account.following.count).to eq 1
  113. expect(account.follow_requests.count).to eq 1
  114. expect(Follow.find_by(account: account, target_account: bob).show_reblogs).to be true
  115. expect(FollowRequest.find_by(account: account, target_account: eve).show_reblogs).to be false
  116. end
  117. end
  118. describe 'when some accounts are already followed and overwrite is not set' do
  119. let(:import) { Import.create(account: account, type: 'following', data: csv) }
  120. it 'mutes the listed accounts, respecting notifications' do
  121. account.follow!(bob, reblogs: true)
  122. subject.call(import)
  123. expect(account.following.count).to eq 1
  124. expect(account.follow_requests.count).to eq 1
  125. expect(Follow.find_by(account: account, target_account: bob).show_reblogs).to be true
  126. expect(FollowRequest.find_by(account: account, target_account: eve).show_reblogs).to be false
  127. end
  128. end
  129. describe 'when some accounts are already followed and overwrite is set' do
  130. let(:import) { Import.create(account: account, type: 'following', data: csv, overwrite: true) }
  131. it 'mutes the listed accounts, respecting notifications' do
  132. account.follow!(bob, reblogs: true)
  133. subject.call(import)
  134. expect(account.following.count).to eq 1
  135. expect(account.follow_requests.count).to eq 1
  136. expect(Follow.find_by(account: account, target_account: bob).show_reblogs).to be true
  137. expect(FollowRequest.find_by(account: account, target_account: eve).show_reblogs).to be false
  138. end
  139. end
  140. end
  141. end