export_spec.rb 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Export do
  4. let(:account) { Fabricate(:account) }
  5. let(:target_accounts) do
  6. [{}, { username: 'one', domain: 'local.host' }].map(&method(:Fabricate).curry(2).call(:account))
  7. end
  8. describe 'to_csv' do
  9. it 'returns a csv of the blocked accounts' do
  10. target_accounts.each { |target_account| account.block!(target_account) }
  11. export = described_class.new(account).to_blocked_accounts_csv
  12. results = export.strip.split
  13. expect(results.size).to eq 2
  14. expect(results.first).to eq 'one@local.host'
  15. end
  16. it 'returns a csv of the muted accounts' do
  17. target_accounts.each { |target_account| account.mute!(target_account) }
  18. export = described_class.new(account).to_muted_accounts_csv
  19. results = export.strip.split("\n")
  20. expect(results.size).to eq 3
  21. expect(results.first).to eq 'Account address,Hide notifications'
  22. expect(results.second).to eq 'one@local.host,true'
  23. end
  24. it 'returns a csv of the following accounts' do
  25. target_accounts.each { |target_account| account.follow!(target_account) }
  26. export = described_class.new(account).to_following_accounts_csv
  27. results = export.strip.split("\n")
  28. expect(results.size).to eq 3
  29. expect(results.first).to eq 'Account address,Show boosts,Notify on new posts,Languages'
  30. expect(results.second).to eq 'one@local.host,true,false,'
  31. end
  32. end
  33. describe 'total_storage' do
  34. it 'returns the total size of the media attachments' do
  35. media_attachment = Fabricate(:media_attachment, account: account)
  36. expect(described_class.new(account).total_storage).to eq media_attachment.file_file_size || 0
  37. end
  38. end
  39. describe 'total_follows' do
  40. it 'returns the total number of the followed accounts' do
  41. target_accounts.each { |target_account| account.follow!(target_account) }
  42. expect(described_class.new(account.reload).total_follows).to eq 2
  43. end
  44. it 'returns the total number of the blocked accounts' do
  45. target_accounts.each { |target_account| account.block!(target_account) }
  46. expect(described_class.new(account.reload).total_blocks).to eq 2
  47. end
  48. it 'returns the total number of the muted accounts' do
  49. target_accounts.each { |target_account| account.mute!(target_account) }
  50. expect(described_class.new(account.reload).total_mutes).to eq 2
  51. end
  52. end
  53. end