diff --git a/app/jobs/reports/monthly_key_metrics_report.rb b/app/jobs/reports/monthly_key_metrics_report.rb index 8438089d1b6..0ca9985cccc 100644 --- a/app/jobs/reports/monthly_key_metrics_report.rb +++ b/app/jobs/reports/monthly_key_metrics_report.rb @@ -11,9 +11,11 @@ def perform(date = Time.zone.today) account_reuse_table = account_reuse_report.account_reuse_report total_profiles_table = account_reuse_report.total_identities_report + total_users_all_time_table = total_user_queries.total_user_count_report upload_to_s3(account_reuse_table, report_name: 'account_reuse') upload_to_s3(total_profiles_table, report_name: 'total_profiles') + upload_to_s3(total_users_all_time_table, report_name: 'total_users_all_time') email_tables = [ [ @@ -28,6 +30,10 @@ def perform(date = Time.zone.today) { title: 'Total proofed identities' }, *total_profiles_table, ], + [ + { title: 'All-time user total' }, + total_users_all_time_table, + ], ] email_message = "Report: #{REPORT_NAME} #{date}" @@ -53,9 +59,15 @@ def emails emails end + def account_reuse_report @account_reuse_report ||= Reporting::AccountReuseAndTotalIdentitiesReport.new(report_date) end + + def total_user_queries + @total_user_queries ||= Reporting::TotalUserCountReport.new(report_date) + end + def upload_to_s3(report_body, report_name: nil) _latest, path = generate_s3_paths(REPORT_NAME, 'csv', subname: report_name, now: report_date) diff --git a/app/services/reporting/account_reuse_and_total_identities_report.rb b/app/services/reporting/account_reuse_and_total_identities_report.rb index ca4966e6608..4d298da6be6 100644 --- a/app/services/reporting/account_reuse_and_total_identities_report.rb +++ b/app/services/reporting/account_reuse_and_total_identities_report.rb @@ -1,3 +1,4 @@ + module Reporting class AccountReuseAndTotalIdentitiesReport attr_reader :report_date diff --git a/app/services/reporting/total_user_count_report.rb b/app/services/reporting/total_user_count_report.rb new file mode 100644 index 00000000000..7ed0f321448 --- /dev/null +++ b/app/services/reporting/total_user_count_report.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Reporting + class TotalUserCountReport + attr_reader :report_date + + def initialize(report_date = Time.zone.today) + @report_date = report_date + end + + def total_user_count_report + [ + ['All-time user count'], + [total_user_count], + ] + end + + private + + def total_user_count + User.where('created_at <= ?', report_date).count + end + end +end diff --git a/spec/services/reporting/total_user_count_report_spec.rb b/spec/services/reporting/total_user_count_report_spec.rb new file mode 100644 index 00000000000..985a0b380f7 --- /dev/null +++ b/spec/services/reporting/total_user_count_report_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Reporting::TotalUserCountReport do + let(:report_date) { Time.zone.today + 1.day } + let!(:user) { create(:user) } + let(:expected_report) do + [ + ['All-time user count'], + [expected_count], + ] + end + + subject { described_class.new(report_date) } + + describe '#total_user_count_report' do + let(:expected_count) { 1 } + + it 'returns the expected data' do + expect(subject.total_user_count_report).to eq(expected_report) + end + + context 'with a suspended user' do + let(:suspended_user) { create(:user, :suspended) } + let(:expected_count) { 2 } + + it 'includes the suspended user in the count' do + expect(suspended_user).to be_suspended + expect(subject.total_user_count_report).to eq(expected_report) + end + end + + context 'with an unconfirmed user' do + let(:unconfirmed_user) { create(:user, :unconfirmed) } + let(:expected_count) { 2 } + + it 'includes the unconfirmed user in the count' do + expect(unconfirmed_user).not_to be_confirmed + expect(subject.total_user_count_report).to eq(expected_report) + end + end + + context 'with a user rejected for fraud' do + let(:fraud_user) { create(:user, :fraud_rejection) } + let(:expected_count) { 2 } + + it 'includes them in the count because they are still a user' do + expect(fraud_user).to be_fraud_rejection + expect(subject.total_user_count_report).to eq(expected_report) + end + end + end +end