2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-11-06 15:15:51 +01:00
|
|
|
describe 'As an administrateur', js: true do
|
2020-11-05 15:09:11 +01:00
|
|
|
let(:super_admin) { create(:super_admin) }
|
2019-08-12 10:35:43 +02:00
|
|
|
let(:admin_email) { 'new_admin@gouv.fr' }
|
2020-01-30 17:08:09 +01:00
|
|
|
let(:new_admin) { Administrateur.by_email(admin_email) }
|
2024-09-17 16:04:48 +02:00
|
|
|
let(:weak_password) { '000000000000' }
|
2021-08-31 18:15:08 +02:00
|
|
|
let(:strong_password) { 'a new, long, and complicated password!' }
|
2019-08-12 10:35:43 +02:00
|
|
|
|
|
|
|
before do
|
2023-04-05 12:36:11 +02:00
|
|
|
body = "{\"hs\": \"agent.educpop.gouv.fr\" }"
|
|
|
|
WebMock.stub_request(:get, /https:\/\/matrix.agent.tchap.gouv.fr\/_matrix\/identity\/api\/v1\/info\?address=(.*)&medium=email/)
|
|
|
|
.to_return(body: body, status: 200)
|
|
|
|
|
2019-08-12 10:35:43 +02:00
|
|
|
perform_enqueued_jobs do
|
2020-11-05 15:09:11 +01:00
|
|
|
super_admin.invite_admin(admin_email)
|
2019-08-12 10:35:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-09-10 23:53:04 +02:00
|
|
|
scenario 'I can register' do
|
2019-11-05 10:05:59 +01:00
|
|
|
expect(new_admin.reload.user.active?).to be(false)
|
2019-10-24 11:41:01 +02:00
|
|
|
|
2019-08-12 10:35:43 +02:00
|
|
|
confirmation_email = open_email(admin_email)
|
|
|
|
token_params = confirmation_email.body.match(/token=[^"]+/)
|
|
|
|
|
|
|
|
visit "admin/activate?#{token_params}"
|
2021-08-31 18:15:08 +02:00
|
|
|
fill_in :administrateur_password, with: weak_password
|
|
|
|
|
|
|
|
expect(page).to have_text('Mot de passe très vulnérable')
|
|
|
|
expect(page).to have_button('Continuer', disabled: true)
|
|
|
|
|
|
|
|
fill_in :administrateur_password, with: strong_password
|
|
|
|
expect(page).to have_text('Mot de passe suffisamment fort et sécurisé')
|
|
|
|
expect(page).to have_button('Continuer', disabled: false)
|
2019-08-12 10:35:43 +02:00
|
|
|
|
|
|
|
click_button 'Continuer'
|
|
|
|
|
|
|
|
expect(page).to have_content 'Mot de passe enregistré'
|
2019-10-24 11:41:01 +02:00
|
|
|
|
2019-11-05 10:05:59 +01:00
|
|
|
expect(new_admin.reload.user.active?).to be(true)
|
2019-08-12 10:35:43 +02:00
|
|
|
end
|
|
|
|
end
|