2019-03-07 17:33:50 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AdministrateurUsageStatisticsService do
|
|
|
|
describe '#administrateur_stats' do
|
|
|
|
let(:service) { AdministrateurUsageStatisticsService.new }
|
|
|
|
subject { service.send(:administrateur_stats, administrateur) }
|
|
|
|
|
|
|
|
before { Timecop.freeze(Time.zone.now) }
|
|
|
|
after { Timecop.return }
|
|
|
|
|
|
|
|
context 'for an administrateur that has nothing' do
|
|
|
|
let(:administrateur) { create(:administrateur) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to eq(
|
|
|
|
ds_sign_in_count: 0,
|
|
|
|
ds_created_at: Time.zone.now,
|
|
|
|
ds_active: false,
|
|
|
|
ds_id: administrateur.id,
|
|
|
|
nb_services: 0,
|
|
|
|
nb_instructeurs: 0,
|
|
|
|
ds_nb_demarches_actives: 0,
|
|
|
|
ds_nb_demarches_archives: 0,
|
|
|
|
ds_nb_demarches_brouillons: 0,
|
|
|
|
nb_demarches_test: 0,
|
|
|
|
nb_demarches_prod: 0,
|
|
|
|
nb_demarches_prod_20: 0,
|
|
|
|
nb_dossiers: 0,
|
|
|
|
nb_dossiers_max: 0,
|
|
|
|
nb_dossiers_traite: 0,
|
2019-06-24 15:02:55 +02:00
|
|
|
nb_dossiers_dossier_en_instruction: 0,
|
|
|
|
admin_roi_low: 0,
|
|
|
|
admin_roi_high: 0
|
2019-03-07 17:33:50 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for an administrateur that has plenty of things' do
|
|
|
|
let(:administrateur) do
|
|
|
|
create(:administrateur,
|
|
|
|
sign_in_count: 17,
|
|
|
|
current_sign_in_at: Time.zone.local(2019, 3, 7),
|
|
|
|
last_sign_in_at: Time.zone.local(2019, 2, 27),
|
|
|
|
active: true,
|
|
|
|
services: [create(:service)],
|
2019-08-06 11:02:54 +02:00
|
|
|
instructeurs: [create(:instructeur)])
|
2019-03-07 17:33:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to include(
|
|
|
|
ds_sign_in_count: 17,
|
|
|
|
ds_current_sign_in_at: Time.zone.local(2019, 3, 7),
|
|
|
|
ds_last_sign_in_at: Time.zone.local(2019, 2, 27),
|
|
|
|
ds_created_at: Time.zone.now,
|
|
|
|
ds_active: true,
|
|
|
|
ds_id: administrateur.id,
|
|
|
|
nb_services: 1,
|
|
|
|
nb_instructeurs: 1
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'counting procedures and dossiers' do
|
|
|
|
let(:administrateur) do
|
|
|
|
create(:administrateur, procedures: [procedure])
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a freshly active procedure' do
|
|
|
|
let(:procedure) { create(:procedure, aasm_state: 'publiee') }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to include(
|
|
|
|
ds_nb_demarches_actives: 1,
|
|
|
|
ds_nb_demarches_archives: 0,
|
|
|
|
ds_nb_demarches_brouillons: 0,
|
|
|
|
nb_demarches_test: 0,
|
|
|
|
nb_demarches_prod: 0,
|
|
|
|
nb_demarches_prod_20: 0,
|
|
|
|
nb_dossiers: 0,
|
|
|
|
nb_dossiers_max: 0,
|
|
|
|
nb_dossiers_traite: 0,
|
2019-06-24 15:02:55 +02:00
|
|
|
nb_dossiers_dossier_en_instruction: 0,
|
|
|
|
admin_roi_low: 0,
|
|
|
|
admin_roi_high: 0
|
2019-03-07 17:33:50 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a procedure archivee' do
|
2019-08-26 15:27:43 +02:00
|
|
|
let(:procedure) { create(:procedure, aasm_state: 'archivee') }
|
|
|
|
let!(:dossiers) do
|
2019-03-07 17:33:50 +01:00
|
|
|
(1..7).flat_map do
|
|
|
|
[
|
2019-08-26 15:27:43 +02:00
|
|
|
create(:dossier, :en_construction, procedure: procedure),
|
|
|
|
create(:dossier, :en_instruction, procedure: procedure),
|
|
|
|
create(:dossier, :accepte, procedure: procedure)
|
2019-03-07 17:33:50 +01:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to include(
|
|
|
|
ds_nb_demarches_actives: 0,
|
|
|
|
ds_nb_demarches_archives: 1,
|
|
|
|
ds_nb_demarches_brouillons: 0,
|
|
|
|
nb_demarches_test: 0,
|
|
|
|
nb_demarches_prod: 1,
|
|
|
|
nb_demarches_prod_20: 1,
|
|
|
|
nb_dossiers: 21,
|
|
|
|
nb_dossiers_max: 21,
|
|
|
|
nb_dossiers_traite: 7,
|
2019-06-24 15:02:55 +02:00
|
|
|
nb_dossiers_dossier_en_instruction: 7,
|
2019-07-08 14:58:32 +02:00
|
|
|
admin_roi_low: 147,
|
|
|
|
admin_roi_high: 357
|
2019-03-07 17:33:50 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a procedure brouillon' do
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to include(
|
|
|
|
ds_nb_demarches_actives: 0,
|
|
|
|
ds_nb_demarches_archives: 0,
|
|
|
|
ds_nb_demarches_brouillons: 1,
|
|
|
|
nb_demarches_test: 0,
|
|
|
|
nb_demarches_prod: 0,
|
|
|
|
nb_demarches_prod_20: 0,
|
|
|
|
nb_dossiers: 0,
|
|
|
|
nb_dossiers_max: 0,
|
|
|
|
nb_dossiers_traite: 0,
|
2019-06-24 15:02:55 +02:00
|
|
|
nb_dossiers_dossier_en_instruction: 0,
|
|
|
|
admin_roi_low: 0,
|
|
|
|
admin_roi_high: 0
|
2019-03-07 17:33:50 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a procedure en test' do
|
2019-08-26 15:27:43 +02:00
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
let!(:dossiers) do
|
2019-03-07 17:33:50 +01:00
|
|
|
(1..7).flat_map do
|
|
|
|
[
|
2019-08-26 15:27:43 +02:00
|
|
|
create(:dossier, :en_construction, procedure: procedure),
|
|
|
|
create(:dossier, :en_instruction, procedure: procedure),
|
|
|
|
create(:dossier, :accepte, procedure: procedure)
|
2019-03-07 17:33:50 +01:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to include(
|
|
|
|
ds_nb_demarches_actives: 0,
|
|
|
|
ds_nb_demarches_archives: 0,
|
|
|
|
ds_nb_demarches_brouillons: 1,
|
|
|
|
nb_demarches_test: 1,
|
|
|
|
nb_demarches_prod: 0,
|
|
|
|
nb_demarches_prod_20: 0,
|
|
|
|
nb_dossiers: 0,
|
|
|
|
nb_dossiers_max: 0,
|
|
|
|
nb_dossiers_traite: 0,
|
2019-06-24 15:02:55 +02:00
|
|
|
nb_dossiers_dossier_en_instruction: 0,
|
|
|
|
admin_roi_low: 0,
|
|
|
|
admin_roi_high: 0
|
2019-03-07 17:33:50 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a procedure en prod' do
|
2019-08-26 15:27:43 +02:00
|
|
|
let(:procedure) { create(:procedure, aasm_state: 'publiee') }
|
|
|
|
let!(:dossiers) do
|
2019-03-07 17:33:50 +01:00
|
|
|
[
|
2019-08-26 15:27:43 +02:00
|
|
|
create(:dossier, :en_construction, procedure: procedure),
|
|
|
|
create(:dossier, :en_instruction, procedure: procedure),
|
|
|
|
create(:dossier, :accepte, procedure: procedure)
|
2019-03-07 17:33:50 +01:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to include(
|
|
|
|
ds_nb_demarches_actives: 1,
|
|
|
|
ds_nb_demarches_archives: 0,
|
|
|
|
ds_nb_demarches_brouillons: 0,
|
|
|
|
nb_demarches_test: 0,
|
|
|
|
nb_demarches_prod: 1,
|
|
|
|
nb_demarches_prod_20: 0,
|
|
|
|
nb_dossiers: 3,
|
|
|
|
nb_dossiers_max: 3,
|
|
|
|
nb_dossiers_traite: 1,
|
2019-06-24 15:02:55 +02:00
|
|
|
nb_dossiers_dossier_en_instruction: 1,
|
2019-07-08 14:58:32 +02:00
|
|
|
admin_roi_low: 21,
|
|
|
|
admin_roi_high: 51
|
2019-03-07 17:33:50 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a procedure en prod and more than 20 dossiers' do
|
2019-08-26 15:27:43 +02:00
|
|
|
let(:procedure) { create(:procedure, aasm_state: 'publiee') }
|
|
|
|
let!(:dossiers) do
|
2019-03-07 17:33:50 +01:00
|
|
|
(1..7).flat_map do
|
|
|
|
[
|
2019-08-26 15:27:43 +02:00
|
|
|
create(:dossier, :en_construction, procedure: procedure),
|
|
|
|
create(:dossier, :en_instruction, procedure: procedure),
|
|
|
|
create(:dossier, :accepte, procedure: procedure)
|
2019-03-07 17:33:50 +01:00
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to include(
|
|
|
|
ds_nb_demarches_actives: 1,
|
|
|
|
ds_nb_demarches_archives: 0,
|
|
|
|
ds_nb_demarches_brouillons: 0,
|
|
|
|
nb_demarches_test: 0,
|
|
|
|
nb_demarches_prod: 1,
|
|
|
|
nb_demarches_prod_20: 1,
|
|
|
|
nb_dossiers: 21,
|
|
|
|
nb_dossiers_max: 21,
|
|
|
|
nb_dossiers_traite: 7,
|
2019-06-24 15:02:55 +02:00
|
|
|
nb_dossiers_dossier_en_instruction: 7,
|
2019-07-08 14:58:32 +02:00
|
|
|
admin_roi_low: 147,
|
|
|
|
admin_roi_high: 357
|
2019-03-07 17:33:50 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|