Merge pull request #2678 from betagouv/frederic/fix_2550-attestations_demarche_declarative
Attestations demarche declarative
This commit is contained in:
commit
526bd28cdc
2 changed files with 16 additions and 10 deletions
|
@ -3,22 +3,25 @@ class AutoReceiveDossiersForProcedureJob < ApplicationJob
|
||||||
|
|
||||||
def perform(procedure_id, state)
|
def perform(procedure_id, state)
|
||||||
procedure = Procedure.find(procedure_id)
|
procedure = Procedure.find(procedure_id)
|
||||||
attrs = case state
|
case state
|
||||||
when Dossier.states.fetch(:en_instruction)
|
when Dossier.states.fetch(:en_instruction)
|
||||||
{
|
procedure.dossiers.state_en_construction.update_all(
|
||||||
state: Dossier.states.fetch(:en_instruction),
|
state: Dossier.states.fetch(:en_instruction),
|
||||||
en_instruction_at: DateTime.now
|
en_instruction_at: DateTime.now
|
||||||
}
|
)
|
||||||
when Dossier.states.fetch(:accepte)
|
when Dossier.states.fetch(:accepte)
|
||||||
{
|
procedure.dossiers.state_en_construction.find_each do |dossier|
|
||||||
state: Dossier.states.fetch(:accepte),
|
dossier.update(
|
||||||
en_instruction_at: DateTime.now,
|
state: Dossier.states.fetch(:accepte),
|
||||||
processed_at: DateTime.now
|
en_instruction_at: DateTime.now,
|
||||||
}
|
processed_at: DateTime.now
|
||||||
|
)
|
||||||
|
dossier.attestation = dossier.build_attestation
|
||||||
|
dossier.save
|
||||||
|
NotificationMailer.send_closed_notification(dossier).deliver_later
|
||||||
|
end
|
||||||
else
|
else
|
||||||
raise "Receiving Procedure##{procedure_id} in invalid state \"#{state}\""
|
raise "Receiving Procedure##{procedure_id} in invalid state \"#{state}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
procedure.dossiers.state_en_construction.update_all(attrs)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,7 @@ RSpec.describe AutoReceiveDossiersForProcedureJob, type: :job do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Timecop.freeze(date)
|
Timecop.freeze(date)
|
||||||
|
create(:attestation_template, procedure: nouveau_dossier1.procedure)
|
||||||
AutoReceiveDossiersForProcedureJob.new.perform(procedure_id, state)
|
AutoReceiveDossiersForProcedureJob.new.perform(procedure_id, state)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,10 +42,12 @@ RSpec.describe AutoReceiveDossiersForProcedureJob, type: :job do
|
||||||
it { expect(nouveau_dossier1.reload.accepte?).to be true }
|
it { expect(nouveau_dossier1.reload.accepte?).to be true }
|
||||||
it { expect(nouveau_dossier1.reload.en_instruction_at).to eq(date) }
|
it { expect(nouveau_dossier1.reload.en_instruction_at).to eq(date) }
|
||||||
it { expect(nouveau_dossier1.reload.processed_at).to eq(date) }
|
it { expect(nouveau_dossier1.reload.processed_at).to eq(date) }
|
||||||
|
it { expect(nouveau_dossier1.reload.attestation).to be_present }
|
||||||
|
|
||||||
it { expect(nouveau_dossier2.reload.accepte?).to be true }
|
it { expect(nouveau_dossier2.reload.accepte?).to be true }
|
||||||
it { expect(nouveau_dossier2.reload.en_instruction_at).to eq(date) }
|
it { expect(nouveau_dossier2.reload.en_instruction_at).to eq(date) }
|
||||||
it { expect(nouveau_dossier2.reload.processed_at).to eq(date) }
|
it { expect(nouveau_dossier2.reload.processed_at).to eq(date) }
|
||||||
|
it { expect(nouveau_dossier2.reload.attestation).to be_present }
|
||||||
|
|
||||||
it { expect(dossier_recu.reload.en_instruction?).to be true }
|
it { expect(dossier_recu.reload.en_instruction?).to be true }
|
||||||
it { expect(dossier_recu.reload.en_instruction_at).to eq(instruction_date) }
|
it { expect(dossier_recu.reload.en_instruction_at).to eq(instruction_date) }
|
||||||
|
|
Loading…
Reference in a new issue