Merge pull request #8285 from tchak/fix-passer-automatiquement-en-instruction
fix(dossier): authorize passage en instruction if auto archive is on and is in the past
This commit is contained in:
commit
b359b3aa9f
4 changed files with 88 additions and 16 deletions
|
@ -537,11 +537,11 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_accepter_automatiquement?
|
def can_accepter_automatiquement?
|
||||||
declarative_triggered_at.nil? && can_terminer?
|
declarative_triggered_at.nil? && procedure.declarative_accepte? && can_terminer?
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_passer_automatiquement_en_instruction?
|
def can_passer_automatiquement_en_instruction?
|
||||||
declarative_triggered_at.nil?
|
(declarative_triggered_at.nil? && procedure.declarative_en_instruction?) || procedure.auto_archive_on&.then { _1 <= Time.zone.today }
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_repasser_en_instruction?
|
def can_repasser_en_instruction?
|
||||||
|
|
|
@ -56,6 +56,18 @@ FactoryBot.define do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_declarative_accepte do
|
||||||
|
after(:build) do |dossier, _evaluator|
|
||||||
|
dossier.procedure.declarative_with_state = 'accepte'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
trait :with_declarative_en_instruction do
|
||||||
|
after(:build) do |dossier, _evaluator|
|
||||||
|
dossier.procedure.declarative_with_state = 'en_instruction'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
trait :archived do
|
trait :archived do
|
||||||
archived { true }
|
archived { true }
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,15 +17,15 @@ RSpec.describe Cron::AutoArchiveProcedureJob, type: :job do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when procedures have auto_archive_on set on yesterday or today" do
|
context "when procedures have auto_archive_on set on yesterday or today" do
|
||||||
let!(:dossier1) { create(:dossier, procedure: procedure_hier, state: Dossier.states.fetch(:brouillon), archived: false) }
|
let!(:dossier1) { create(:dossier, procedure: procedure_hier) }
|
||||||
let!(:dossier2) { create(:dossier, procedure: procedure_hier, state: Dossier.states.fetch(:en_construction), archived: false) }
|
let!(:dossier2) { create(:dossier, :en_construction, procedure: procedure_hier) }
|
||||||
let!(:dossier3) { create(:dossier, procedure: procedure_hier, state: Dossier.states.fetch(:en_construction), archived: false) }
|
let!(:dossier3) { create(:dossier, :en_construction, procedure: procedure_hier) }
|
||||||
let!(:dossier4) { create(:dossier, procedure: procedure_hier, state: Dossier.states.fetch(:en_construction), archived: false) }
|
let!(:dossier4) { create(:dossier, :en_construction, procedure: procedure_hier) }
|
||||||
let!(:dossier5) { create(:dossier, procedure: procedure_hier, state: Dossier.states.fetch(:en_instruction), archived: false) }
|
let!(:dossier5) { create(:dossier, :en_instruction, procedure: procedure_hier) }
|
||||||
let!(:dossier6) { create(:dossier, procedure: procedure_hier, state: Dossier.states.fetch(:accepte), archived: false) }
|
let!(:dossier6) { create(:dossier, :accepte, procedure: procedure_hier) }
|
||||||
let!(:dossier7) { create(:dossier, procedure: procedure_hier, state: Dossier.states.fetch(:refuse), archived: false) }
|
let!(:dossier7) { create(:dossier, :refuse, procedure: procedure_hier) }
|
||||||
let!(:dossier8) { create(:dossier, procedure: procedure_hier, state: Dossier.states.fetch(:sans_suite), archived: false) }
|
let!(:dossier8) { create(:dossier, :sans_suite, procedure: procedure_hier) }
|
||||||
let!(:dossier9) { create(:dossier, procedure: procedure_aujourdhui, state: Dossier.states.fetch(:en_construction), archived: false) }
|
let!(:dossier9) { create(:dossier, :en_construction, procedure: procedure_aujourdhui) }
|
||||||
let(:last_operation) { dossier2.dossier_operation_logs.last }
|
let(:last_operation) { dossier2.dossier_operation_logs.last }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|
|
@ -1052,7 +1052,7 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#accepter_automatiquement!' do
|
describe '#accepter_automatiquement!' do
|
||||||
let(:dossier) { create(:dossier, :en_construction, :with_individual) }
|
let(:dossier) { create(:dossier, :en_construction, :with_individual, :with_declarative_accepte) }
|
||||||
let(:last_operation) { dossier.dossier_operation_logs.last }
|
let(:last_operation) { dossier.dossier_operation_logs.last }
|
||||||
let!(:now) { Time.zone.parse('01/01/2100') }
|
let!(:now) { Time.zone.parse('01/01/2100') }
|
||||||
let(:attestation) { Attestation.new }
|
let(:attestation) { Attestation.new }
|
||||||
|
@ -1097,7 +1097,7 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#passer_automatiquement_en_instruction!' do
|
describe '#passer_automatiquement_en_instruction!' do
|
||||||
let(:dossier) { create(:dossier, :en_construction, en_construction_close_to_expiration_notice_sent_at: Time.zone.now) }
|
let(:dossier) { create(:dossier, :en_construction, :with_declarative_en_instruction, en_construction_close_to_expiration_notice_sent_at: Time.zone.now) }
|
||||||
let(:last_operation) { dossier.dossier_operation_logs.last }
|
let(:last_operation) { dossier.dossier_operation_logs.last }
|
||||||
let(:operation_serialized) { last_operation.data }
|
let(:operation_serialized) { last_operation.data }
|
||||||
let(:instructeur) { create(:instructeur) }
|
let(:instructeur) { create(:instructeur) }
|
||||||
|
@ -1113,6 +1113,66 @@ describe Dossier do
|
||||||
it { expect(operation_serialized['executed_at']).to eq(last_operation.executed_at.iso8601) }
|
it { expect(operation_serialized['executed_at']).to eq(last_operation.executed_at.iso8601) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#can_passer_automatiquement_en_instruction?' do
|
||||||
|
let(:dossier) { create(:dossier, :en_construction, declarative_triggered_at: declarative_triggered_at) }
|
||||||
|
let(:declarative_triggered_at) { nil }
|
||||||
|
|
||||||
|
it { expect(dossier.can_passer_automatiquement_en_instruction?).to be_falsey }
|
||||||
|
|
||||||
|
context 'when dossier is declarative' do
|
||||||
|
before { dossier.procedure.update(declarative_with_state: :en_instruction) }
|
||||||
|
|
||||||
|
context 'when dossier never transitioned' do
|
||||||
|
it { expect(dossier.can_passer_automatiquement_en_instruction?).to be_truthy }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when dossier transitioned before' do
|
||||||
|
let(:declarative_triggered_at) { 1.day.ago }
|
||||||
|
|
||||||
|
it { expect(dossier.can_passer_automatiquement_en_instruction?).to be_falsey }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when procedure has auto archive set' do
|
||||||
|
before { dossier.procedure.update(auto_archive_on: 1.day.ago) }
|
||||||
|
|
||||||
|
it { expect(dossier.can_passer_automatiquement_en_instruction?).to be_truthy }
|
||||||
|
|
||||||
|
context 'when auto_archive_on is in the future' do
|
||||||
|
before { dossier.procedure.update(auto_archive_on: 1.day.from_now) }
|
||||||
|
|
||||||
|
it { expect(dossier.can_passer_automatiquement_en_instruction?).to be_falsey }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when dossier transitioned before' do
|
||||||
|
let(:declarative_triggered_at) { 1.day.ago }
|
||||||
|
|
||||||
|
it { expect(dossier.can_passer_automatiquement_en_instruction?).to be_truthy }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#can_accepter_automatiquement?' do
|
||||||
|
let(:dossier) { create(:dossier, :en_instruction, declarative_triggered_at: declarative_triggered_at) }
|
||||||
|
let(:declarative_triggered_at) { nil }
|
||||||
|
|
||||||
|
it { expect(dossier.can_accepter_automatiquement?).to be_falsey }
|
||||||
|
|
||||||
|
context 'when dossier is declarative' do
|
||||||
|
before { dossier.procedure.update(declarative_with_state: :accepte) }
|
||||||
|
|
||||||
|
context 'when dossier never transitioned' do
|
||||||
|
it { expect(dossier.can_accepter_automatiquement?).to be_truthy }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when dossier transitioned before' do
|
||||||
|
let(:declarative_triggered_at) { 1.day.ago }
|
||||||
|
|
||||||
|
it { expect(dossier.can_accepter_automatiquement?).to be_falsey }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "can't transition to terminer when etablissement is in degraded mode" do
|
describe "can't transition to terminer when etablissement is in degraded mode" do
|
||||||
let(:instructeur) { create(:instructeur) }
|
let(:instructeur) { create(:instructeur) }
|
||||||
let(:motivation) { 'motivation' }
|
let(:motivation) { 'motivation' }
|
||||||
|
@ -1138,8 +1198,8 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when dossier is en_construction" do
|
context "when dossier is en_construction" do
|
||||||
let(:dossier_incomplete) { create(:dossier, :en_construction, :with_entreprise, as_degraded_mode: true) }
|
let(:dossier_incomplete) { create(:dossier, :en_construction, :with_entreprise, :with_declarative_accepte, as_degraded_mode: true) }
|
||||||
let(:dossier_ok) { create(:dossier, :en_construction, :with_entreprise, as_degraded_mode: false) }
|
let(:dossier_ok) { create(:dossier, :en_construction, :with_entreprise, :with_declarative_accepte, as_degraded_mode: false) }
|
||||||
|
|
||||||
it "can't accepter_automatiquement" do
|
it "can't accepter_automatiquement" do
|
||||||
expect(dossier_incomplete.may_accepter_automatiquement?(instructeur:, motivation:)).to be_falsey
|
expect(dossier_incomplete.may_accepter_automatiquement?(instructeur:, motivation:)).to be_falsey
|
||||||
|
@ -1613,7 +1673,7 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'en_construction' do
|
context 'en_construction' do
|
||||||
let(:dossier) { create(:dossier, :en_construction, :followed, :with_individual) }
|
let(:dossier) { create(:dossier, :en_construction, :followed, :with_individual, :with_declarative_accepte) }
|
||||||
|
|
||||||
it "clean up titres identite on accepter_automatiquement" do
|
it "clean up titres identite on accepter_automatiquement" do
|
||||||
expect(champ_titre_identite.piece_justificative_file.attached?).to be_truthy
|
expect(champ_titre_identite.piece_justificative_file.attached?).to be_truthy
|
||||||
|
|
Loading…
Reference in a new issue