From ea22823a6bd81133406e7b5a085b4328d815e0c4 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Tue, 5 Sep 2023 16:07:56 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Add=20YOP=20to=20Report=5FHeader?= =?UTF-8?q?=20>=20Report=5FFilters=20when=20provided?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prior to this commit, when given a YOP we were not providing that value as part of the response document. With this commit, when we're provided a YOP, we include that as part of the "Report_Header > Report_Filters". Related to: - https://github.com/scientist-softserv/palni-palci/issues/720 - https://github.com/scientist-softserv/palni-palci/issues/687 --- app/models/sushi.rb | 4 ++-- app/models/sushi/item_report.rb | 1 + spec/models/sushi/item_report_spec.rb | 21 +++++++++++++++++++++ spec/models/sushi_spec.rb | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/app/models/sushi.rb b/app/models/sushi.rb index 3d344a43b..173e0b6f0 100644 --- a/app/models/sushi.rb +++ b/app/models/sushi.rb @@ -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+)$/ @@ -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)) diff --git a/app/models/sushi/item_report.rb b/app/models/sushi/item_report.rb index 6dc11a672..3ab308fcf 100644 --- a/app/models/sushi/item_report.rb +++ b/app/models/sushi/item_report.rb @@ -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 diff --git a/spec/models/sushi/item_report_spec.rb b/spec/models/sushi/item_report_spec.rb index d55e56fe1..a0a61e40e 100644 --- a/spec/models/sushi/item_report_spec.rb +++ b/spec/models/sushi/item_report_spec.rb @@ -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 diff --git a/spec/models/sushi_spec.rb b/spec/models/sushi_spec.rb index c879796c6..bf47eb985 100644 --- a/spec/models/sushi_spec.rb +++ b/spec/models/sushi_spec.rb @@ -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