Merge pull request #1548 from betagouv/fix-1510
[Fix #1510] Send email after dossier is received
This commit is contained in:
commit
cac3a0c294
2 changed files with 23 additions and 1 deletions
|
@ -69,11 +69,13 @@ module NewUser
|
|||
render :modifier
|
||||
else
|
||||
if @dossier.brouillon?
|
||||
@dossier.en_construction!
|
||||
NotificationMailer.send_notification(@dossier, @dossier.procedure.initiated_mail_template).deliver_now!
|
||||
redirect_to merci_dossier_path(@dossier)
|
||||
else
|
||||
@dossier.en_construction!
|
||||
redirect_to users_dossier_recapitulatif_path(@dossier)
|
||||
end
|
||||
@dossier.en_construction!
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -167,6 +167,20 @@ describe NewUser::DossiersController, type: :controller do
|
|||
expect(dossier.reload.state).to eq('en_construction')
|
||||
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
|
||||
before do
|
||||
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(flash.alert).to eq(['nop']) }
|
||||
|
||||
it 'does not send an email' do
|
||||
expect(NotificationMailer).not_to receive(:send_notification)
|
||||
|
||||
subject
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the pj service returns an error' do
|
||||
|
|
Loading…
Reference in a new issue