about summary refs log tree commit diff
path: root/spec/models/export_spec.rb
blob: 5202ae9e1758822e6f7bb5a90e69c8eba2422b62 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'rails_helper'

describe Export do
  let(:account) { Fabricate(:account) }
  let(:target_accounts) do
    [{}, { username: 'one', domain: 'local.host' }].map(&method(:Fabricate).curry(2).call(:account))
  end

  describe 'to_csv' do
    it 'returns a csv of the blocked accounts' do
      target_accounts.each(&account.method(:block!))

      export = Export.new(account).to_blocked_accounts_csv
      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
      target_accounts.each(&account.method(:mute!))

      export = Export.new(account).to_muted_accounts_csv
      results = export.strip.split("\n")

      expect(results.size).to eq 3
      expect(results.first).to eq 'Account address,Hide notifications'
      expect(results.second).to eq 'one@local.host,true'
    end

    it 'returns a csv of the following accounts' do
      target_accounts.each(&account.method(:follow!))

      export = Export.new(account).to_following_accounts_csv
      results = export.strip.split("\n")

      expect(results.size).to eq 3
      expect(results.first).to eq 'Account address,Show boosts,Notify on new posts,Languages'
      expect(results.second).to eq 'one@local.host,true,false,'
    end
  end

  describe 'total_storage' do
    it 'returns the total size of the media attachments' do
      media_attachment = Fabricate(:media_attachment, account: account)
      expect(Export.new(account).total_storage).to eq media_attachment.file_file_size || 0
    end
  end

  describe 'total_follows' do
    it 'returns the total number of the followed accounts' do
      target_accounts.each(&account.method(:follow!))
      expect(Export.new(account.reload).total_follows).to eq 2
    end

    it 'returns the total number of the blocked accounts' do
      target_accounts.each(&account.method(:block!))
      expect(Export.new(account.reload).total_blocks).to eq 2
    end

    it 'returns the total number of the muted accounts' do
      target_accounts.each(&account.method(:mute!))
      expect(Export.new(account.reload).total_mutes).to eq 2
    end
  end
end