Skip to content

Commit

Permalink
Add agency to dois response (#1281)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bklaing2 authored Nov 20, 2024
1 parent 30bdaac commit fdf9ec8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/datacite_dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}

Expand Down Expand Up @@ -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],
}

Expand Down Expand Up @@ -447,6 +449,7 @@ def show
composite: nil,
affiliation: params[:affiliation],
publisher: params[:publisher],
include_other_registration_agencies: params[:include_other_registration_agencies],
}

render(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -535,6 +539,7 @@ def create
detail: true,
affiliation: params[:affiliation],
publisher: params[:publisher],
include_other_registration_agencies: params[:include_other_registration_agencies],
}

render(
Expand Down Expand Up @@ -595,6 +600,7 @@ def update
detail: true,
affiliation: params[:affiliation],
publisher: params[:publisher],
include_other_registration_agencies: params[:include_other_registration_agencies],
}

render(
Expand Down
3 changes: 3 additions & 0 deletions app/serializers/datacite_doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions spec/requests/datacite_dois/datacite_dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand Down

0 comments on commit fdf9ec8

Please sign in to comment.