fix(cron/procedure-declarative): don't auto accept a dossier still in degraded mode

This commit is contained in:
Colin Darie 2022-09-22 16:26:14 +02:00
parent 9b929c86ea
commit 6a4a9c8e03
2 changed files with 39 additions and 13 deletions

View file

@ -640,7 +640,9 @@ class Procedure < ApplicationRecord
dossiers dossiers
.state_en_construction .state_en_construction
.where(declarative_triggered_at: nil) .where(declarative_triggered_at: nil)
.find_each(&:accepter_automatiquement!) .find_each do |dossier|
dossier.accepter_automatiquement! if dossier.may_accepter_automatiquement?
end
end end
end end

View file

@ -12,20 +12,23 @@ RSpec.describe Cron::DeclarativeProceduresJob, type: :job do
let(:dossier_repasse_en_construction) { create(:dossier, :en_construction, :with_individual, procedure: procedure) } let(:dossier_repasse_en_construction) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
before do before do
Timecop.freeze(date) Timecop.freeze(date)
dossier_repasse_en_construction.touch(:declarative_triggered_at) dossier_repasse_en_construction&.touch(:declarative_triggered_at)
dossiers = [ end
nouveau_dossier1,
nouveau_dossier2,
dossier_recu,
dossier_brouillon,
dossier_repasse_en_construction
]
Cron::DeclarativeProceduresJob.new.perform subject(:perform_job) do
dossiers = [
nouveau_dossier1,
nouveau_dossier2,
dossier_recu,
dossier_brouillon,
dossier_repasse_en_construction
].compact
dossiers.each(&:reload) Cron::DeclarativeProceduresJob.new.perform
end
dossiers.each(&:reload)
end
after { Timecop.return } after { Timecop.return }
@ -35,6 +38,7 @@ RSpec.describe Cron::DeclarativeProceduresJob, type: :job do
let(:last_operation) { nouveau_dossier1.dossier_operation_logs.last } let(:last_operation) { nouveau_dossier1.dossier_operation_logs.last }
it { it {
perform_job
expect(nouveau_dossier1.en_instruction?).to be_truthy expect(nouveau_dossier1.en_instruction?).to be_truthy
expect(nouveau_dossier1.en_instruction_at).to eq(date) expect(nouveau_dossier1.en_instruction_at).to eq(date)
expect(last_operation.operation).to eq('passer_en_instruction') expect(last_operation.operation).to eq('passer_en_instruction')
@ -58,6 +62,7 @@ RSpec.describe Cron::DeclarativeProceduresJob, type: :job do
let(:last_operation) { nouveau_dossier1.dossier_operation_logs.last } let(:last_operation) { nouveau_dossier1.dossier_operation_logs.last }
it { it {
perform_job
expect(nouveau_dossier1.accepte?).to be true expect(nouveau_dossier1.accepte?).to be true
expect(nouveau_dossier1.en_instruction_at).to eq(date) expect(nouveau_dossier1.en_instruction_at).to eq(date)
expect(nouveau_dossier1.processed_at).to eq(date) expect(nouveau_dossier1.processed_at).to eq(date)
@ -78,6 +83,25 @@ RSpec.describe Cron::DeclarativeProceduresJob, type: :job do
expect(dossier_brouillon.en_instruction_at).to eq(nil) expect(dossier_brouillon.en_instruction_at).to eq(nil)
expect(dossier_brouillon.processed_at).to eq(nil) expect(dossier_brouillon.processed_at).to eq(nil)
} }
context "having etablissement in degraded_mode" do
let(:procedure) { create(:procedure, :published, :with_instructeur, for_individual: false, declarative_with_state: state) }
let(:nouveau_dossier1) { create(:dossier, :en_construction, :with_entreprise, :with_attestation, procedure: procedure, as_degraded_mode: false) }
let(:nouveau_dossier2) { create(:dossier, :en_construction, :with_entreprise, :with_attestation, procedure: procedure, as_degraded_mode: true) }
let(:dossier_recu) { nil }
let(:dossier_repasse_en_construction) { nil }
before do
expect(nouveau_dossier2).to_not receive(:accepter_automatiquement)
expect(Sentry).to_not receive(:capture_exception)
end
it {
perform_job
expect(nouveau_dossier1).to be_accepte
expect(nouveau_dossier2).to be_en_construction
}
end
end end
end end
end end