1
0

Add coverage for admin/metrics base classes, simplify subclass generation (#29527)

This commit is contained in:
Matt Jankowski 2024-03-11 05:16:19 -04:00 committed by GitHub
parent b9722dfe2b
commit a7284690fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 67 additions and 23 deletions

View File

@ -2,15 +2,15 @@
class Admin::Metrics::Dimension
DIMENSIONS = {
languages: Admin::Metrics::Dimension::LanguagesDimension,
sources: Admin::Metrics::Dimension::SourcesDimension,
servers: Admin::Metrics::Dimension::ServersDimension,
space_usage: Admin::Metrics::Dimension::SpaceUsageDimension,
software_versions: Admin::Metrics::Dimension::SoftwareVersionsDimension,
tag_servers: Admin::Metrics::Dimension::TagServersDimension,
tag_languages: Admin::Metrics::Dimension::TagLanguagesDimension,
instance_accounts: Admin::Metrics::Dimension::InstanceAccountsDimension,
instance_languages: Admin::Metrics::Dimension::InstanceLanguagesDimension,
languages: LanguagesDimension,
sources: SourcesDimension,
servers: ServersDimension,
space_usage: SpaceUsageDimension,
software_versions: SoftwareVersionsDimension,
tag_servers: TagServersDimension,
tag_languages: TagLanguagesDimension,
instance_accounts: InstanceAccountsDimension,
instance_languages: InstanceLanguagesDimension,
}.freeze
def self.retrieve(dimension_keys, start_at, end_at, limit, params)

View File

@ -2,20 +2,20 @@
class Admin::Metrics::Measure
MEASURES = {
active_users: Admin::Metrics::Measure::ActiveUsersMeasure,
new_users: Admin::Metrics::Measure::NewUsersMeasure,
interactions: Admin::Metrics::Measure::InteractionsMeasure,
opened_reports: Admin::Metrics::Measure::OpenedReportsMeasure,
resolved_reports: Admin::Metrics::Measure::ResolvedReportsMeasure,
tag_accounts: Admin::Metrics::Measure::TagAccountsMeasure,
tag_uses: Admin::Metrics::Measure::TagUsesMeasure,
tag_servers: Admin::Metrics::Measure::TagServersMeasure,
instance_accounts: Admin::Metrics::Measure::InstanceAccountsMeasure,
instance_media_attachments: Admin::Metrics::Measure::InstanceMediaAttachmentsMeasure,
instance_reports: Admin::Metrics::Measure::InstanceReportsMeasure,
instance_statuses: Admin::Metrics::Measure::InstanceStatusesMeasure,
instance_follows: Admin::Metrics::Measure::InstanceFollowsMeasure,
instance_followers: Admin::Metrics::Measure::InstanceFollowersMeasure,
active_users: ActiveUsersMeasure,
new_users: NewUsersMeasure,
interactions: InteractionsMeasure,
opened_reports: OpenedReportsMeasure,
resolved_reports: ResolvedReportsMeasure,
tag_accounts: TagAccountsMeasure,
tag_uses: TagUsesMeasure,
tag_servers: TagServersMeasure,
instance_accounts: InstanceAccountsMeasure,
instance_media_attachments: InstanceMediaAttachmentsMeasure,
instance_reports: InstanceReportsMeasure,
instance_statuses: InstanceStatusesMeasure,
instance_follows: InstanceFollowsMeasure,
instance_followers: InstanceFollowersMeasure,
}.freeze
def self.retrieve(measure_keys, start_at, end_at, params)

View File

@ -0,0 +1,22 @@
# frozen_string_literal: true
require 'rails_helper'
describe Admin::Metrics::Dimension do
describe '.retrieve' do
subject { described_class.retrieve(reports, start_at, end_at, 5, params) }
let(:start_at) { 2.days.ago }
let(:end_at) { Time.now.utc }
let(:params) { ActionController::Parameters.new({ instance_accounts: [123], instance_languages: ['en'] }) }
let(:reports) { [:instance_accounts, :instance_languages] }
it 'returns instances of provided classes' do
expect(subject)
.to contain_exactly(
be_a(Admin::Metrics::Dimension::InstanceAccountsDimension),
be_a(Admin::Metrics::Dimension::InstanceLanguagesDimension)
)
end
end
end

View File

@ -0,0 +1,22 @@
# frozen_string_literal: true
require 'rails_helper'
describe Admin::Metrics::Measure do
describe '.retrieve' do
subject { described_class.retrieve(reports, start_at, end_at, params) }
let(:start_at) { 2.days.ago }
let(:end_at) { Time.now.utc }
let(:params) { ActionController::Parameters.new({ instance_accounts: [123], instance_followers: [123] }) }
let(:reports) { [:instance_accounts, :instance_followers] }
it 'returns instances of provided classes' do
expect(subject)
.to contain_exactly(
be_a(Admin::Metrics::Measure::InstanceAccountsMeasure),
be_a(Admin::Metrics::Measure::InstanceFollowersMeasure)
)
end
end
end