fix specs

This commit is contained in:
Lisa Durand 2024-07-04 14:25:09 +02:00
parent 67be27e18f
commit 8ff2bbbaab
No known key found for this signature in database
GPG key ID: 0DF91F2CA1E8B816
3 changed files with 18 additions and 16 deletions

View file

@ -227,9 +227,11 @@ module Administrateurs
instructeurs, invalid_emails = groupe_instructeur.add_instructeurs(emails:) instructeurs, invalid_emails = groupe_instructeur.add_instructeurs(emails:)
if invalid_emails.present? if invalid_emails.present?
errors += [t('.wrong_address', errors += [
count: invalid_emails.size, t('.wrong_address',
emails: invalid_emails.join(', '))] count: invalid_emails.size,
emails: invalid_emails.join(', '))
]
end end
if instructeurs.present? if instructeurs.present?

View file

@ -341,7 +341,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
context 'when all emails are valid' do context 'when all emails are valid' do
let(:emails) { ['test@b.gouv.fr', 'test2@b.gouv.fr'].to_json } let(:emails) { ['test@b.gouv.fr', 'test2@b.gouv.fr'].to_json }
it do it do
expect(subject).to redirect_to admin_procedure_groupe_instructeurs_path(procedure_non_routee) expect(subject).to render_template(:index)
expect(subject.request.flash[:alert]).to be_nil expect(subject.request.flash[:alert]).to be_nil
expect(subject.request.flash[:notice]).to be_present expect(subject.request.flash[:notice]).to be_present
end end
@ -350,7 +350,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
context 'when there is at least one bad email' do context 'when there is at least one bad email' do
let(:emails) { ['badmail', 'instructeur2@gmail.com'].to_json } let(:emails) { ['badmail', 'instructeur2@gmail.com'].to_json }
it do it do
expect(subject).to redirect_to admin_procedure_groupe_instructeurs_path(procedure_non_routee) expect(subject).to render_template(:index)
expect(subject.request.flash[:alert]).to be_present expect(subject.request.flash[:alert]).to be_present
expect(subject.request.flash[:notice]).to be_present expect(subject.request.flash[:notice]).to be_present
end end
@ -360,7 +360,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
let(:instructeur) { create(:instructeur) } let(:instructeur) { create(:instructeur) }
before { procedure_non_routee.groupe_instructeurs.first.add_instructeurs(emails: [instructeur.user.email]) } before { procedure_non_routee.groupe_instructeurs.first.add_instructeurs(emails: [instructeur.user.email]) }
let(:emails) { [instructeur.email].to_json } let(:emails) { [instructeur.email].to_json }
it { expect(subject).to redirect_to admin_procedure_groupe_instructeurs_path(procedure_non_routee) } it { expect(subject).to render_template(:index) }
end end
context 'when signed in admin comes from manager' do context 'when signed in admin comes from manager' do
@ -385,7 +385,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
context 'of news instructeurs' do context 'of news instructeurs' do
let!(:user_email_verified) { create(:user, :with_email_verified) } let!(:user_email_verified) { create(:user, :with_email_verified) }
let!(:instructeur_email_verified) { create(:instructeur, user: user_email_verified) } let!(:instructeur_email_verified) { create(:instructeur, user: user_email_verified) }
let(:new_instructeur_emails) { ['new_i1@mail.com', 'new_i2@mail.com', instructeur_email_verified.email] } let(:new_instructeur_emails) { ['new_i1@gmail.com', 'new_i2@gmail.com', instructeur_email_verified.email] }
before do before do
allow(GroupeInstructeurMailer).to receive(:notify_added_instructeurs) allow(GroupeInstructeurMailer).to receive(:notify_added_instructeurs)
@ -398,7 +398,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
it 'validates changes and responses' do it 'validates changes and responses' do
expect(gi_1_2.instructeurs.pluck(:email)).to include(*new_instructeur_emails) expect(gi_1_2.instructeurs.pluck(:email)).to include(*new_instructeur_emails)
expect(flash.notice).to be_present expect(flash.notice).to be_present
expect(response).to redirect_to(admin_procedure_groupe_instructeur_path(procedure, gi_1_2)) expect(response).to render_template(:show)
expect(procedure.routing_enabled?).to be_truthy expect(procedure.routing_enabled?).to be_truthy
expect(GroupeInstructeurMailer).to have_received(:notify_added_instructeurs).with( expect(GroupeInstructeurMailer).to have_received(:notify_added_instructeurs).with(
gi_1_2, gi_1_2,
@ -409,13 +409,13 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
it "calls InstructeurMailer with the right params" do it "calls InstructeurMailer with the right params" do
expect(InstructeurMailer).to have_received(:confirm_and_notify_added_instructeur).with( expect(InstructeurMailer).to have_received(:confirm_and_notify_added_instructeur).with(
User.find_by(email: 'new_i1@mail.com').instructeur, User.find_by(email: 'new_i1@gmail.com').instructeur,
gi_1_2, gi_1_2,
admin.email admin.email
) )
expect(InstructeurMailer).to have_received(:confirm_and_notify_added_instructeur).with( expect(InstructeurMailer).to have_received(:confirm_and_notify_added_instructeur).with(
User.find_by(email: 'new_i2@mail.com').instructeur, User.find_by(email: 'new_i2@gmail.com').instructeur,
gi_1_2, gi_1_2,
admin.email admin.email
) )
@ -425,22 +425,22 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
context 'of an instructeur already in the group' do context 'of an instructeur already in the group' do
let(:new_instructeur_emails) { [instructeur.email] } let(:new_instructeur_emails) { [instructeur.email] }
before { do_request } before { do_request }
it { expect(response).to redirect_to(admin_procedure_groupe_instructeur_path(procedure, gi_1_2)) } it { expect(response).to render_template(:show) }
end end
context 'of badly formed email' do context 'of badly formed email' do
let(:new_instructeur_emails) { ['badly_formed_email'] } let(:new_instructeur_emails) { ['badly_formed_email'] }
before { do_request } before { do_request }
it do it do
expect(flash.alert).to be_present expect(flash.alert).to be_present
expect(response).to redirect_to(admin_procedure_groupe_instructeur_path(procedure, gi_1_2)) expect(response).to render_template(:show)
end end
end end
context 'of an empty string' do context 'of an empty string' do
let(:new_instructeur_emails) { [''] } let(:new_instructeur_emails) { [''] }
before { do_request } before { do_request }
it { expect(response).to redirect_to(admin_procedure_groupe_instructeur_path(procedure, gi_1_2)) } it { expect(response).to render_template(:show) }
end end
context 'when connected as an administrateur from manager' do context 'when connected as an administrateur from manager' do

View file

@ -86,7 +86,7 @@ describe Instructeurs::GroupeInstructeursController, type: :controller do
end end
context 'of a new instructeur' do context 'of a new instructeur' do
let(:new_instructeur_email) { 'new_instructeur@mail.com' } let(:new_instructeur_email) { 'new_instructeur@gmail.com' }
before { subject } before { subject }
it "works" do it "works" do