Merge pull request #1548 from betagouv/fix-1510

[Fix #1510] Send email after dossier is received
This commit is contained in:
gregoirenovel 2018-03-05 19:19:43 +01:00 committed by GitHub
commit cac3a0c294
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View file

@ -69,11 +69,13 @@ module NewUser
render :modifier render :modifier
else else
if @dossier.brouillon? if @dossier.brouillon?
@dossier.en_construction!
NotificationMailer.send_notification(@dossier, @dossier.procedure.initiated_mail_template).deliver_now!
redirect_to merci_dossier_path(@dossier) redirect_to merci_dossier_path(@dossier)
else else
@dossier.en_construction!
redirect_to users_dossier_recapitulatif_path(@dossier) redirect_to users_dossier_recapitulatif_path(@dossier)
end end
@dossier.en_construction!
end end
end end

View file

@ -167,6 +167,20 @@ describe NewUser::DossiersController, type: :controller do
expect(dossier.reload.state).to eq('en_construction') expect(dossier.reload.state).to eq('en_construction')
end end
it 'sends an email only on the first #update' do
delivery = double
expect(delivery).to receive(:deliver_now!).with(no_args)
expect(NotificationMailer).to receive(:send_notification)
.and_return(delivery)
subject
expect(NotificationMailer).not_to receive(:send_notification)
subject
end
context 'when the update fails' do context 'when the update fails' do
before do before do
expect_any_instance_of(Dossier).to receive(:update).and_return(false) expect_any_instance_of(Dossier).to receive(:update).and_return(false)
@ -178,6 +192,12 @@ describe NewUser::DossiersController, type: :controller do
it { expect(response).to render_template(:modifier) } it { expect(response).to render_template(:modifier) }
it { expect(flash.alert).to eq(['nop']) } it { expect(flash.alert).to eq(['nop']) }
it 'does not send an email' do
expect(NotificationMailer).not_to receive(:send_notification)
subject
end
end end
context 'when the pj service returns an error' do context 'when the pj service returns an error' do