-
Notifications
You must be signed in to change notification settings - Fork 166
LG-10812 | Report on all-time user count #9350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c5e3a7e
a3dbbcc
f94c66f
5e7eeae
0a72953
f264e20
0305152
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,14 +11,16 @@ | |
| let(:report_folder) do | ||
| 'int/monthly-key-metrics-report/2021/2021-03-02.monthly-key-metrics-report' | ||
| end | ||
| let(:account_reuse_s3_path) do | ||
| "#{report_folder}/account_reuse.csv" | ||
| end | ||
| let(:total_profiles_s3_path) do | ||
| "#{report_folder}/total_profiles.csv" | ||
| end | ||
| let(:account_deletion_rate_s3_path) do | ||
| "#{report_folder}/account_deletion_rate.csv" | ||
| let(:account_reuse_s3_path) { "#{report_folder}/account_reuse.csv" } | ||
| let(:total_profiles_s3_path) { "#{report_folder}/total_profiles.csv" } | ||
| let(:account_deletion_rate_s3_path) { "#{report_folder}/account_deletion_rate.csv" } | ||
| let(:total_user_count_s3_path) { "#{report_folder}/total_user_count.csv" } | ||
| let(:s3_metadata) do | ||
| { | ||
| body: anything, | ||
| content_type: 'text/csv', | ||
| bucket: 'reports-bucket.1234-us-west-1', | ||
| } | ||
| end | ||
|
|
||
| before do | ||
|
|
@@ -80,23 +82,22 @@ | |
| it 'uploads a file to S3 based on the report date' do | ||
| expect(subject).to receive(:upload_file_to_s3_bucket).with( | ||
| path: account_reuse_s3_path, | ||
| body: anything, | ||
| content_type: 'text/csv', | ||
| bucket: 'reports-bucket.1234-us-west-1', | ||
| **s3_metadata, | ||
| ).exactly(1).time.and_call_original | ||
|
|
||
| expect(subject).to receive(:upload_file_to_s3_bucket).with( | ||
| path: total_profiles_s3_path, | ||
| body: anything, | ||
| content_type: 'text/csv', | ||
| bucket: 'reports-bucket.1234-us-west-1', | ||
| **s3_metadata, | ||
| ).exactly(1).time.and_call_original | ||
|
|
||
| expect(subject).to receive(:upload_file_to_s3_bucket).with( | ||
| path: account_deletion_rate_s3_path, | ||
| body: anything, | ||
| content_type: 'text/csv', | ||
| bucket: 'reports-bucket.1234-us-west-1', | ||
| **s3_metadata, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought I'd try to DRY this up a little rather than copying it for a 4th time. |
||
| ).exactly(1).time.and_call_original | ||
|
|
||
| expect(subject).to receive(:upload_file_to_s3_bucket).with( | ||
| path: total_user_count_s3_path, | ||
| **s3_metadata, | ||
| ).exactly(1).time.and_call_original | ||
|
|
||
| subject.perform(report_date) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| require 'rails_helper' | ||
| require 'csv' | ||
|
|
||
| RSpec.describe Reporting::TotalUserCountReport do | ||
| let(:report_date) do | ||
| Date.new(2021, 3, 1).in_time_zone('UTC') | ||
| end | ||
| let(:expected_report) do | ||
| [ | ||
| ['All-time user count'], | ||
| [expected_count], | ||
| ] | ||
| end | ||
|
|
||
| subject(:report) { described_class.new(report_date) } | ||
|
|
||
| before { travel_to report_date } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is slightly copypasta; we don't assert the actual date here. But it nicely avoids the hassle I ran into previously where I had to set |
||
|
|
||
| shared_examples 'a report with that user counted' do | ||
| let(:expected_count) { 1 } | ||
| it 'includes that user in the count' do | ||
| expect(subject.total_user_count_report).to eq expected_report | ||
| end | ||
| end | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a big savings, but IMHO it better expresses the intent vs. repeating |
||
|
|
||
| describe '#total_user_count_report' do | ||
| context 'with no users' do | ||
| let(:expected_count) { 0 } | ||
|
|
||
| it 'returns a report with a count of zero' do | ||
| expect(subject.total_user_count_report).to eq expected_report | ||
| end | ||
| end | ||
|
|
||
| context 'with one ordinary user' do | ||
| let!(:user) { create(:user) } | ||
| it_behaves_like 'a report with that user counted' | ||
| end | ||
|
|
||
| context 'with a suspended user' do | ||
| let!(:suspended_user) { create(:user, :suspended) } | ||
|
|
||
| it 'has a suspended user' do | ||
| expect(suspended_user).to be_suspended | ||
| expect(User.count).to eq 1 | ||
| end | ||
|
|
||
| it_behaves_like 'a report with that user counted' | ||
| end | ||
|
|
||
| context 'with an unconfirmed user' do | ||
| let!(:unconfirmed_user) { create(:user, :unconfirmed) } | ||
|
|
||
| it 'has an unconfirmed user' do | ||
| expect(unconfirmed_user).to_not be_confirmed | ||
| expect(User.count).to eq 1 | ||
| end | ||
|
|
||
| it_behaves_like 'a report with that user counted' | ||
| end | ||
|
|
||
| context 'with a user rejected for fraud' do | ||
| let!(:fraud_user) { create(:user, :fraud_rejection) } | ||
|
|
||
| it 'has a user rejected for fraud' do | ||
| expect(fraud_user).to be_fraud_rejection | ||
| expect(User.count).to eq 1 | ||
| end | ||
|
|
||
| it_behaves_like 'a report with that user counted' | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized this didn't actually need to be
do...endblocks for length so I compacted them. Tell me if you hate this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compact is good!