2021-08-26 14:52:31 +02:00
|
|
|
describe Manager::AdministrateursController, type: :controller do
|
2020-11-05 15:09:11 +01:00
|
|
|
let(:super_admin) { create(:super_admin) }
|
2024-06-01 22:50:48 +02:00
|
|
|
let(:administrateur) { administrateurs(:default_admin) }
|
2018-01-17 10:28:59 +01:00
|
|
|
|
2020-02-18 16:43:05 +01:00
|
|
|
before do
|
2020-11-05 15:09:11 +01:00
|
|
|
sign_in super_admin
|
2020-02-18 16:43:05 +01:00
|
|
|
end
|
|
|
|
|
2020-03-26 16:17:07 +01:00
|
|
|
describe '#show' do
|
2020-11-04 16:35:15 +01:00
|
|
|
let(:subject) { get :show, params: { id: administrateur.id } }
|
2020-03-26 16:17:07 +01:00
|
|
|
|
2020-11-04 16:35:15 +01:00
|
|
|
context 'with 2FA not enabled' do
|
2020-11-05 15:09:11 +01:00
|
|
|
let(:super_admin) { create(:super_admin, otp_required_for_login: false) }
|
|
|
|
it { expect(subject).to redirect_to(edit_super_admin_otp_path) }
|
2020-03-26 16:17:07 +01:00
|
|
|
end
|
|
|
|
|
2020-11-04 16:35:15 +01:00
|
|
|
context 'with 2FA enabled' do
|
|
|
|
render_views
|
2020-11-05 15:09:11 +01:00
|
|
|
let(:super_admin) { create(:super_admin, otp_required_for_login: true) }
|
2020-11-04 16:35:15 +01:00
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(response.body).to include(administrateur.email) }
|
|
|
|
end
|
2020-03-26 16:17:07 +01:00
|
|
|
end
|
|
|
|
|
2020-02-18 16:41:56 +01:00
|
|
|
describe 'GET #new' do
|
|
|
|
render_views
|
|
|
|
it 'displays form to create a new admin' do
|
|
|
|
get :new
|
2020-06-29 17:48:01 +02:00
|
|
|
expect(response).to have_http_status(:success)
|
2020-02-18 16:41:56 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-17 10:28:59 +01:00
|
|
|
describe 'POST #create' do
|
|
|
|
let(:email) { 'plop@plop.com' }
|
2023-03-03 14:16:15 +01:00
|
|
|
let(:password) { SECURE_PASSWORD }
|
2018-01-17 10:28:59 +01:00
|
|
|
|
2018-01-23 18:16:44 +01:00
|
|
|
subject { post :create, params: { administrateur: { email: email } } }
|
2018-01-17 10:28:59 +01:00
|
|
|
|
|
|
|
context 'when email and password are correct' do
|
|
|
|
it 'add new administrateur in database' do
|
|
|
|
expect { subject }.to change(Administrateur, :count).by(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'alert new mail are send' do
|
|
|
|
expect(AdministrationMailer).to receive(:invite_admin).and_return(AdministrationMailer)
|
2018-05-25 18:05:28 +02:00
|
|
|
expect(AdministrationMailer).to receive(:deliver_later)
|
2018-01-17 10:28:59 +01:00
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when email or password are missing' do
|
|
|
|
let(:email) { '' }
|
|
|
|
|
|
|
|
it { expect { subject }.to change(Administrateur, :count).by(0) }
|
|
|
|
end
|
|
|
|
end
|
2019-08-19 10:47:37 +02:00
|
|
|
|
|
|
|
describe '#delete' do
|
2020-03-26 16:17:07 +01:00
|
|
|
subject { delete :delete, params: { id: administrateur.id } }
|
2019-08-19 10:47:37 +02:00
|
|
|
|
|
|
|
it 'deletes the admin' do
|
|
|
|
subject
|
|
|
|
|
2020-03-26 16:17:07 +01:00
|
|
|
expect(Administrateur.find_by(id: administrateur.id)).to be_nil
|
2019-08-19 10:47:37 +02:00
|
|
|
end
|
|
|
|
end
|
2020-02-18 17:40:30 +01:00
|
|
|
|
|
|
|
describe '#index' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
it 'searches admin by email' do
|
2020-03-26 16:17:07 +01:00
|
|
|
get :index, params: { search: administrateur.email }
|
2020-06-29 17:48:01 +02:00
|
|
|
expect(response).to have_http_status(:success)
|
2020-02-18 17:40:30 +01:00
|
|
|
end
|
|
|
|
end
|
2018-01-17 10:28:59 +01:00
|
|
|
end
|