Show the mean verification time in the Résumé tab

This commit is contained in:
gregoirenovel 2018-09-18 17:47:41 +02:00
parent d55c9dff4d
commit f3a257d81d
3 changed files with 28 additions and 0 deletions
app
models
views/new_user/dossiers/show
spec/features/new_user

View file

@ -326,6 +326,17 @@ class Procedure < ApplicationRecord
end
end
def mean_verification_time
verification_times = dossiers
.state_termine
.pluck(:en_construction_at, :en_instruction_at)
.map { |times| times[1] - times[0] }
if verification_times.present?
verification_times.sum.fdiv(verification_times.size).ceil
end
end
def mean_instruction_time
instruction_times = dossiers
.state_termine

View file

@ -26,6 +26,11 @@
= succeed '.' do
%strong votre dossier passera directement en instruction
- if dossier.procedure.mean_verification_time
- cache(dossier.procedure, expires_in: 1.week) do
%p
Le temps moyen de vérification pour cette démarche est de #{distance_of_time_in_words(dossier.procedure.mean_verification_time)}.
- elsif dossier.en_instruction?
.en-instruction
%p Votre dossier est complet. Il est en cours dexamen par les instructeur de ladministration.

View file

@ -20,6 +20,18 @@ describe 'Dossier details:' do
end
describe "the user can see the mean time they are expected to wait" do
context "the dossier is in construction" do
before do
other_dossier = create(:dossier, :accepte, :for_individual, procedure: simple_procedure, en_construction_at: 10.days.ago, en_instruction_at: Time.now)
end
it "show the proper wait time" do
visit_dossier dossier
expect(page).to have_text("Le temps moyen de vérification pour cette démarche est de 10 jours.")
end
end
context "the dossier is in instruction" do
let(:dossier) { create(:dossier, :en_instruction, :for_individual, :with_commentaires, user: user, procedure: simple_procedure) }