Merge branch 'dev'
This commit is contained in:
commit
8f0e87f29b
3 changed files with 26 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
|
||||
|
||||
|
|
|
@ -106,13 +106,16 @@ class Users::DossiersController < UsersController
|
|||
update_current_user_siret!(siret)
|
||||
|
||||
etablissement_attributes = SIRETService.fetch(siret, @facade.dossier)
|
||||
Rails.logger.info("etablissement_attributes for siret: #{siret}, present?: #{etablissement_attributes.present?}")
|
||||
|
||||
if etablissement_attributes.present?
|
||||
etablissement_attributes = ActionController::Parameters.new(etablissement_attributes).permit!
|
||||
etablissement = @facade.dossier.create_etablissement(etablissement_attributes)
|
||||
if etablissement.save
|
||||
Rails.logger.info("etablissement saved, siret: #{siret}, id: #{etablissement.id}")
|
||||
@facade.dossier.mandataire_social!(current_user.france_connect_information)
|
||||
else
|
||||
Rails.logger.info("etablissement not saved, siret: #{siret}, errors: #{etablissement.errors.full_messages}")
|
||||
return errors_valid_siret
|
||||
end
|
||||
else
|
||||
|
|
|
@ -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