Fix AdministrateurUsageStatisticsService

This commit is contained in:
Paul Chavard 2019-09-17 11:26:38 +02:00
parent adfa80142a
commit 8a691d534a
2 changed files with 7 additions and 9 deletions

View file

@ -8,7 +8,7 @@
# - For all other dossiers, the synthetic_state and the state are the same # - For all other dossiers, the synthetic_state and the state are the same
class AdministrateurUsageStatisticsService class AdministrateurUsageStatisticsService
def update_administrateurs def update_administrateurs
Administrateur.find_each do |administrateur| Administrateur.includes(:user).find_each do |administrateur|
stats = administrateur_stats(administrateur) stats = administrateur_stats(administrateur)
api.identify(administrateur.email, stats) api.identify(administrateur.email, stats)
end end
@ -27,7 +27,7 @@ class AdministrateurUsageStatisticsService
nb_dossiers_roi = nb_dossiers_by_procedure_id.reject { |procedure_id, _count| is_brouillon(procedure_id) }.map { |_procedure_id, count| count }.sum nb_dossiers_roi = nb_dossiers_by_procedure_id.reject { |procedure_id, _count| is_brouillon(procedure_id) }.map { |_procedure_id, count| count }.sum
result = { result = {
ds_sign_in_count: administrateur.sign_in_count, ds_sign_in_count: administrateur.user.sign_in_count,
ds_created_at: administrateur.created_at, ds_created_at: administrateur.created_at,
ds_active: administrateur.active, ds_active: administrateur.active,
ds_id: administrateur.id, ds_id: administrateur.id,
@ -62,12 +62,12 @@ class AdministrateurUsageStatisticsService
admin_roi_high: nb_dossiers_roi * 17 admin_roi_high: nb_dossiers_roi * 17
} }
if administrateur.current_sign_in_at.present? if administrateur.user.current_sign_in_at.present?
result[:ds_current_sign_in_at] = administrateur.current_sign_in_at result[:ds_current_sign_in_at] = administrateur.user.current_sign_in_at
end end
if administrateur.last_sign_in_at.present? if administrateur.user.last_sign_in_at.present?
result[:ds_last_sign_in_at] = administrateur.last_sign_in_at result[:ds_last_sign_in_at] = administrateur.user.last_sign_in_at
end end
result result

View file

@ -38,9 +38,7 @@ describe AdministrateurUsageStatisticsService do
context 'for an administrateur that has plenty of things' do context 'for an administrateur that has plenty of things' do
let(:administrateur) do let(:administrateur) do
create(:administrateur, create(:administrateur,
sign_in_count: 17, user: create(:user, sign_in_count: 17, current_sign_in_at: Time.zone.local(2019, 3, 7), last_sign_in_at: Time.zone.local(2019, 2, 27)),
current_sign_in_at: Time.zone.local(2019, 3, 7),
last_sign_in_at: Time.zone.local(2019, 2, 27),
active: true, active: true,
services: [create(:service)], services: [create(:service)],
instructeurs: [create(:instructeur)]) instructeurs: [create(:instructeur)])