Merge pull request #2678 from betagouv/frederic/fix_2550-attestations_demarche_declarative

Attestations demarche declarative
This commit is contained in:
Frederic Merizen 2018-09-25 16:07:39 +02:00 committed by GitHub
commit 526bd28cdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View file

@ -3,22 +3,25 @@ class AutoReceiveDossiersForProcedureJob < ApplicationJob
def perform(procedure_id, state)
procedure = Procedure.find(procedure_id)
attrs = case state
case state
when Dossier.states.fetch(:en_instruction)
{
procedure.dossiers.state_en_construction.update_all(
state: Dossier.states.fetch(:en_instruction),
en_instruction_at: DateTime.now
}
)
when Dossier.states.fetch(:accepte)
{
procedure.dossiers.state_en_construction.find_each do |dossier|
dossier.update(
state: Dossier.states.fetch(:accepte),
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
raise "Receiving Procedure##{procedure_id} in invalid state \"#{state}\""
end
procedure.dossiers.state_en_construction.update_all(attrs)
end
end

View file

@ -7,6 +7,7 @@ RSpec.describe AutoReceiveDossiersForProcedureJob, type: :job do
before do
Timecop.freeze(date)
create(:attestation_template, procedure: nouveau_dossier1.procedure)
AutoReceiveDossiersForProcedureJob.new.perform(procedure_id, state)
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.en_instruction_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.en_instruction_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_at).to eq(instruction_date) }