~cytrogen/masto-fe

ref: 685270f3f7ea6d4a8a48ec641e8fdfd9fc2e2d7f masto-fe/spec/requests/api/v1/profiles_spec.rb -rw-r--r-- 2.5 KiB
685270f3 — Claire [Glitch] Fix clicking “Explore” or “Live feeds” column headers to scroll in advanced mode 2 years ago
                                                                                
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Deleting profile images' do
  let(:account) do
    Fabricate(
      :account,
      avatar: fixture_file_upload('avatar.gif', 'image/gif'),
      header: fixture_file_upload('attachment.jpg', 'image/jpeg')
    )
  end
  let(:token)   { Fabricate(:accessible_access_token, resource_owner_id: account.user.id, scopes: scopes) }
  let(:scopes)  { 'write:accounts' }
  let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }

  describe 'DELETE /api/v1/profile' do
    before do
      allow(ActivityPub::UpdateDistributionWorker).to receive(:perform_async)
    end

    context 'when deleting an avatar' do
      context 'with wrong scope' do
        before do
          delete '/api/v1/profile/avatar', headers: headers
        end

        it_behaves_like 'forbidden for wrong scope', 'read'
      end

      it 'returns http success' do
        delete '/api/v1/profile/avatar', headers: headers

        expect(response).to have_http_status(200)
      end

      it 'deletes the avatar' do
        delete '/api/v1/profile/avatar', headers: headers

        account.reload

        expect(account.avatar).to_not exist
      end

      it 'does not delete the header' do
        delete '/api/v1/profile/avatar', headers: headers

        account.reload

        expect(account.header).to exist
      end

      it 'queues up an account update distribution' do
        delete '/api/v1/profile/avatar', headers: headers

        expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
      end
    end

    context 'when deleting a header' do
      context 'with wrong scope' do
        before do
          delete '/api/v1/profile/header', headers: headers
        end

        it_behaves_like 'forbidden for wrong scope', 'read'
      end

      it 'returns http success' do
        delete '/api/v1/profile/header', headers: headers

        expect(response).to have_http_status(200)
      end

      it 'does not delete the avatar' do
        delete '/api/v1/profile/header', headers: headers

        account.reload

        expect(account.avatar).to exist
      end

      it 'deletes the header' do
        delete '/api/v1/profile/header', headers: headers

        account.reload

        expect(account.header).to_not exist
      end

      it 'queues up an account update distribution' do
        delete '/api/v1/profile/header', headers: headers

        expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
      end
    end
  end
end