test(declarative): clarify intention with pending correction & declarative procedure

This commit is contained in:
Colin Darie 2023-12-11 13:10:25 +01:00
parent c26b59722d
commit 3d21262e89
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
2 changed files with 23 additions and 7 deletions

View file

@ -4,7 +4,7 @@ class ProcessStalledDeclarativeDossierJob < ApplicationJob
case dossier.procedure.declarative_with_state case dossier.procedure.declarative_with_state
when Procedure.declarative_with_states.fetch(:en_instruction) 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! dossier.passer_automatiquement_en_instruction!
end end
when Procedure.declarative_with_states.fetch(:accepte) when Procedure.declarative_with_states.fetch(:accepte)

View file

@ -4,13 +4,12 @@ RSpec.describe ProcessStalledDeclarativeDossierJob, type: :job do
let(:last_operation) { dossier.dossier_operation_logs.last } let(:last_operation) { dossier.dossier_operation_logs.last }
subject(:perform_job) do subject(:perform_job) do
described_class.perform_now(dossier) described_class.perform_now(dossier.reload)
dossier.reload
end end
before do before do
freeze_time freeze_time
perform_job
dossier.reload
end end
context 'declarative en instruction' do 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:) } let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_attestation, procedure:) }
it { it {
perform_job
expect(dossier.state).to eq('en_instruction') expect(dossier.state).to eq('en_instruction')
expect(dossier.en_instruction_at).to eq(Time.current) expect(dossier.en_instruction_at).to eq(Time.current)
expect(last_operation.operation).to eq('passer_en_instruction') 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 context 'dossier repasse en_construction' do
let(:dossier) { create(:dossier, :en_construction, :with_individual, procedure:, declarative_triggered_at: 1.day.ago) } 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
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) } let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure:, en_instruction_at: 2.days.ago) }
it { it {
perform_job
expect(dossier.state).to eq('en_instruction') expect(dossier.state).to eq('en_instruction')
expect(dossier.en_instruction_at).to eq(2.days.ago) expect(dossier.en_instruction_at).to eq(2.days.ago)
expect(dossier.processed_at).to be_nil 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:) } let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_attestation, procedure:) }
it { it {
perform_job
expect(dossier.state).to eq('accepte') expect(dossier.state).to eq('accepte')
expect(dossier.en_instruction_at).to eq(Time.current) expect(dossier.en_instruction_at).to eq(Time.current)
expect(dossier.processed_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) } let(:dossier) { create(:dossier, :en_instruction, :with_individual, procedure:, en_instruction_at: 2.days.ago) }
it { it {
perform_job
expect(dossier.state).to eq('en_instruction') expect(dossier.state).to eq('en_instruction')
expect(dossier.en_instruction_at).to eq(2.days.ago) expect(dossier.en_instruction_at).to eq(2.days.ago)
expect(dossier.processed_at).to be_nil expect(dossier.processed_at).to be_nil
@ -74,6 +89,7 @@ RSpec.describe ProcessStalledDeclarativeDossierJob, type: :job do
let(:dossier) { create(:dossier, :brouillon) } let(:dossier) { create(:dossier, :brouillon) }
it { it {
perform_job
expect(dossier.state).to eq('brouillon') expect(dossier.state).to eq('brouillon')
expect(dossier.en_instruction_at).to be_nil expect(dossier.en_instruction_at).to be_nil
expect(dossier.processed_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) } 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 context 'having etablissement in degraded_mode' do
let(:dossier) { create(:dossier, :en_construction, :with_entreprise, :with_attestation, procedure:, as_degraded_mode: true) } 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) expect(Sentry).to_not receive(:capture_exception)
end end
it { expect(dossier).to be_en_construction } it { expect(subject).to be_en_construction }
end end
end end
end end