2023-10-13 10:42:59 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe 'Admin::Accounts' do
|
|
|
|
let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Performing batch updates' do
|
|
|
|
let(:unapproved_user_account) { Fabricate(:account) }
|
|
|
|
let(:approved_user_account) { Fabricate(:account) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
unapproved_user_account.user.update(approved: false)
|
|
|
|
approved_user_account.user.update(approved: true)
|
|
|
|
|
|
|
|
visit admin_accounts_path
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without selecting any accounts' do
|
|
|
|
it 'displays a notice about account selection' do
|
2024-01-04 10:20:32 +01:00
|
|
|
click_on button_for_suspend
|
2023-10-13 10:42:59 +02:00
|
|
|
|
|
|
|
expect(page).to have_content(selection_error_text)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with action of `suspend`' do
|
|
|
|
it 'suspends the account' do
|
|
|
|
batch_checkbox_for(approved_user_account).check
|
|
|
|
|
2024-01-04 10:20:32 +01:00
|
|
|
click_on button_for_suspend
|
2023-10-13 10:42:59 +02:00
|
|
|
|
|
|
|
expect(approved_user_account.reload).to be_suspended
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with action of `approve`' do
|
|
|
|
it 'approves the account user' do
|
|
|
|
batch_checkbox_for(unapproved_user_account).check
|
|
|
|
|
2024-01-04 10:20:32 +01:00
|
|
|
click_on button_for_approve
|
2023-10-13 10:42:59 +02:00
|
|
|
|
|
|
|
expect(unapproved_user_account.reload.user).to be_approved
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-01-10 12:06:58 +01:00
|
|
|
context 'with action of `reject`', :sidekiq_inline do
|
2023-10-13 10:42:59 +02:00
|
|
|
it 'rejects and removes the account' do
|
|
|
|
batch_checkbox_for(unapproved_user_account).check
|
|
|
|
|
2024-01-04 10:20:32 +01:00
|
|
|
click_on button_for_reject
|
2023-10-13 10:42:59 +02:00
|
|
|
|
|
|
|
expect { unapproved_user_account.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def button_for_suspend
|
|
|
|
I18n.t('admin.accounts.perform_full_suspension')
|
|
|
|
end
|
|
|
|
|
|
|
|
def button_for_approve
|
|
|
|
I18n.t('admin.accounts.approve')
|
|
|
|
end
|
|
|
|
|
|
|
|
def button_for_reject
|
|
|
|
I18n.t('admin.accounts.reject')
|
|
|
|
end
|
|
|
|
|
|
|
|
def selection_error_text
|
|
|
|
I18n.t('admin.accounts.no_account_selected')
|
|
|
|
end
|
|
|
|
|
|
|
|
def batch_checkbox_for(account)
|
|
|
|
find("#form_account_batch_account_ids_#{account.id}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|