diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/settings/exports/following_accounts_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/fixtures/files/new-following-imports.txt | 4 | ||||
-rw-r--r-- | spec/models/export_spec.rb | 7 | ||||
-rw-r--r-- | spec/services/import_service_spec.rb | 91 |
4 files changed, 97 insertions, 7 deletions
diff --git a/spec/controllers/settings/exports/following_accounts_controller_spec.rb b/spec/controllers/settings/exports/following_accounts_controller_spec.rb index 786769d24..78858e772 100644 --- a/spec/controllers/settings/exports/following_accounts_controller_spec.rb +++ b/spec/controllers/settings/exports/following_accounts_controller_spec.rb @@ -11,7 +11,7 @@ describe Settings::Exports::FollowingAccountsController do sign_in user, scope: :user get :index, format: :csv - expect(response.body).to eq "username@domain\n" + expect(response.body).to eq "Account address,Show boosts\nusername@domain,true\n" end end end diff --git a/spec/fixtures/files/new-following-imports.txt b/spec/fixtures/files/new-following-imports.txt new file mode 100644 index 000000000..5ea6c7346 --- /dev/null +++ b/spec/fixtures/files/new-following-imports.txt @@ -0,0 +1,4 @@ +Account address,Show boosts +bob,true +eve@example.com,false + diff --git a/spec/models/export_spec.rb b/spec/models/export_spec.rb index 0553f4098..4e6b824bb 100644 --- a/spec/models/export_spec.rb +++ b/spec/models/export_spec.rb @@ -32,10 +32,11 @@ describe Export do target_accounts.each(&account.method(:follow!)) export = Export.new(account).to_following_accounts_csv - results = export.strip.split + results = export.strip.split("\n") - expect(results.size).to eq 2 - expect(results.first).to eq 'one@local.host' + expect(results.size).to eq 3 + expect(results.first).to eq 'Account address,Show boosts' + expect(results.second).to eq 'one@local.host,true' end end diff --git a/spec/services/import_service_spec.rb b/spec/services/import_service_spec.rb index bd23781ce..5cf2dadf0 100644 --- a/spec/services/import_service_spec.rb +++ b/spec/services/import_service_spec.rb @@ -1,9 +1,9 @@ require 'rails_helper' RSpec.describe ImportService, type: :service do - let!(:account) { Fabricate(:account) } - let!(:bob) { Fabricate(:account, username: 'bob') } - let!(:eve) { Fabricate(:account, username: 'eve', domain: 'example.com') } + let!(:account) { Fabricate(:account, locked: false) } + let!(:bob) { Fabricate(:account, username: 'bob', locked: false) } + let!(:eve) { Fabricate(:account, username: 'eve', domain: 'example.com', locked: false) } context 'import old-style list of muted users' do subject { ImportService.new } @@ -81,4 +81,89 @@ RSpec.describe ImportService, type: :service do end end end + + context 'import old-style list of followed users' do + subject { ImportService.new } + + let(:csv) { attachment_fixture('mute-imports.txt') } + + before do + allow(NotificationWorker).to receive(:perform_async) + end + + describe 'when no accounts are followed' do + let(:import) { Import.create(account: account, type: 'following', data: csv) } + it 'follows the listed accounts, including boosts' do + subject.call(import) + expect(account.following.count).to eq 2 + expect(Follow.find_by(account: account, target_account: bob).show_reblogs).to be true + end + end + + describe 'when some accounts are already followed and overwrite is not set' do + let(:import) { Import.create(account: account, type: 'following', data: csv) } + + it 'follows the listed accounts, including notifications' do + account.follow!(bob, reblogs: false) + subject.call(import) + expect(account.following.count).to eq 2 + expect(Follow.find_by(account: account, target_account: bob).show_reblogs).to be true + end + end + + describe 'when some accounts are already followed and overwrite is set' do + let(:import) { Import.create(account: account, type: 'following', data: csv, overwrite: true) } + + it 'mutes the listed accounts, including notifications' do + account.follow!(bob, reblogs: false) + subject.call(import) + expect(account.following.count).to eq 2 + expect(Follow.find_by(account: account, target_account: bob).show_reblogs).to be true + end + end + end + + context 'import new-style list of followed users' do + subject { ImportService.new } + + let(:csv) { attachment_fixture('new-following-imports.txt') } + + before do + allow(NotificationWorker).to receive(:perform_async) + end + + describe 'when no accounts are followed' do + let(:import) { Import.create(account: account, type: 'following', data: csv) } + it 'follows the listed accounts, respecting boosts' do + subject.call(import) + expect(account.following.count).to eq 2 + expect(Follow.find_by(account: account, target_account: bob).show_reblogs).to be true + expect(Follow.find_by(account: account, target_account: eve).show_reblogs).to be false + end + end + + describe 'when some accounts are already followed and overwrite is not set' do + let(:import) { Import.create(account: account, type: 'following', data: csv) } + + it 'mutes the listed accounts, respecting notifications' do + account.follow!(bob, reblogs: true) + subject.call(import) + expect(account.following.count).to eq 2 + expect(Follow.find_by(account: account, target_account: bob).show_reblogs).to be true + expect(Follow.find_by(account: account, target_account: eve).show_reblogs).to be false + end + end + + describe 'when some accounts are already followed and overwrite is set' do + let(:import) { Import.create(account: account, type: 'following', data: csv, overwrite: true) } + + it 'mutes the listed accounts, respecting notifications' do + account.follow!(bob, reblogs: true) + subject.call(import) + expect(account.following.count).to eq 2 + expect(Follow.find_by(account: account, target_account: bob).show_reblogs).to be true + expect(Follow.find_by(account: account, target_account: eve).show_reblogs).to be false + end + end + end end |