From 30df4767910aed10687485783a3e09c1c3f93319 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 6 Jun 2023 10:50:46 +0200 Subject: [PATCH] fix(sva): ensure "en construction" + "en instruction" notifications when submitting at submission MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- app/controllers/users/dossiers_controller.rb | 2 +- .../users/dossiers_controller_spec.rb | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 7fda5b873..6cba4c35a 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -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 diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 2aa3d9da9..5262898b0 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -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 n’avez 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