Skip to content

Commit

Permalink
Merge pull request #890 from scientist-softserv/i686-or-conditions
Browse files Browse the repository at this point in the history
🐛 Handle "or" behavior for specified metric types
  • Loading branch information
jeremyf authored Oct 30, 2023
2 parents 1cf1dcd + f16df37 commit b987092
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/sushi/platform_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ def as_json(_options = {})
alias to_hash as_json

def attribute_performance_for_resource_types
return [] if metric_type_in_params && metric_types.include?("Searches_Platform")
# We want to consider "or" behavior for multiple metric_types. Namely if you specify any
# metric type (other than Searches_Platform) you're going to get results.
#
# See https://github.com/scientist-softserv/palni-palci/issues/686#issuecomment-1785326034
return [] if metric_type_in_params && (metric_types & (ALLOWED_METRIC_TYPES - ['Searches_Platform'])).count.zero?

data_for_resource_types.map do |record|
{
Expand Down
14 changes: 14 additions & 0 deletions spec/models/sushi/platform_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@
end
end

context 'when given metric_types searches_platform AND total_item_requests' do
let(:params) do
{
begin_date: '2023-08',
end_date: '2023-09',
metric_type: 'total_item_requests|searches_platform'
}
end

it 'includes the platform data type and the article data type (which is the only data type within the date range' do
expect(subject.dig('Report_Items', 'Attribute_Performance').map { |ap| ap['Data_Type'] }.sort).to match_array(['Article', 'Platform'])
end
end

context 'with additional params that are not required' do
let(:params) do
{
Expand Down

0 comments on commit b987092

Please sign in to comment.