Skip to content

Commit

Permalink
Merge pull request #768 from scientist-softserv/adding-yop-to-filter-…
Browse files Browse the repository at this point in the history
…header

🐛 Add YOP to Report_Header > Report_Filters when provided
  • Loading branch information
jeremyf authored Sep 5, 2023
2 parents 42be90d + ea22823 commit af5079e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/sushi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def coerce_author(params = {})
module YearOfPublicationCoercion
extend ActiveSupport::Concern
included do
attr_reader :yop_as_where_parameters, :yop_in_params
attr_reader :yop_as_where_parameters, :yop
end

DATE_RANGE_REGEXP = /^(\d+)\s*-\s*(\d+)$/
Expand Down Expand Up @@ -347,7 +347,7 @@ def coerce_yop(params = {})
where_values << Integer(slug)
end
end

@yop = params[:yop]
@yop_as_where_parameters = ["(#{where_clauses.join(' OR ')})"] + where_values
rescue ArgumentError
raise Sushi::InvalidParameterValue.invalid_yop(params.fetch(:yop))
Expand Down
1 change: 1 addition & 0 deletions app/models/sushi/item_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def as_json(_options = {})
report_hash['Report_Header']['Report_Filters']['Item_ID'] = item_id if item_id_in_params
report_hash['Report_Header']['Report_Filters']['Metric_Type'] = metric_types if metric_type_in_params
report_hash['Report_Header']['Report_Filters']['Platform'] = platform if platform_in_params
report_hash['Report_Header']['Report_Filters']['YOP'] = yop if yop

report_hash
end
Expand Down
21 changes: 21 additions & 0 deletions spec/models/sushi/item_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@
expect(subject.dig('Report_Items', 0, 'Items', 0, 'Attribute_Performance', 0, 'Performance', 'Unique_Item_Investigations', '2023-08')).to eq(1)
expect(subject.dig('Report_Items', 2, 'Items', 0, 'Attribute_Performance', 0, 'Performance', 'Unique_Item_Investigations', '2022-01')).to eq(1)
end

describe 'yop parameter' do
context 'when provided' do
let(:params) do
{
**required_parameters,
yop: '1900-2023'
}
end

it 'has a Report_Header > Report_Filters > YOP property' do
expect(subject.dig("Report_Header", "Report_Filters", "YOP")).to eq('1900-2023')
end
end

context 'when not provided' do
it 'does not have a Report_Header > Report_Filters > YOP property' do
expect(subject.dig("Report_Header", "Report_Filters")).not_to have_key("YOP")
end
end
end
end

describe 'with an access_method parameter' do
Expand Down
1 change: 1 addition & 0 deletions spec/models/sushi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def initialize(params = {})
let(:params) { { yop: given_yop } }

if expected.is_a?(Array)
its(:yop) { is_expected.to eq(given_yop) }
its(:yop_as_where_parameters) { is_expected.to match_array(expected) }
else
it "raises an #{expected}" do
Expand Down

0 comments on commit af5079e

Please sign in to comment.