From fdf9ec8328413eaaf67bd18787374cfa92117ce9 Mon Sep 17 00:00:00 2001 From: Bryceson Laing Date: Wed, 20 Nov 2024 08:18:36 -0600 Subject: [PATCH] Add agency to dois response (#1281) * add agency to dois response * update spec for agency * only return agency when include_other_registration_agencies is set * pass include_other_registration_agencies to serializer --- app/controllers/datacite_dois_controller.rb | 8 +++++++- app/serializers/datacite_doi_serializer.rb | 3 +++ .../datacite_dois/datacite_dois_spec.rb | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/controllers/datacite_dois_controller.rb b/app/controllers/datacite_dois_controller.rb index 46c3d51b9..456e4822c 100644 --- a/app/controllers/datacite_dois_controller.rb +++ b/app/controllers/datacite_dois_controller.rb @@ -203,6 +203,7 @@ def index detail: params[:detail], affiliation: params[:affiliation], publisher: params[:publisher], + include_other_registration_agencies: params[:include_other_registration_agencies], is_collection: options[:is_collection], } @@ -349,6 +350,7 @@ def index composite: params[:composite], affiliation: params[:affiliation], publisher: params[:publisher], + include_other_registration_agencies: params[:include_other_registration_agencies], is_collection: options[:is_collection], } @@ -447,6 +449,7 @@ def show composite: nil, affiliation: params[:affiliation], publisher: params[:publisher], + include_other_registration_agencies: params[:include_other_registration_agencies], } render( @@ -504,7 +507,8 @@ def validate options[:params] = { current_ability: current_ability, affiliation: params[:affiliation], - publisher: params[:publisher] + publisher: params[:publisher], + include_other_registration_agencies: params[:include_other_registration_agencies], } render( @@ -535,6 +539,7 @@ def create detail: true, affiliation: params[:affiliation], publisher: params[:publisher], + include_other_registration_agencies: params[:include_other_registration_agencies], } render( @@ -595,6 +600,7 @@ def update detail: true, affiliation: params[:affiliation], publisher: params[:publisher], + include_other_registration_agencies: params[:include_other_registration_agencies], } render( diff --git a/app/serializers/datacite_doi_serializer.rb b/app/serializers/datacite_doi_serializer.rb index fc27235c5..41d70982a 100644 --- a/app/serializers/datacite_doi_serializer.rb +++ b/app/serializers/datacite_doi_serializer.rb @@ -65,6 +65,9 @@ class DataciteDoiSerializer :citations_over_time, if: Proc.new { |_object, params| params && params[:detail] } + attributes :agency, + if: Proc.new { |_object, params| params && params[:include_other_registration_agencies] } + belongs_to :client, record_type: :clients belongs_to :provider, diff --git a/spec/requests/datacite_dois/datacite_dois_spec.rb b/spec/requests/datacite_dois/datacite_dois_spec.rb index 4aa5593e9..14c3bcf02 100755 --- a/spec/requests/datacite_dois/datacite_dois_spec.rb +++ b/spec/requests/datacite_dois/datacite_dois_spec.rb @@ -438,6 +438,24 @@ def clear_doi_index end end + describe "GET /dois/:id with agency values", prefix_pool_size: 1 do + let!(:doi) { create(:doi, client: client, aasm_state: "findable") } + + it "returns agency values when flag is set" do + get "/dois/#{doi.doi}?include_other_registration_agencies=true", nil, headers + + expect(last_response.status).to eq(200) + expect(json.dig("data", "attributes", "agency")).to eq("datacite") + end + + it "does not returns agency values when flag isn't set" do + get "/dois/#{doi.doi}", nil, headers + + expect(last_response.status).to eq(200) + expect(json.dig("data", "attributes")).to_not have_key("agency") + end + end + describe "GET /dois with client-type filter", prefix_pool_size: 3 do let!(:dois) { create_list(:doi, 10, client: client, aasm_state: "findable", version_info: "testtag") } let(:client_igsn_id_catalog) { create(:client, provider: provider, client_type: "igsnCatalog") }