From da6b9238f53c6660e6cd9feedaa96a1b7ce01f92 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 12 Apr 2024 05:38:24 -0400 Subject: [PATCH] Expand coverage for admin/metrics/measure/* classes (#29914) --- .../measure/active_users_measure_spec.rb | 29 +++++++++++++-- .../measure/instance_accounts_measure_spec.rb | 20 +++++++--- .../instance_followers_measure_spec.rb | 21 ++++++++--- .../measure/instance_follows_measure_spec.rb | 19 +++++++--- ...instance_media_attachments_measure_spec.rb | 23 +++++++++--- .../measure/instance_reports_measure_spec.rb | 19 +++++++--- .../measure/instance_statuses_measure_spec.rb | 19 +++++++--- .../measure/interactions_measure_spec.rb | 29 +++++++++++++-- .../metrics/measure/new_users_measure_spec.rb | 21 +++++++++-- .../measure/opened_reports_measure_spec.rb | 21 +++++++++-- .../measure/resolved_reports_measure_spec.rb | 21 +++++++++-- .../measure/tag_accounts_measure_spec.rb | 37 +++++++++++++++++-- .../measure/tag_servers_measure_spec.rb | 36 ++++++++++++++++-- .../metrics/measure/tag_uses_measure_spec.rb | 37 +++++++++++++++++-- 14 files changed, 292 insertions(+), 60 deletions(-) diff --git a/spec/lib/admin/metrics/measure/active_users_measure_spec.rb b/spec/lib/admin/metrics/measure/active_users_measure_spec.rb index 55164ed88ac..38ee14075b3 100644 --- a/spec/lib/admin/metrics/measure/active_users_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/active_users_measure_spec.rb @@ -3,15 +3,38 @@ require 'rails_helper' describe Admin::Metrics::Measure::ActiveUsersMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let(:start_at) { 2.days.ago } let(:end_at) { Time.now.utc } let(:params) { ActionController::Parameters.new } describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + context 'with activity tracking records' do + before do + 3.times do + travel_to(2.days.ago) { record_login_activity } + end + 2.times do + travel_to(1.day.ago) { record_login_activity } + end + travel_to(0.days.ago) { record_login_activity } + end + + it 'returns correct activity tracker counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '3'), + include(date: 1.day.ago.midnight.to_time, value: '2'), + include(date: 0.days.ago.midnight.to_time, value: '1') + ) + end + + def record_login_activity + ActivityTracker.record('activity:logins', Fabricate(:user).id) + end end end end diff --git a/spec/lib/admin/metrics/measure/instance_accounts_measure_spec.rb b/spec/lib/admin/metrics/measure/instance_accounts_measure_spec.rb index 8e414963f33..0d2ad31c399 100644 --- a/spec/lib/admin/metrics/measure/instance_accounts_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/instance_accounts_measure_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Admin::Metrics::Measure::InstanceAccountsMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let(:domain) { 'example.com' } @@ -20,12 +20,13 @@ describe Admin::Metrics::Measure::InstanceAccountsMeasure do Fabricate(:account, domain: "foo.#{domain}", created_at: 1.year.ago) Fabricate(:account, domain: "foo.#{domain}") Fabricate(:account, domain: "bar.#{domain}") + Fabricate(:account, domain: 'other-host.example') end - describe 'total' do + describe '#total' do context 'without include_subdomains' do it 'returns the expected number of accounts' do - expect(measure.total).to eq 3 + expect(subject.total).to eq 3 end end @@ -33,14 +34,21 @@ describe Admin::Metrics::Measure::InstanceAccountsMeasure do let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') } it 'returns the expected number of accounts' do - expect(measure.total).to eq 6 + expect(subject.total).to eq 6 end end end describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + it 'returns correct instance_accounts counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '0'), + include(date: 1.day.ago.midnight.to_time, value: '0'), + include(date: 0.days.ago.midnight.to_time, value: '1') + ) end end end diff --git a/spec/lib/admin/metrics/measure/instance_followers_measure_spec.rb b/spec/lib/admin/metrics/measure/instance_followers_measure_spec.rb index c627e6cede0..27bf30d17d5 100644 --- a/spec/lib/admin/metrics/measure/instance_followers_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/instance_followers_measure_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Admin::Metrics::Measure::InstanceFollowersMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let(:domain) { 'example.com' } @@ -22,12 +22,14 @@ describe Admin::Metrics::Measure::InstanceFollowersMeasure do Fabricate(:account, domain: "foo.#{domain}").follow!(local_account) Fabricate(:account, domain: "foo.#{domain}").follow!(local_account) Fabricate(:account, domain: "bar.#{domain}") + + Fabricate(:account, domain: 'other.example').follow!(local_account) end - describe 'total' do + describe '#total' do context 'without include_subdomains' do it 'returns the expected number of accounts' do - expect(measure.total).to eq 2 + expect(subject.total).to eq 2 end end @@ -35,14 +37,21 @@ describe Admin::Metrics::Measure::InstanceFollowersMeasure do let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') } it 'returns the expected number of accounts' do - expect(measure.total).to eq 4 + expect(subject.total).to eq 4 end end end describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + it 'returns correct instance_followers counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '0'), + include(date: 1.day.ago.midnight.to_time, value: '0'), + include(date: 0.days.ago.midnight.to_time, value: '2') + ) end end end diff --git a/spec/lib/admin/metrics/measure/instance_follows_measure_spec.rb b/spec/lib/admin/metrics/measure/instance_follows_measure_spec.rb index 42f33dfc35f..9961ea56c42 100644 --- a/spec/lib/admin/metrics/measure/instance_follows_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/instance_follows_measure_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Admin::Metrics::Measure::InstanceFollowsMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let(:domain) { 'example.com' } @@ -24,10 +24,10 @@ describe Admin::Metrics::Measure::InstanceFollowsMeasure do Fabricate(:account, domain: "bar.#{domain}") end - describe 'total' do + describe '#total' do context 'without include_subdomains' do it 'returns the expected number of accounts' do - expect(measure.total).to eq 2 + expect(subject.total).to eq 2 end end @@ -35,14 +35,21 @@ describe Admin::Metrics::Measure::InstanceFollowsMeasure do let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') } it 'returns the expected number of accounts' do - expect(measure.total).to eq 4 + expect(subject.total).to eq 4 end end end describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + it 'returns correct instance_followers counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '0'), + include(date: 1.day.ago.midnight.to_time, value: '0'), + include(date: 0.days.ago.midnight.to_time, value: '2') + ) end end end diff --git a/spec/lib/admin/metrics/measure/instance_media_attachments_measure_spec.rb b/spec/lib/admin/metrics/measure/instance_media_attachments_measure_spec.rb index c103307f971..36344509306 100644 --- a/spec/lib/admin/metrics/measure/instance_media_attachments_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/instance_media_attachments_measure_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let(:domain) { 'example.com' } @@ -20,11 +20,11 @@ describe Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure do remote_account_on_subdomain.media_attachments.create!(file: attachment_fixture('attachment.jpg')) end - describe 'total' do + describe '#total' do context 'without include_subdomains' do it 'returns the expected number of accounts' do expected_total = remote_account.media_attachments.sum(:file_file_size) + remote_account.media_attachments.sum(:thumbnail_file_size) - expect(measure.total).to eq expected_total + expect(subject.total).to eq expected_total end end @@ -36,14 +36,25 @@ describe Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure do account.media_attachments.sum(:file_file_size) + account.media_attachments.sum(:thumbnail_file_size) end - expect(measure.total).to eq expected_total + expect(subject.total).to eq expected_total end end end describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + it 'returns correct media_attachments counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '0'), + include(date: 1.day.ago.midnight.to_time, value: '0'), + include(date: 0.days.ago.midnight.to_time, value: expected_domain_only_total.to_s) + ) + end + + def expected_domain_only_total + remote_account.media_attachments.sum(:file_file_size) + remote_account.media_attachments.sum(:thumbnail_file_size) end end end diff --git a/spec/lib/admin/metrics/measure/instance_reports_measure_spec.rb b/spec/lib/admin/metrics/measure/instance_reports_measure_spec.rb index 62fcf84ac13..ca64049d926 100644 --- a/spec/lib/admin/metrics/measure/instance_reports_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/instance_reports_measure_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Admin::Metrics::Measure::InstanceReportsMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let(:domain) { 'example.com' } @@ -21,10 +21,10 @@ describe Admin::Metrics::Measure::InstanceReportsMeasure do Fabricate(:report, target_account: Fabricate(:account, domain: "bar.#{domain}")) end - describe 'total' do + describe '#total' do context 'without include_subdomains' do it 'returns the expected number of accounts' do - expect(measure.total).to eq 2 + expect(subject.total).to eq 2 end end @@ -32,14 +32,21 @@ describe Admin::Metrics::Measure::InstanceReportsMeasure do let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') } it 'returns the expected number of accounts' do - expect(measure.total).to eq 5 + expect(subject.total).to eq 5 end end end describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + it 'returns correct instance_reports counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '0'), + include(date: 1.day.ago.midnight.to_time, value: '0'), + include(date: 0.days.ago.midnight.to_time, value: '2') + ) end end end diff --git a/spec/lib/admin/metrics/measure/instance_statuses_measure_spec.rb b/spec/lib/admin/metrics/measure/instance_statuses_measure_spec.rb index df4cfe207bc..ac28658ea07 100644 --- a/spec/lib/admin/metrics/measure/instance_statuses_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/instance_statuses_measure_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Admin::Metrics::Measure::InstanceStatusesMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let(:domain) { 'example.com' } @@ -21,10 +21,10 @@ describe Admin::Metrics::Measure::InstanceStatusesMeasure do Fabricate(:status, account: Fabricate(:account, domain: "bar.#{domain}")) end - describe 'total' do + describe '#total' do context 'without include_subdomains' do it 'returns the expected number of accounts' do - expect(measure.total).to eq 2 + expect(subject.total).to eq 2 end end @@ -32,14 +32,21 @@ describe Admin::Metrics::Measure::InstanceStatusesMeasure do let(:params) { ActionController::Parameters.new(domain: domain, include_subdomains: 'true') } it 'returns the expected number of accounts' do - expect(measure.total).to eq 5 + expect(subject.total).to eq 5 end end end describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + it 'returns correct instance_statuses counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '0'), + include(date: 1.day.ago.midnight.to_time, value: '0'), + include(date: 0.days.ago.midnight.to_time, value: '2') + ) end end end diff --git a/spec/lib/admin/metrics/measure/interactions_measure_spec.rb b/spec/lib/admin/metrics/measure/interactions_measure_spec.rb index e98c8305989..ed333380cfb 100644 --- a/spec/lib/admin/metrics/measure/interactions_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/interactions_measure_spec.rb @@ -3,15 +3,38 @@ require 'rails_helper' describe Admin::Metrics::Measure::InteractionsMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let(:start_at) { 2.days.ago } let(:end_at) { Time.now.utc } let(:params) { ActionController::Parameters.new } describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + context 'with activity tracking records' do + before do + 3.times do + travel_to(2.days.ago) { record_interaction_activity } + end + 2.times do + travel_to(1.day.ago) { record_interaction_activity } + end + travel_to(0.days.ago) { record_interaction_activity } + end + + it 'returns correct activity tracker counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '3'), + include(date: 1.day.ago.midnight.to_time, value: '2'), + include(date: 0.days.ago.midnight.to_time, value: '1') + ) + end + + def record_interaction_activity + ActivityTracker.increment('activity:interactions') + end end end end diff --git a/spec/lib/admin/metrics/measure/new_users_measure_spec.rb b/spec/lib/admin/metrics/measure/new_users_measure_spec.rb index fe82f8219b1..085acbcede8 100644 --- a/spec/lib/admin/metrics/measure/new_users_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/new_users_measure_spec.rb @@ -3,15 +3,30 @@ require 'rails_helper' describe Admin::Metrics::Measure::NewUsersMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let(:start_at) { 2.days.ago } let(:end_at) { Time.now.utc } let(:params) { ActionController::Parameters.new } describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + context 'with user records' do + before do + 3.times { Fabricate :user, created_at: 2.days.ago } + 2.times { Fabricate :user, created_at: 1.day.ago } + Fabricate :user, created_at: 0.days.ago + end + + it 'returns correct user counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '3'), + include(date: 1.day.ago.midnight.to_time, value: '2'), + include(date: 0.days.ago.midnight.to_time, value: '1') + ) + end end end end diff --git a/spec/lib/admin/metrics/measure/opened_reports_measure_spec.rb b/spec/lib/admin/metrics/measure/opened_reports_measure_spec.rb index deed64ae888..d5ba78527ea 100644 --- a/spec/lib/admin/metrics/measure/opened_reports_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/opened_reports_measure_spec.rb @@ -3,15 +3,30 @@ require 'rails_helper' describe Admin::Metrics::Measure::OpenedReportsMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let(:start_at) { 2.days.ago } let(:end_at) { Time.now.utc } let(:params) { ActionController::Parameters.new } describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + context 'with report records' do + before do + 3.times { Fabricate :report, created_at: 2.days.ago } + 2.times { Fabricate :report, created_at: 1.day.ago } + Fabricate :report, created_at: 0.days.ago + end + + it 'returns correct report counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '3'), + include(date: 1.day.ago.midnight.to_time, value: '2'), + include(date: 0.days.ago.midnight.to_time, value: '1') + ) + end end end end diff --git a/spec/lib/admin/metrics/measure/resolved_reports_measure_spec.rb b/spec/lib/admin/metrics/measure/resolved_reports_measure_spec.rb index cb98df2dc24..f7b497590d3 100644 --- a/spec/lib/admin/metrics/measure/resolved_reports_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/resolved_reports_measure_spec.rb @@ -3,15 +3,30 @@ require 'rails_helper' describe Admin::Metrics::Measure::ResolvedReportsMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let(:start_at) { 2.days.ago } let(:end_at) { Time.now.utc } let(:params) { ActionController::Parameters.new } describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + context 'with report records' do + before do + 3.times { Fabricate :report, action_taken_at: 2.days.ago } + 2.times { Fabricate :report, action_taken_at: 1.day.ago } + Fabricate :report, action_taken_at: 0.days.ago + end + + it 'returns correct report counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '3'), + include(date: 1.day.ago.midnight.to_time, value: '2'), + include(date: 0.days.ago.midnight.to_time, value: '1') + ) + end end end end diff --git a/spec/lib/admin/metrics/measure/tag_accounts_measure_spec.rb b/spec/lib/admin/metrics/measure/tag_accounts_measure_spec.rb index 938b67afa32..b33ae7bb710 100644 --- a/spec/lib/admin/metrics/measure/tag_accounts_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/tag_accounts_measure_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Admin::Metrics::Measure::TagAccountsMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let!(:tag) { Fabricate(:tag) } @@ -12,8 +12,39 @@ describe Admin::Metrics::Measure::TagAccountsMeasure do let(:params) { ActionController::Parameters.new(id: tag.id) } describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + context 'with tagged accounts' do + let(:alice) { Fabricate(:account, domain: 'alice.example') } + let(:bob) { Fabricate(:account, domain: 'bob.example') } + + before do + 3.times do + travel_to(2.days.ago) { add_tag_history(alice) } + end + + 2.times do + travel_to(1.day.ago) do + add_tag_history(alice) + add_tag_history(bob) + end + end + + add_tag_history(bob) + end + + it 'returns correct tag_accounts counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '1'), + include(date: 1.day.ago.midnight.to_time, value: '2'), + include(date: 0.days.ago.midnight.to_time, value: '1') + ) + end + + def add_tag_history(account) + tag.history.add(account.id) + end end end end diff --git a/spec/lib/admin/metrics/measure/tag_servers_measure_spec.rb b/spec/lib/admin/metrics/measure/tag_servers_measure_spec.rb index e09a2b04e5f..e1e2ced43a5 100644 --- a/spec/lib/admin/metrics/measure/tag_servers_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/tag_servers_measure_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Admin::Metrics::Measure::TagServersMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let!(:tag) { Fabricate(:tag) } @@ -12,8 +12,38 @@ describe Admin::Metrics::Measure::TagServersMeasure do let(:params) { ActionController::Parameters.new(id: tag.id) } describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + context 'with tagged statuses' do + let(:alice) { Fabricate(:account, domain: 'alice.example') } + let(:bob) { Fabricate(:account, domain: 'bob.example') } + + before do + 3.times do + status_alice = Fabricate(:status, account: alice, created_at: 2.days.ago) + status_alice.tags << tag + end + + 2.times do + status_alice = Fabricate(:status, account: alice, created_at: 1.day.ago) + status_alice.tags << tag + + status_bob = Fabricate(:status, account: bob, created_at: 1.day.ago) + status_bob.tags << tag + end + + status_bob = Fabricate(:status, account: bob, created_at: 0.days.ago) + status_bob.tags << tag + end + + it 'returns correct tag counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '1'), + include(date: 1.day.ago.midnight.to_time, value: '2'), + include(date: 0.days.ago.midnight.to_time, value: '1') + ) + end end end end diff --git a/spec/lib/admin/metrics/measure/tag_uses_measure_spec.rb b/spec/lib/admin/metrics/measure/tag_uses_measure_spec.rb index 869e9374459..dd66f00de05 100644 --- a/spec/lib/admin/metrics/measure/tag_uses_measure_spec.rb +++ b/spec/lib/admin/metrics/measure/tag_uses_measure_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Admin::Metrics::Measure::TagUsesMeasure do - subject(:measure) { described_class.new(start_at, end_at, params) } + subject { described_class.new(start_at, end_at, params) } let!(:tag) { Fabricate(:tag) } @@ -12,8 +12,39 @@ describe Admin::Metrics::Measure::TagUsesMeasure do let(:params) { ActionController::Parameters.new(id: tag.id) } describe '#data' do - it 'runs data query without error' do - expect { measure.data }.to_not raise_error + context 'with tagged accounts' do + let(:alice) { Fabricate(:account, domain: 'alice.example') } + let(:bob) { Fabricate(:account, domain: 'bob.example') } + + before do + 3.times do + travel_to(2.days.ago) { add_tag_history(alice) } + end + + 2.times do + travel_to(1.day.ago) do + add_tag_history(alice) + add_tag_history(bob) + end + end + + add_tag_history(bob) + end + + it 'returns correct tag_uses counts' do + expect(subject.data.size) + .to eq(3) + expect(subject.data.map(&:symbolize_keys)) + .to contain_exactly( + include(date: 2.days.ago.midnight.to_time, value: '3'), + include(date: 1.day.ago.midnight.to_time, value: '4'), + include(date: 0.days.ago.midnight.to_time, value: '1') + ) + end + + def add_tag_history(account) + tag.history.add(account.id) + end end end end