-
Notifications
You must be signed in to change notification settings - Fork 166
[WIP] LG-10812 | Report on total user count #9300
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
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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
|
|
||
| module Reporting | ||
| class AccountReuseAndTotalIdentitiesReport | ||
| attr_reader :report_date | ||
|
|
||
| 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 |
|---|---|---|
| @@ -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 | ||
|
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. Aside: I just recently learned about how much magic you can do with built-in rspec matchers. If a class responds to This was kind of scaffolding for myself to confirm that my 'suspended' user was indeed suspended, but I'm inclined to leave it in for clarity. |
||
| expect(subject.total_user_count_report).to eq(expected_report) | ||
|
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'm not super proud of this pattern. I'm essentially testing All that said, I'm not testing these because I think they might break; I'm testing them to make explicit what I intend as the expected behavior. Should a suspended, unconfirmed, or rejected-for-fraud user be included in "Total users all-time", or is that surprising? Given that we have previously received requests for "active users," I am interpreting "Total users all-time" to include non-active users, but will the consumers of our report agree? (I worry that this turns into a large can of worms otherwise.) |
||
| 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 | ||
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.
Much of this is actually from Luis's PR; you can view my commits individually if you need to separate them out. I'll rebase this Friday as appropriate.