fix(stat): ignore forks, previews & dossiers from draft procedures
This commit is contained in:
parent
d2f1af0830
commit
aa8bef48b0
2 changed files with 37 additions and 2 deletions
|
@ -50,12 +50,13 @@ class Stat < ApplicationRecord
|
|||
COUNT(*) FILTER ( WHERE state != 'brouillon' ) AS "not_brouillon",
|
||||
COUNT(*) FILTER ( WHERE state != 'brouillon' and depose_at BETWEEN :one_month_ago AND :now ) AS "dossiers_depose_avant_30_jours",
|
||||
COUNT(*) FILTER ( WHERE state != 'brouillon' and depose_at BETWEEN :two_months_ago AND :one_month_ago ) AS "dossiers_deposes_entre_60_et_30_jours",
|
||||
COUNT(*) FILTER ( WHERE state = 'brouillon' ) AS "brouillon",
|
||||
COUNT(*) FILTER ( WHERE state = 'brouillon' AND editing_fork_origin_id IS NULL AND (for_procedure_preview IS NULL OR for_procedure_preview = false)) AS "brouillon",
|
||||
COUNT(*) FILTER ( WHERE state = 'en_construction' ) AS "en_construction",
|
||||
COUNT(*) FILTER ( WHERE state = 'en_instruction' ) AS "en_instruction",
|
||||
COUNT(*) FILTER ( WHERE state in ('accepte', 'refuse', 'sans_suite') ) AS "termines"
|
||||
FROM dossiers
|
||||
WHERE hidden_at IS NULL
|
||||
WHERE hidden_at IS NULL
|
||||
AND revision_id NOT IN (SELECT r.id FROM procedure_revisions r LEFT JOIN procedures p ON r.procedure_id=p.id WHERE p.aasm_state = 'brouillon')
|
||||
EOF
|
||||
)
|
||||
end
|
||||
|
|
|
@ -21,6 +21,40 @@ describe Stat, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe '.dossiers_states' do
|
||||
let(:procedure) { create(:procedure, :published) }
|
||||
before do
|
||||
create_list(:dossier, 2, :en_construction, depose_at: 10.days.ago, procedure:)
|
||||
create_list(:dossier, 3, :en_construction, depose_at: 40.days.ago, procedure:)
|
||||
|
||||
create_list(:dossier, 3, :brouillon, procedure:, for_procedure_preview: nil)
|
||||
create_list(:dossier, 1, :brouillon, procedure:, for_procedure_preview: false)
|
||||
|
||||
create_list(:dossier, 6, :en_instruction, procedure:)
|
||||
|
||||
create_list(:dossier, 5, :accepte, procedure:)
|
||||
create_list(:dossier, 1, :refuse, procedure:)
|
||||
create_list(:dossier, 1, :sans_suite, procedure:)
|
||||
|
||||
# ignored dossiers
|
||||
create(:dossier, :brouillon, editing_fork_origin: Dossier.en_construction.first)
|
||||
create(:dossier, :brouillon, procedure: create(:procedure, :draft))
|
||||
create(:dossier, :brouillon, for_procedure_preview: true)
|
||||
end
|
||||
|
||||
subject(:stats) { Stat.send(:dossiers_states) }
|
||||
|
||||
it 'works' do
|
||||
expect(stats["not_brouillon"]).to eq(18)
|
||||
expect(stats["dossiers_depose_avant_30_jours"]).to eq(2)
|
||||
expect(stats["dossiers_deposes_entre_60_et_30_jours"]).to eq(3)
|
||||
expect(stats["brouillon"]).to eq(4)
|
||||
expect(stats["en_construction"]).to eq(5)
|
||||
expect(stats["en_instruction"]).to eq(6)
|
||||
expect(stats["termines"]).to eq(7)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.update_stats' do
|
||||
it 'merges dossiers_states and deleted_dossiers_states' do
|
||||
stats = {
|
||||
|
|
Loading…
Reference in a new issue