]> cat aescling's git repositories - mastodon.git/blob - spec/controllers/admin/accounts_controller_spec.rb
Add moderation warnings (#9519)
[mastodon.git] / spec / controllers / admin / accounts_controller_spec.rb
1 require 'rails_helper'
2
3 RSpec.describe Admin::AccountsController, type: :controller do
4 render_views
5
6 before { sign_in current_user, scope: :user }
7
8 describe 'GET #index' do
9 let(:current_user) { Fabricate(:user, admin: true) }
10
11 around do |example|
12 default_per_page = Account.default_per_page
13 Account.paginates_per 1
14 example.run
15 Account.paginates_per default_per_page
16 end
17
18 it 'filters with parameters' do
19 new = AccountFilter.method(:new)
20
21 expect(AccountFilter).to receive(:new) do |params|
22 h = params.to_h
23
24 expect(h[:local]).to eq '1'
25 expect(h[:remote]).to eq '1'
26 expect(h[:by_domain]).to eq 'domain'
27 expect(h[:active]).to eq '1'
28 expect(h[:silenced]).to eq '1'
29 expect(h[:suspended]).to eq '1'
30 expect(h[:username]).to eq 'username'
31 expect(h[:display_name]).to eq 'display name'
32 expect(h[:email]).to eq 'local-part@domain'
33 expect(h[:ip]).to eq '0.0.0.42'
34
35 new.call({})
36 end
37
38 get :index, params: {
39 local: '1',
40 remote: '1',
41 by_domain: 'domain',
42 active: '1',
43 silenced: '1',
44 suspended: '1',
45 username: 'username',
46 display_name: 'display name',
47 email: 'local-part@domain',
48 ip: '0.0.0.42'
49 }
50 end
51
52 it 'paginates accounts' do
53 Fabricate(:account)
54
55 get :index, params: { page: 2 }
56
57 accounts = assigns(:accounts)
58 expect(accounts.count).to eq 1
59 expect(accounts.klass).to be Account
60 end
61
62 it 'returns http success' do
63 get :index
64 expect(response).to have_http_status(200)
65 end
66 end
67
68 describe 'GET #show' do
69 let(:current_user) { Fabricate(:user, admin: true) }
70 let(:account) { Fabricate(:account, username: 'bob') }
71
72 it 'returns http success' do
73 get :show, params: { id: account.id }
74 expect(response).to have_http_status(200)
75 end
76 end
77
78 describe 'POST #subscribe' do
79 subject { post :subscribe, params: { id: account.id } }
80
81 let(:current_user) { Fabricate(:user, admin: admin) }
82 let(:account) { Fabricate(:account) }
83
84 context 'when user is admin' do
85 let(:admin) { true }
86
87 it { is_expected.to redirect_to admin_account_path(account.id) }
88 end
89
90 context 'when user is not admin' do
91 let(:admin) { false }
92
93 it { is_expected.to have_http_status :forbidden }
94 end
95 end
96
97 describe 'POST #unsubscribe' do
98 subject { post :unsubscribe, params: { id: account.id } }
99
100 let(:current_user) { Fabricate(:user, admin: admin) }
101 let(:account) { Fabricate(:account) }
102
103 context 'when user is admin' do
104 let(:admin) { true }
105
106 it { is_expected.to redirect_to admin_account_path(account.id) }
107 end
108
109 context 'when user is not admin' do
110 let(:admin) { false }
111
112 it { is_expected.to have_http_status :forbidden }
113 end
114 end
115
116 describe 'POST #memorialize' do
117 subject { post :memorialize, params: { id: account.id } }
118
119 let(:current_user) { Fabricate(:user, admin: current_user_admin) }
120 let(:account) { Fabricate(:account, user: user) }
121 let(:user) { Fabricate(:user, admin: target_user_admin) }
122
123 context 'when user is admin' do
124 let(:current_user_admin) { true }
125
126 context 'when target user is admin' do
127 let(:target_user_admin) { true }
128
129 it 'fails to memorialize account' do
130 is_expected.to have_http_status :forbidden
131 expect(account.reload).not_to be_memorial
132 end
133 end
134
135 context 'when target user is not admin' do
136 let(:target_user_admin) { false }
137
138 it 'succeeds in memorializing account' do
139 is_expected.to redirect_to admin_account_path(account.id)
140 expect(account.reload).to be_memorial
141 end
142 end
143 end
144
145 context 'when user is not admin' do
146 let(:current_user_admin) { false }
147
148 context 'when target user is admin' do
149 let(:target_user_admin) { true }
150
151 it 'fails to memorialize account' do
152 is_expected.to have_http_status :forbidden
153 expect(account.reload).not_to be_memorial
154 end
155 end
156
157 context 'when target user is not admin' do
158 let(:target_user_admin) { false }
159
160 it 'fails to memorialize account' do
161 is_expected.to have_http_status :forbidden
162 expect(account.reload).not_to be_memorial
163 end
164 end
165 end
166 end
167
168 describe 'POST #enable' do
169 subject { post :enable, params: { id: account.id } }
170
171 let(:current_user) { Fabricate(:user, admin: admin) }
172 let(:account) { Fabricate(:account, user: user) }
173 let(:user) { Fabricate(:user, disabled: true) }
174
175 context 'when user is admin' do
176 let(:admin) { true }
177
178 it 'succeeds in enabling account' do
179 is_expected.to redirect_to admin_account_path(account.id)
180 expect(user.reload).not_to be_disabled
181 end
182 end
183
184 context 'when user is not admin' do
185 let(:admin) { false }
186
187 it 'fails to enable account' do
188 is_expected.to have_http_status :forbidden
189 expect(user.reload).to be_disabled
190 end
191 end
192 end
193
194 describe 'POST #redownload' do
195 subject { post :redownload, params: { id: account.id } }
196
197 let(:current_user) { Fabricate(:user, admin: admin) }
198 let(:account) { Fabricate(:account) }
199
200 context 'when user is admin' do
201 let(:admin) { true }
202
203 it 'succeeds in redownloadin' do
204 is_expected.to redirect_to admin_account_path(account.id)
205 end
206 end
207
208 context 'when user is not admin' do
209 let(:admin) { false }
210
211 it 'fails to redownload' do
212 is_expected.to have_http_status :forbidden
213 end
214 end
215 end
216
217 describe 'POST #remove_avatar' do
218 subject { post :remove_avatar, params: { id: account.id } }
219
220 let(:current_user) { Fabricate(:user, admin: admin) }
221 let(:account) { Fabricate(:account) }
222
223 context 'when user is admin' do
224 let(:admin) { true }
225
226 it 'succeeds in removing avatar' do
227 is_expected.to redirect_to admin_account_path(account.id)
228 end
229 end
230
231 context 'when user is not admin' do
232 let(:admin) { false }
233
234 it 'fails to remove avatar' do
235 is_expected.to have_http_status :forbidden
236 end
237 end
238 end
239 end
This page took 0.370607 seconds and 4 git commands to generate.