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

shrike
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 class Admin::Metrics::Dimension
DIMENSIONS = { DIMENSIONS = {
languages: Admin::Metrics::Dimension::LanguagesDimension, languages: LanguagesDimension,
sources: Admin::Metrics::Dimension::SourcesDimension, sources: SourcesDimension,
servers: Admin::Metrics::Dimension::ServersDimension, servers: ServersDimension,
space_usage: Admin::Metrics::Dimension::SpaceUsageDimension, space_usage: SpaceUsageDimension,
software_versions: Admin::Metrics::Dimension::SoftwareVersionsDimension, software_versions: SoftwareVersionsDimension,
tag_servers: Admin::Metrics::Dimension::TagServersDimension, tag_servers: TagServersDimension,
tag_languages: Admin::Metrics::Dimension::TagLanguagesDimension, tag_languages: TagLanguagesDimension,
instance_accounts: Admin::Metrics::Dimension::InstanceAccountsDimension, instance_accounts: InstanceAccountsDimension,
instance_languages: Admin::Metrics::Dimension::InstanceLanguagesDimension, instance_languages: InstanceLanguagesDimension,
}.freeze }.freeze
def self.retrieve(dimension_keys, start_at, end_at, limit, params) def self.retrieve(dimension_keys, start_at, end_at, limit, params)

View File

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