Merge pull request #2986 from betagouv/restrict-dossier-time-estimation
Restreint l'estimation de la durée de traitement à un mois
This commit is contained in:
commit
7c6437b01a
2 changed files with 17 additions and 5 deletions
|
@ -426,6 +426,7 @@ class Procedure < ApplicationRecord
|
||||||
def percentile_time(start_attribute, end_attribute, p)
|
def percentile_time(start_attribute, end_attribute, p)
|
||||||
times = dossiers
|
times = dossiers
|
||||||
.state_termine
|
.state_termine
|
||||||
|
.where(end_attribute => 1.month.ago..DateTime.current)
|
||||||
.pluck(start_attribute, end_attribute)
|
.pluck(start_attribute, end_attribute)
|
||||||
.map { |(start_date, end_date)| end_date - start_date }
|
.map { |(start_date, end_date)| end_date - start_date }
|
||||||
|
|
||||||
|
|
|
@ -708,12 +708,14 @@ describe Procedure do
|
||||||
describe '#usual_instruction_time' do
|
describe '#usual_instruction_time' do
|
||||||
let(:procedure) { create(:procedure) }
|
let(:procedure) { create(:procedure) }
|
||||||
|
|
||||||
|
def create_dossier(instruction_date:, processed_date:)
|
||||||
|
dossier = create(:dossier, :accepte, procedure: procedure)
|
||||||
|
dossier.update!(en_instruction_at: instruction_date, processed_at: processed_date)
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
processed_delays.each do |delay|
|
processed_delays.each do |delay|
|
||||||
dossier = create :dossier, :accepte, procedure: procedure
|
create_dossier(instruction_date: 1.week.ago - delay, processed_date: 1.week.ago)
|
||||||
instruction_date = 1.month.ago
|
|
||||||
processed_date = instruction_date + delay
|
|
||||||
dossier.update!(en_instruction_at: instruction_date, processed_at: processed_date)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -725,9 +727,18 @@ describe Procedure do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when there are very old dossiers' do
|
||||||
|
let(:processed_delays) { [2.days, 2.days] }
|
||||||
|
let!(:old_dossier) { create_dossier(instruction_date: 3.months.ago, processed_date: 2.months.ago) }
|
||||||
|
|
||||||
|
it 'ignores dossiers older than 1 month' do
|
||||||
|
expect(procedure.usual_instruction_time).to be_within(10.seconds).of(2.days)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when there is only one processed dossier' do
|
context 'when there is only one processed dossier' do
|
||||||
let(:processed_delays) { [1.day] }
|
let(:processed_delays) { [1.day] }
|
||||||
it { expect(procedure.usual_instruction_time).to eq(1.day) }
|
it { expect(procedure.usual_instruction_time).to be_within(10.seconds).of(1.day) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'where there is no processed dossier' do
|
context 'where there is no processed dossier' do
|
||||||
|
|
Loading…
Add table
Reference in a new issue