Spec Factory: an administrateur always has a gestionnaire
This commit is contained in:
parent
4fafa6e339
commit
f0139c5962
10 changed files with 51 additions and 57 deletions
|
@ -119,4 +119,8 @@ class Administrateur < ApplicationRecord
|
|||
def owns?(procedure)
|
||||
id == procedure.administrateur_id
|
||||
end
|
||||
|
||||
def gestionnaire
|
||||
Gestionnaire.find_by(email: email)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -203,7 +203,7 @@ describe Admin::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when procedure is correctly saved' do
|
||||
let!(:gestionnaire) { create(:gestionnaire, email: admin.email) }
|
||||
let(:gestionnaire) { admin.gestionnaire }
|
||||
|
||||
before do
|
||||
post :create, params: { procedure: procedure_params }
|
||||
|
|
|
@ -7,9 +7,9 @@ describe Gestionnaires::PasswordsController, type: :controller do
|
|||
|
||||
describe "update" do
|
||||
context "unified login" do
|
||||
let(:gestionnaire) { create(:gestionnaire, email: 'unique@plop.com', password: 'un super mot de passe') }
|
||||
let(:user) { create(:user, email: 'unique@plop.com', password: 'un super mot de passe') }
|
||||
let(:administrateur) { create(:administrateur, email: 'unique@plop.com', password: 'un super mot de passe') }
|
||||
let(:gestionnaire) { administrateur.gestionnaire }
|
||||
|
||||
before do
|
||||
@token = gestionnaire.send(:set_reset_password_token)
|
||||
|
|
|
@ -8,12 +8,10 @@ describe Users::PasswordsController, type: :controller do
|
|||
describe "update" do
|
||||
context "unified login" do
|
||||
let(:user) { create(:user, email: 'unique@plop.com', password: 'mot de passe complexe') }
|
||||
let(:gestionnaire) { create(:gestionnaire, email: 'unique@plop.com', password: 'mot de passe complexe') }
|
||||
let(:administrateur) { create(:administrateur, email: 'unique@plop.com', password: 'mot de passe complexe') }
|
||||
|
||||
before do
|
||||
@token = user.send(:set_reset_password_token)
|
||||
gestionnaire # make sure it's created
|
||||
administrateur # make sure it's created
|
||||
end
|
||||
|
||||
|
@ -26,7 +24,7 @@ describe Users::PasswordsController, type: :controller do
|
|||
}
|
||||
}
|
||||
expect(subject.current_user).to eq(user)
|
||||
expect(subject.current_gestionnaire).to eq(gestionnaire)
|
||||
expect(subject.current_gestionnaire.email).to eq(administrateur.email)
|
||||
end
|
||||
|
||||
it "also signs administrateur in" do
|
||||
|
|
|
@ -26,42 +26,37 @@ describe Users::SessionsController, type: :controller do
|
|||
let(:email) { 'unique@plop.com' }
|
||||
let(:password) { 'un super mot de passe' }
|
||||
|
||||
let(:user) { create(:user, email: email, password: password) }
|
||||
let(:gestionnaire) { create(:gestionnaire, :with_trusted_device, email: email, password: password) }
|
||||
let(:administrateur) { create(:administrateur, email: email, password: password) }
|
||||
let!(:user) { create(:user, email: email, password: password) }
|
||||
let!(:administrateur) { create(:administrateur, :with_admin_trusted_device, email: email, password: password) }
|
||||
let(:gestionnaire) { administrateur.gestionnaire }
|
||||
|
||||
it 'signs user in' do
|
||||
post :create, params: { user: { email: user.email, password: user.password } }
|
||||
expect(@response.redirect?).to be(true)
|
||||
post :create, params: { user: { email: email, password: password } }
|
||||
|
||||
expect(subject).to redirect_to link_sent_path(email: email)
|
||||
|
||||
# do not know why, should be test related
|
||||
expect(subject.current_user).to eq(user)
|
||||
|
||||
expect(subject.current_gestionnaire).to be(nil)
|
||||
expect(subject.current_administrateur).to be(nil)
|
||||
expect(user.reload.loged_in_with_france_connect).to be(nil)
|
||||
end
|
||||
|
||||
it 'signs gestionnaire in' do
|
||||
post :create, params: { user: { email: gestionnaire.email, password: gestionnaire.password } }
|
||||
|
||||
expect(subject).to redirect_to link_sent_path(email: gestionnaire.email)
|
||||
expect(subject.current_user).to be(nil)
|
||||
expect(subject.current_gestionnaire).to be(nil)
|
||||
expect(subject.current_administrateur).to be(nil)
|
||||
end
|
||||
|
||||
context 'when the device is trusted' do
|
||||
before do
|
||||
allow(controller).to receive(:trusted_device?).and_return(true)
|
||||
post :create, params: { user: { email: gestionnaire.email, password: gestionnaire.password } }
|
||||
post :create, params: { user: { email: email, password: password } }
|
||||
end
|
||||
|
||||
it 'directly log the gestionnaire' do
|
||||
expect(@response.redirect?).to be(true)
|
||||
expect(subject).not_to redirect_to link_sent_path(email: gestionnaire.email)
|
||||
expect(subject).not_to redirect_to link_sent_path(email: email)
|
||||
# TODO when signing in as non-administrateur, and not starting a demarche, log in to gestionnaire path
|
||||
# expect(subject).to redirect_to gestionnaire_procedures_path
|
||||
expect(subject.current_user).to be(nil)
|
||||
expect(subject.current_user).to eq(user)
|
||||
expect(subject.current_gestionnaire).to eq(gestionnaire)
|
||||
expect(subject.current_administrateur).to be(nil)
|
||||
expect(subject.current_administrateur).to eq(administrateur)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -73,7 +68,8 @@ describe Users::SessionsController, type: :controller do
|
|||
post :create, params: { user: { email: administrateur.email, password: administrateur.password } }
|
||||
|
||||
expect(subject).to redirect_to link_sent_path(email: gestionnaire.email)
|
||||
expect(subject.current_user).to be(nil)
|
||||
|
||||
expect(subject.current_user).to eq(user)
|
||||
expect(subject.current_gestionnaire).to be(nil)
|
||||
expect(subject.current_administrateur).to eq(nil)
|
||||
end
|
||||
|
@ -110,7 +106,6 @@ describe Users::SessionsController, type: :controller do
|
|||
end
|
||||
|
||||
context 'with different passwords' do
|
||||
let!(:gestionnaire) { create(:gestionnaire, email: email, password: 'mot de passe complexe') }
|
||||
let!(:administrateur) { create(:administrateur, email: email, password: 'mot de passe complexe') }
|
||||
|
||||
before do
|
||||
|
@ -193,20 +188,20 @@ describe Users::SessionsController, type: :controller do
|
|||
delete :destroy
|
||||
expect(@response.headers["Location"]).to eq(FRANCE_CONNECT[:particulier][:logout_endpoint])
|
||||
end
|
||||
end
|
||||
|
||||
context "when associated administrateur" do
|
||||
let(:administrateur) { create(:administrateur, email: 'unique@plop.com') }
|
||||
context "when associated administrateur" do
|
||||
let(:administrateur) { create(:administrateur, email: 'unique@plop.com') }
|
||||
|
||||
it 'signs user + gestionnaire + administrateur out' do
|
||||
sign_in user
|
||||
sign_in gestionnaire
|
||||
sign_in administrateur
|
||||
delete :destroy
|
||||
expect(@response.redirect?).to be(true)
|
||||
expect(subject.current_user).to be(nil)
|
||||
expect(subject.current_gestionnaire).to be(nil)
|
||||
expect(subject.current_administrateur).to be(nil)
|
||||
end
|
||||
it 'signs user + gestionnaire + administrateur out' do
|
||||
sign_in user
|
||||
sign_in administrateur.gestionnaire
|
||||
sign_in administrateur
|
||||
delete :destroy
|
||||
expect(@response.redirect?).to be(true)
|
||||
expect(subject.current_user).to be(nil)
|
||||
expect(subject.current_gestionnaire).to be(nil)
|
||||
expect(subject.current_administrateur).to be(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -284,8 +279,8 @@ describe Users::SessionsController, type: :controller do
|
|||
let(:password) { 'un super mot de passe' }
|
||||
|
||||
let!(:user) { create(:user, email: email, password: password) }
|
||||
let!(:gestionnaire) { create(:gestionnaire, email: email, password: password) }
|
||||
let!(:administrateur) { create(:administrateur, email: email, password: password) }
|
||||
let(:gestionnaire) { administrateur.gestionnaire }
|
||||
|
||||
before do
|
||||
post :sign_in_by_link, params: { id: gestionnaire.id, jeton: jeton }
|
||||
|
|
|
@ -3,6 +3,16 @@ FactoryBot.define do
|
|||
factory :administrateur do
|
||||
email { generate(:administrateur_email) }
|
||||
password { 'mon chien aime les bananes' }
|
||||
|
||||
after(:create) do |admin|
|
||||
create(:gestionnaire, email: admin.email, password: admin.password)
|
||||
end
|
||||
end
|
||||
|
||||
trait :with_admin_trusted_device do
|
||||
after(:create) do |admin|
|
||||
admin.gestionnaire.update(features: { "enable_email_login_token" => true })
|
||||
end
|
||||
end
|
||||
|
||||
trait :with_api_token do
|
||||
|
|
|
@ -5,8 +5,7 @@ feature 'Administrator connection' do
|
|||
|
||||
let(:email) { 'admin1@admin.com' }
|
||||
let(:password) { 'mon chien aime les bananes' }
|
||||
let!(:admin) { create(:administrateur, :with_procedure, email: email, password: password) }
|
||||
let!(:gestionnaire) { create(:gestionnaire, :with_trusted_device, email: email, password: password) }
|
||||
let!(:admin) { create(:administrateur, :with_admin_trusted_device, :with_procedure, email: email, password: password) }
|
||||
|
||||
before do
|
||||
visit new_administrateur_session_path
|
||||
|
|
|
@ -116,7 +116,7 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
|
|||
end
|
||||
end
|
||||
|
||||
scenario 'After adding champ and file, check impossibility to publish procedure, add instructeur and make publication' do
|
||||
scenario 'After adding champ and file, make publication' do
|
||||
fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libelle de champ'
|
||||
click_on 'add_type_de_champ'
|
||||
click_on 'onglet-pieces'
|
||||
|
@ -125,17 +125,6 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
|
|||
fill_in 'procedure_types_de_piece_justificative_attributes_0_libelle', with: 'libelle de piece'
|
||||
click_on 'add_piece_justificative'
|
||||
|
||||
click_on 'onglet-infos'
|
||||
expect(page).to have_current_path(admin_procedure_path(Procedure.last))
|
||||
expect(page).to have_selector('#disabled-publish-procedure')
|
||||
expect(page.find_by_id('disabled-publish-procedure')[:disabled]).to eq('true')
|
||||
|
||||
click_on 'onglet-instructeurs'
|
||||
expect(page).to have_current_path(admin_procedure_instructeurs_path(Procedure.last))
|
||||
fill_in 'gestionnaire_email', with: 'gestionnaire@apientreprise.fr'
|
||||
click_on 'add-gestionnaire-email'
|
||||
page.first('.gestionnaire-affectation').click
|
||||
|
||||
click_on 'onglet-infos'
|
||||
expect(page).to have_current_path(admin_procedure_path(Procedure.last))
|
||||
expect(page).to have_selector('#publish-procedure', visible: true)
|
||||
|
|
|
@ -22,7 +22,7 @@ describe Administrateur, type: :model do
|
|||
|
||||
it 'syncs credentials to associated administrateur' do
|
||||
administrateur = create(:administrateur)
|
||||
gestionnaire = create(:gestionnaire, email: administrateur.email)
|
||||
gestionnaire = administrateur.gestionnaire
|
||||
|
||||
administrateur.update(email: 'whoami@plop.com', password: 'et encore un autre mdp')
|
||||
|
||||
|
|
|
@ -149,13 +149,12 @@ describe Gestionnaire, type: :model do
|
|||
end
|
||||
|
||||
it 'syncs credentials to associated administrateur' do
|
||||
gestionnaire = create(:gestionnaire)
|
||||
admin = create(:administrateur, email: gestionnaire.email)
|
||||
admin = create(:administrateur)
|
||||
gestionnaire = admin.gestionnaire
|
||||
|
||||
gestionnaire.update(email: 'whoami@plop.com', password: 'super secret')
|
||||
gestionnaire.update(password: 'super secret')
|
||||
|
||||
admin.reload
|
||||
expect(admin.email).to eq('whoami@plop.com')
|
||||
expect(admin.valid_password?('super secret')).to be(true)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue