demarches-normaliennes/spec/system/administrateurs/admin_creation_spec.rb

43 lines
1.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
describe 'As an administrateur', js: true do
let(:super_admin) { create(:super_admin) }
2019-08-12 10:35:43 +02:00
let(:admin_email) { 'new_admin@gouv.fr' }
let(:new_admin) { Administrateur.by_email(admin_email) }
2024-09-17 16:04:48 +02:00
let(:weak_password) { '000000000000' }
let(:strong_password) { 'a new, long, and complicated password!' }
2019-08-12 10:35:43 +02:00
before do
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
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-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}"
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-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