accounts_spec.rb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Admin::Accounts' do
  4. let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  5. before do
  6. sign_in current_user
  7. end
  8. describe 'Performing batch updates' do
  9. let(:unapproved_user_account) { Fabricate(:account) }
  10. let(:approved_user_account) { Fabricate(:account) }
  11. before do
  12. unapproved_user_account.user.update(approved: false)
  13. approved_user_account.user.update(approved: true)
  14. visit admin_accounts_path
  15. end
  16. context 'without selecting any accounts' do
  17. it 'displays a notice about account selection' do
  18. click_on button_for_suspend
  19. expect(page).to have_content(selection_error_text)
  20. end
  21. end
  22. context 'with action of `suspend`' do
  23. it 'suspends the account' do
  24. batch_checkbox_for(approved_user_account).check
  25. click_on button_for_suspend
  26. expect(approved_user_account.reload).to be_suspended
  27. end
  28. end
  29. context 'with action of `approve`' do
  30. it 'approves the account user' do
  31. batch_checkbox_for(unapproved_user_account).check
  32. click_on button_for_approve
  33. expect(unapproved_user_account.reload.user).to be_approved
  34. end
  35. end
  36. context 'with action of `reject`', :inline_jobs do
  37. it 'rejects and removes the account' do
  38. batch_checkbox_for(unapproved_user_account).check
  39. click_on button_for_reject
  40. expect { unapproved_user_account.reload }.to raise_error(ActiveRecord::RecordNotFound)
  41. end
  42. end
  43. def button_for_suspend
  44. I18n.t('admin.accounts.perform_full_suspension')
  45. end
  46. def button_for_approve
  47. I18n.t('admin.accounts.approve')
  48. end
  49. def button_for_reject
  50. I18n.t('admin.accounts.reject')
  51. end
  52. def selection_error_text
  53. I18n.t('admin.accounts.no_account_selected')
  54. end
  55. def batch_checkbox_for(account)
  56. find("#form_account_batch_account_ids_#{account.id}")
  57. end
  58. end
  59. end