2023-02-22 11:55:31 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-12 06:00:43 +10:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 15:12:25 +10:00
|
|
|
RSpec.describe Export do
|
2017-06-19 19:30:27 +10:00
|
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
let(:target_accounts) do
|
2023-02-18 08:56:20 +11:00
|
|
|
[{}, { username: 'one', domain: 'local.host' }].map(&method(:Fabricate).curry(2).call(:account))
|
2017-06-19 19:30:27 +10:00
|
|
|
end
|
2017-04-13 23:29:30 +10:00
|
|
|
|
2017-06-19 19:30:27 +10:00
|
|
|
describe 'to_csv' do
|
2017-04-13 23:29:30 +10:00
|
|
|
it 'returns a csv of the blocked accounts' do
|
2023-05-03 18:30:54 +10:00
|
|
|
target_accounts.each { |target_account| account.block!(target_account) }
|
2017-06-19 19:30:27 +10:00
|
|
|
|
2023-06-06 21:58:33 +10:00
|
|
|
export = described_class.new(account).to_blocked_accounts_csv
|
2017-04-13 23:29:30 +10:00
|
|
|
results = export.strip.split
|
|
|
|
|
|
|
|
expect(results.size).to eq 2
|
|
|
|
expect(results.first).to eq 'one@local.host'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a csv of the muted accounts' do
|
2023-05-03 18:30:54 +10:00
|
|
|
target_accounts.each { |target_account| account.mute!(target_account) }
|
2017-06-19 19:30:27 +10:00
|
|
|
|
2023-06-06 21:58:33 +10:00
|
|
|
export = described_class.new(account).to_muted_accounts_csv
|
2019-04-04 03:17:43 +11:00
|
|
|
results = export.strip.split("\n")
|
2017-04-13 23:29:30 +10:00
|
|
|
|
2019-04-04 03:17:43 +11:00
|
|
|
expect(results.size).to eq 3
|
|
|
|
expect(results.first).to eq 'Account address,Hide notifications'
|
|
|
|
expect(results.second).to eq 'one@local.host,true'
|
2017-04-13 23:29:30 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns a csv of the following accounts' do
|
2023-05-03 18:30:54 +10:00
|
|
|
target_accounts.each { |target_account| account.follow!(target_account) }
|
2017-06-19 19:30:27 +10:00
|
|
|
|
2023-06-06 21:58:33 +10:00
|
|
|
export = described_class.new(account).to_following_accounts_csv
|
2019-04-08 15:28:27 +10:00
|
|
|
results = export.strip.split("\n")
|
2017-04-12 06:00:43 +10:00
|
|
|
|
2019-04-08 15:28:27 +10:00
|
|
|
expect(results.size).to eq 3
|
2022-09-21 07:51:21 +10:00
|
|
|
expect(results.first).to eq 'Account address,Show boosts,Notify on new posts,Languages'
|
|
|
|
expect(results.second).to eq 'one@local.host,true,false,'
|
2017-04-12 06:00:43 +10:00
|
|
|
end
|
|
|
|
end
|
2017-06-19 19:30:27 +10:00
|
|
|
|
|
|
|
describe 'total_storage' do
|
|
|
|
it 'returns the total size of the media attachments' do
|
|
|
|
media_attachment = Fabricate(:media_attachment, account: account)
|
2023-06-06 21:58:33 +10:00
|
|
|
expect(described_class.new(account).total_storage).to eq media_attachment.file_file_size || 0
|
2017-06-19 19:30:27 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'total_follows' do
|
|
|
|
it 'returns the total number of the followed accounts' do
|
2023-05-03 18:30:54 +10:00
|
|
|
target_accounts.each { |target_account| account.follow!(target_account) }
|
2023-06-06 21:58:33 +10:00
|
|
|
expect(described_class.new(account.reload).total_follows).to eq 2
|
2017-06-19 19:30:27 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the total number of the blocked accounts' do
|
2023-05-03 18:30:54 +10:00
|
|
|
target_accounts.each { |target_account| account.block!(target_account) }
|
2023-06-06 21:58:33 +10:00
|
|
|
expect(described_class.new(account.reload).total_blocks).to eq 2
|
2017-06-19 19:30:27 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the total number of the muted accounts' do
|
2023-05-03 18:30:54 +10:00
|
|
|
target_accounts.each { |target_account| account.mute!(target_account) }
|
2023-06-06 21:58:33 +10:00
|
|
|
expect(described_class.new(account.reload).total_mutes).to eq 2
|
2017-06-19 19:30:27 +10:00
|
|
|
end
|
|
|
|
end
|
2017-04-12 06:00:43 +10:00
|
|
|
end
|