simple cases when the preexisting targeted account does not have instructeur or profile profile

This commit is contained in:
simon lehericey 2021-10-04 14:00:32 +02:00
parent c56199e8f7
commit 9a6a53349f
2 changed files with 64 additions and 17 deletions

View file

@ -21,24 +21,54 @@ describe Manager::UsersController, type: :controller do
subject { patch :update, params: { id: user.id, user: { email: nouvel_email } } }
describe 'with a valid email' do
let(:nouvel_email) { 'nouvel.email@domaine.fr' }
context 'when the targeted email does not exist' do
describe 'with a valid email' do
let(:nouvel_email) { 'nouvel.email@domaine.fr' }
it 'updates the user email' do
subject
it 'updates the user email' do
subject
expect(User.find_by(id: user.id).email).to eq(nouvel_email)
expect(User.find_by(id: user.id).email).to eq(nouvel_email)
end
end
describe 'with an invalid email' do
let(:nouvel_email) { 'plop' }
it 'does not update the user email' do
subject
expect(User.find_by(id: user.id).email).not_to eq(nouvel_email)
expect(flash[:error]).to match("Courriel invalide")
end
end
end
describe 'with an invalid email' do
let(:nouvel_email) { 'plop' }
context 'when the targeted email exists' do
let(:preexisting_user) { create(:user, email: 'email.existant@domaine.fr') }
let(:nouvel_email) { preexisting_user.email }
it 'does not update the user email' do
subject
context 'and the old account has a dossier' do
let!(:dossier) { create(:dossier, user: user) }
expect(User.find_by(id: user.id).email).not_to eq(nouvel_email)
expect(flash[:error]).to match("« #{nouvel_email} » nest pas une adresse valide.")
it 'transfers the dossier' do
subject
expect(preexisting_user.dossiers).to match([dossier])
end
end
context 'and the old account belongs to an instructeur and expert' do
let!(:instructeur) { create(:instructeur, user: user) }
let!(:expert) { create(:expert, user: user) }
it 'transfers instructeur account' do
subject
preexisting_user.reload
expect(preexisting_user.instructeur).to match(instructeur)
expect(preexisting_user.expert).to match(expert)
end
end
end
end