fix(dossier_transfer): avoid all transfers without valid email

Cf #7621
This commit is contained in:
Colin Darie 2022-08-02 13:01:06 +02:00
parent 8dc966feb4
commit a5d5f4307f
2 changed files with 21 additions and 4 deletions

View file

@ -30,8 +30,14 @@ module Users
end
def transfer_all_dossiers
DossierTransfer.initiate(next_owner_email, current_user.dossiers)
flash.notice = t('.new_transfer', count: current_user.dossiers.count, email: next_owner_email)
transfer = DossierTransfer.initiate(next_owner_email, current_user.dossiers)
if transfer.valid?
flash.notice = t('.new_transfer', count: current_user.dossiers.count, email: next_owner_email)
else
flash.alert = transfer.errors.full_messages
end
redirect_to profil_path
end

View file

@ -133,15 +133,26 @@ describe Users::ProfilController, type: :controller do
let(:next_owner) { 'loulou@lou.com' }
let(:created_transfer) { DossierTransfer.first }
before do
subject {
post :transfer_all_dossiers, params: { next_owner: next_owner }
end
}
before { subject }
it "transfer all dossiers" do
expect(created_transfer.email).to eq(next_owner)
expect(created_transfer.dossiers).to match_array(dossiers)
expect(flash.notice).to eq("Le transfert de 3 dossiers à #{next_owner} est en cours")
end
context "next owner has an empty email" do
let(:next_owner) { '' }
it "should not transfer to an empty email" do
expect { subject }.not_to change { DossierTransfer.count }
expect(flash.alert).to eq(["L'adresse email est invalide"])
end
end
end
context 'POST #accept_merge' do