diff --git a/app/jobs/process_stalled_declarative_dossier_job.rb b/app/jobs/process_stalled_declarative_dossier_job.rb index cead75d26..1e2481688 100644 --- a/app/jobs/process_stalled_declarative_dossier_job.rb +++ b/app/jobs/process_stalled_declarative_dossier_job.rb @@ -4,7 +4,7 @@ class ProcessStalledDeclarativeDossierJob < ApplicationJob case dossier.procedure.declarative_with_state when Procedure.declarative_with_states.fetch(:en_instruction) - if !dossier.en_instruction? + if !dossier.en_instruction? && dossier.may_passer_automatiquement_en_instruction? dossier.passer_automatiquement_en_instruction! end when Procedure.declarative_with_states.fetch(:accepte) diff --git a/spec/jobs/process_stalled_declarative_dossier_job_spec.rb b/spec/jobs/process_stalled_declarative_dossier_job_spec.rb index 89ca96e19..b481f0989 100644 --- a/spec/jobs/process_stalled_declarative_dossier_job_spec.rb +++ b/spec/jobs/process_stalled_declarative_dossier_job_spec.rb @@ -4,13 +4,12 @@ RSpec.describe ProcessStalledDeclarativeDossierJob, type: :job do let(:last_operation) { dossier.dossier_operation_logs.last } subject(:perform_job) do - described_class.perform_now(dossier) + described_class.perform_now(dossier.reload) + dossier.reload end before do freeze_time - perform_job - dossier.reload end context 'declarative en instruction' do @@ -20,6 +19,7 @@ RSpec.describe ProcessStalledDeclarativeDossierJob, type: :job do let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_attestation, procedure:) } it { + perform_job expect(dossier.state).to eq('en_instruction') expect(dossier.en_instruction_at).to eq(Time.current) expect(last_operation.operation).to eq('passer_en_instruction') @@ -29,7 +29,19 @@ RSpec.describe ProcessStalledDeclarativeDossierJob, type: :job do context 'dossier repasse en_construction' do let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure:, declarative_triggered_at: 1.day.ago) } - it { expect(dossier.state).to eq('en_construction') } + it { expect(subject.state).to eq('en_construction') } + end + + context 'with pending correction' do + let!(:correction) { create(:dossier_correction, dossier:) } + + it { expect(subject.state).to eq('en_construction') } + end + + context 'with resolved correction' do + let!(:correction) { create(:dossier_correction, :resolved, dossier:) } + + it { expect(subject.state).to eq('en_instruction') } end end @@ -37,6 +49,7 @@ RSpec.describe ProcessStalledDeclarativeDossierJob, type: :job do let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure:, en_instruction_at: 2.days.ago) } it { + perform_job expect(dossier.state).to eq('en_instruction') expect(dossier.en_instruction_at).to eq(2.days.ago) expect(dossier.processed_at).to be_nil @@ -51,6 +64,7 @@ RSpec.describe ProcessStalledDeclarativeDossierJob, type: :job do let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_attestation, procedure:) } it { + perform_job expect(dossier.state).to eq('accepte') expect(dossier.en_instruction_at).to eq(Time.current) expect(dossier.processed_at).to eq(Time.current) @@ -64,6 +78,7 @@ RSpec.describe ProcessStalledDeclarativeDossierJob, type: :job do let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure:, en_instruction_at: 2.days.ago) } it { + perform_job expect(dossier.state).to eq('en_instruction') expect(dossier.en_instruction_at).to eq(2.days.ago) expect(dossier.processed_at).to be_nil @@ -74,6 +89,7 @@ RSpec.describe ProcessStalledDeclarativeDossierJob, type: :job do let(:dossier) { create(:dossier, :brouillon) } it { + perform_job expect(dossier.state).to eq('brouillon') expect(dossier.en_instruction_at).to be_nil expect(dossier.processed_at).to be_nil @@ -85,7 +101,7 @@ RSpec.describe ProcessStalledDeclarativeDossierJob, type: :job do let(:dossier) { create(:dossier, :en_construction, :with_entreprise, :with_attestation, procedure:, as_degraded_mode: false) } - it { expect(dossier).to be_accepte } + it { expect(subject).to be_accepte } context 'having etablissement in degraded_mode' do let(:dossier) { create(:dossier, :en_construction, :with_entreprise, :with_attestation, procedure:, as_degraded_mode: true) } @@ -95,7 +111,7 @@ RSpec.describe ProcessStalledDeclarativeDossierJob, type: :job do expect(Sentry).to_not receive(:capture_exception) end - it { expect(dossier).to be_en_construction } + it { expect(subject).to be_en_construction } end end end