fix(sva): ensure "en construction" + "en instruction" notifications when submitting at submission

Pour le moment on conserve les 2 emails car l'email en construction
contient des informations spécifiques :
- l'attestation de dépôt
- potentiellement un contenu spécifique car il provient d'un template

Même remarque pour les démarches déclaratives.
This commit is contained in:
Colin Darie 2023-06-06 10:50:46 +02:00
parent 4bdd4310ab
commit 30df476791
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
2 changed files with 23 additions and 4 deletions

View file

@ -185,7 +185,7 @@ module Users
if errors.blank?
@dossier.passer_en_construction!
@dossier.process_declarative!
@dossier.process_sva_svr! # TODO no en construction email if SVA/SVR (and declarative?)
@dossier.process_sva_svr!
NotificationMailer.send_en_construction_notification(@dossier).deliver_later
@dossier.groupe_instructeur.instructeurs.with_instant_email_dossier_notifications.each do |instructeur|
DossierMailer.notify_new_dossier_depose_to_instructeur(@dossier, instructeur.email).deliver_later

View file

@ -1,4 +1,6 @@
describe Users::DossiersController, type: :controller do
include ActiveSupport::Testing::TimeHelpers
let(:user) { create(:user) }
describe 'before_actions' do
@ -351,9 +353,8 @@ describe Users::DossiersController, type: :controller do
let(:payload) { { id: dossier.id } }
subject do
Timecop.freeze(now) do
post :submit_brouillon, params: payload
end
travel_to now
post :submit_brouillon, params: payload
end
context 'when the dossier cannot be updated by the user' do
@ -433,6 +434,24 @@ describe Users::DossiersController, type: :controller do
it { expect(flash.alert).to eq("Vous navez pas accès à ce dossier") }
end
end
context 'when procedure has sva enabled' do
let(:procedure) { create(:procedure, :sva) }
let!(:dossier) { create(:dossier, :brouillon, procedure:, user:) }
it 'passe automatiquement en instruction' do
delivery = double.tap { expect(_1).to receive(:deliver_later).with(no_args).twice }
expect(NotificationMailer).to receive(:send_en_construction_notification).and_return(delivery)
expect(NotificationMailer).to receive(:send_en_instruction_notification).and_return(delivery)
subject
dossier.reload
expect(dossier).to be_en_instruction
expect(dossier.pending_correction?).to be_falsey
expect(dossier.en_instruction_at).to within(5.seconds).of(Time.current)
end
end
end
describe '#submit_en_construction' do