Merge pull request #9697 from tchak/fix-repasser_en_instruction-email
fix(dossier): use traitements to send repasser_en_instruction template
This commit is contained in:
commit
2b6cd5068b
7 changed files with 74 additions and 33 deletions
34
app/lib/dossier_with_reference_date.rb
Normal file
34
app/lib/dossier_with_reference_date.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
class DossierWithReferenceDate
|
||||
def self.assign(dossier, state: nil, reference_date: nil)
|
||||
created_at = reference_date.presence || default_created_at(dossier)
|
||||
|
||||
case (state || dossier.state)
|
||||
when Dossier.states.fetch(:en_construction)
|
||||
dossier.created_at = created_at
|
||||
dossier.en_construction_at ||= created_at + 1.minute
|
||||
dossier.depose_at ||= dossier.en_construction_at
|
||||
when Dossier.states.fetch(:en_instruction)
|
||||
assign(dossier, state: Dossier.states.fetch(:en_construction), reference_date: created_at)
|
||||
dossier.en_instruction_at ||= created_at + 2.minutes
|
||||
when Dossier.states.fetch(:accepte), Dossier.states.fetch(:refuse), Dossier.states.fetch(:sans_suite)
|
||||
assign(dossier, state: Dossier.states.fetch(:en_instruction), reference_date: created_at)
|
||||
dossier.processed_at ||= created_at + 3.minutes
|
||||
end
|
||||
end
|
||||
|
||||
def self.default_created_at(dossier)
|
||||
reference_date, delta = case dossier.state
|
||||
when Dossier.states.fetch(:en_construction)
|
||||
[dossier.depose_at || dossier.en_construction_at, 1.minute]
|
||||
when Dossier.states.fetch(:en_instruction)
|
||||
[dossier.en_instruction_at, 2.minutes]
|
||||
when Dossier.states.fetch(:accepte), Dossier.states.fetch(:refuse), Dossier.states.fetch(:sans_suite)
|
||||
[dossier.processed_at, 3.minutes]
|
||||
end
|
||||
if reference_date.present?
|
||||
reference_date - delta
|
||||
else
|
||||
10.minutes.ago
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,6 @@
|
|||
class Dossier < ApplicationRecord
|
||||
self.ignored_columns += [:re_instructed_at]
|
||||
|
||||
include DossierCloneConcern
|
||||
include DossierCorrectableConcern
|
||||
include DossierFilteringConcern
|
||||
|
@ -974,7 +976,6 @@ class Dossier < ApplicationRecord
|
|||
self.sva_svr_decision_on = nil
|
||||
self.motivation = nil
|
||||
self.justificatif_motivation.purge_later
|
||||
self.re_instructed_at = Time.zone.now
|
||||
|
||||
save!
|
||||
rebase_later
|
||||
|
|
|
@ -594,7 +594,11 @@ class Procedure < ApplicationRecord
|
|||
when Dossier.states.fetch(:en_construction)
|
||||
initiated_mail_template
|
||||
when Dossier.states.fetch(:en_instruction)
|
||||
dossier.re_instructed_at.present? ? re_instructed_mail_template : received_mail_template
|
||||
if dossier.traitements.where(state: Dossier.states.fetch(:en_instruction)).one?
|
||||
received_mail_template
|
||||
else
|
||||
re_instructed_mail_template
|
||||
end
|
||||
when Dossier.states.fetch(:accepte)
|
||||
closed_mail_template
|
||||
when Dossier.states.fetch(:refuse)
|
||||
|
|
|
@ -79,7 +79,7 @@ describe API::V1::DossiersController do
|
|||
it do
|
||||
expect(subject[:id]).to eq(dossier.id)
|
||||
expect(subject[:updated_at]).to eq("2008-09-01T08:05:00.000Z")
|
||||
expect(subject[:initiated_at]).to eq("2008-09-01T08:06:00.000Z")
|
||||
expect(subject[:initiated_at]).to eq("2008-09-01T07:56:00.000Z")
|
||||
expect(subject[:state]).to eq("initiated")
|
||||
expect(subject.keys.size).to eq(4)
|
||||
end
|
||||
|
@ -189,7 +189,7 @@ describe API::V1::DossiersController do
|
|||
it do
|
||||
expect(subject[:id]).to eq(dossier.id)
|
||||
expect(subject[:state]).to eq('closed')
|
||||
expect(subject[:created_at]).to eq('2008-09-01T08:05:00.000Z')
|
||||
expect(subject[:created_at]).to eq('2008-09-01T07:55:00.000Z')
|
||||
expect(subject[:updated_at]).to eq('2008-09-01T08:05:00.000Z')
|
||||
expect(subject[:archived]).to eq(dossier.archived)
|
||||
expect(subject.keys).to match_array(field_list)
|
||||
|
|
|
@ -141,8 +141,10 @@ FactoryBot.define do
|
|||
after(:create) do |dossier, _evaluator|
|
||||
dossier.state = Dossier.states.fetch(:en_construction)
|
||||
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
|
||||
dossier.en_construction_at ||= dossier.created_at + 1.minute
|
||||
dossier.depose_at ||= dossier.en_construction_at
|
||||
|
||||
processed_at = DossierWithReferenceDate.assign(dossier)
|
||||
dossier.traitements.passer_en_construction(processed_at:)
|
||||
|
||||
dossier.save!
|
||||
end
|
||||
end
|
||||
|
@ -151,9 +153,10 @@ FactoryBot.define do
|
|||
after(:create) do |dossier, _evaluator|
|
||||
dossier.state = Dossier.states.fetch(:en_instruction)
|
||||
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
|
||||
dossier.en_construction_at ||= dossier.created_at + 1.minute
|
||||
dossier.depose_at ||= dossier.en_construction_at
|
||||
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
|
||||
|
||||
processed_at = DossierWithReferenceDate.assign(dossier)
|
||||
dossier.traitements.passer_en_instruction(processed_at:)
|
||||
|
||||
dossier.save!
|
||||
end
|
||||
end
|
||||
|
@ -166,42 +169,42 @@ FactoryBot.define do
|
|||
after(:create) do |dossier, evaluator|
|
||||
dossier.state = Dossier.states.fetch(:accepte)
|
||||
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
|
||||
if dossier.processed_at.present?
|
||||
dossier.en_construction_at ||= dossier.processed_at - 2.minutes
|
||||
dossier.depose_at ||= dossier.en_construction_at
|
||||
dossier.en_instruction_at ||= dossier.processed_at - 1.minute
|
||||
dossier.traitements.accepter(motivation: evaluator.motivation, processed_at: dossier.processed_at)
|
||||
else
|
||||
dossier.en_construction_at ||= dossier.created_at + 1.minute
|
||||
dossier.depose_at ||= dossier.en_construction_at
|
||||
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
|
||||
dossier.processed_at = dossier.en_instruction_at + 1.minute
|
||||
dossier.traitements.accepter(motivation: evaluator.motivation, processed_at: dossier.processed_at)
|
||||
end
|
||||
|
||||
processed_at = DossierWithReferenceDate.assign(dossier)
|
||||
dossier.traitements.accepter(motivation: evaluator.motivation, processed_at:)
|
||||
|
||||
dossier.save!
|
||||
end
|
||||
end
|
||||
|
||||
trait :refuse do
|
||||
after(:create) do |dossier, _evaluator|
|
||||
transient do
|
||||
motivation { nil }
|
||||
end
|
||||
|
||||
after(:create) do |dossier, evaluator|
|
||||
dossier.state = Dossier.states.fetch(:refuse)
|
||||
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
|
||||
dossier.en_construction_at ||= dossier.created_at + 1.minute
|
||||
dossier.depose_at ||= dossier.en_construction_at
|
||||
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
|
||||
dossier.traitements.refuser(processed_at: dossier.en_instruction_at + 1.minute)
|
||||
|
||||
processed_at = DossierWithReferenceDate.assign(dossier)
|
||||
dossier.traitements.refuser(motivation: evaluator.motivation, processed_at:)
|
||||
|
||||
dossier.save!
|
||||
end
|
||||
end
|
||||
|
||||
trait :sans_suite do
|
||||
after(:create) do |dossier, _evaluator|
|
||||
transient do
|
||||
motivation { nil }
|
||||
end
|
||||
|
||||
after(:create) do |dossier, evaluator|
|
||||
dossier.state = Dossier.states.fetch(:sans_suite)
|
||||
dossier.groupe_instructeur ||= dossier.procedure&.defaut_groupe_instructeur
|
||||
dossier.en_construction_at ||= dossier.created_at + 1.minute
|
||||
dossier.depose_at ||= dossier.en_construction_at
|
||||
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
|
||||
dossier.traitements.classer_sans_suite(processed_at: dossier.en_instruction_at + 1.minute)
|
||||
|
||||
processed_at = DossierWithReferenceDate.assign(dossier)
|
||||
dossier.traitements.classer_sans_suite(motivation: evaluator.motivation, processed_at:)
|
||||
|
||||
dossier.save!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1641,7 +1641,6 @@ describe Dossier, type: :model do
|
|||
|
||||
it { expect(dossier.state).to eq('en_instruction') }
|
||||
it { expect(dossier.archived).to be_falsey }
|
||||
it { expect(dossier.processed_at).to be_nil }
|
||||
it { expect(dossier.motivation).to be_nil }
|
||||
it { expect(dossier.justificatif_motivation.attached?).to be_falsey }
|
||||
it { expect(dossier.attestation).to be_nil }
|
||||
|
|
|
@ -45,7 +45,7 @@ describe Stat, type: :model do
|
|||
|
||||
it 'works' do
|
||||
expect(stats["not_brouillon"]).to eq(18)
|
||||
expect(stats["dossiers_depose_avant_30_jours"]).to eq(2)
|
||||
expect(stats["dossiers_depose_avant_30_jours"]).to eq(15)
|
||||
expect(stats["dossiers_deposes_entre_60_et_30_jours"]).to eq(3)
|
||||
expect(stats["brouillon"]).to eq(1)
|
||||
expect(stats["en_construction"]).to eq(5)
|
||||
|
|
Loading…
Reference in a new issue