diff --git a/app/serializers/datacite_doi_serializer.rb b/app/serializers/datacite_doi_serializer.rb index 98897079d..d3414694a 100644 --- a/app/serializers/datacite_doi_serializer.rb +++ b/app/serializers/datacite_doi_serializer.rb @@ -126,6 +126,7 @@ class DataciteDoiSerializer Array.wrap(c["affiliation"]).map do |a| params[:affiliation] ? a : a["name"] end.compact + c["nameIdentifiers"] = Array.wrap(c["nameIdentifiers"]) c end.compact end diff --git a/spec/requests/datacite_dois_spec.rb b/spec/requests/datacite_dois_spec.rb index 60e3281c8..dc5309bb5 100644 --- a/spec/requests/datacite_dois_spec.rb +++ b/spec/requests/datacite_dois_spec.rb @@ -350,6 +350,7 @@ "nameType" => "Personal", "name" => "John Doe", "affiliation" => [], + "nameIdentifiers" => [], }) end @@ -360,6 +361,28 @@ expect(json.dig("data", "attributes", "creators")).to eq([doi.creators]) end end + + context "nameIdentifiers started as an object not array" do + let(:doi) do + create(:doi, client: client, creators: + [{ + "nameType" => "Personal", + "name" => "John Doe", + "affiliation" => [], + "nameIdentifiers": { + "nameIdentifier": "http://viaf.org/viaf/4934600", + "nameIdentifierScheme": "VIAF" + }, + }]) + end + + it "returns the nameIdentifiers as list" do + get "/dois/#{doi.doi}", nil, headers + + expect(last_response.status).to eq(200) + expect(json.dig("data", "attributes", "creators", 0, "nameIdentifiers")).to eq([{ "nameIdentifier" => "http://viaf.org/viaf/4934600", "nameIdentifierScheme" => "VIAF"}]) + end + end end describe "GET /dois for dissertations", elasticsearch: true, vcr: true do @@ -1357,7 +1380,7 @@ context "when the creators change" do let(:xml) { Base64.strict_encode64(file_fixture("datacite.xml").read) } - let(:creators) { [{ "affiliation" => [], "name" => "Ollomi, Benjamin" }, { "affiliation" => [], "name" => "Duran, Patrick" }] } + let(:creators) { [{ "affiliation" => [], "nameIdentifiers" => [], "name" => "Ollomi, Benjamin" }, { "affiliation" => [], "nameIdentifiers" => [], "name" => "Duran, Patrick" }] } let(:valid_attributes) do { "data" => { @@ -2472,7 +2495,7 @@ end context "when the creators change" do - let(:creators) { [{ "affiliation" => [], "name" => "Ollomi, Benjamin" }, { "affiliation" => [], "name" => "Duran, Patrick" }] } + let(:creators) { [{ "affiliation" => [], "nameIdentifiers" => [], "name" => "Ollomi, Benjamin" }, { "affiliation" => [], "nameIdentifiers" => [], "name" => "Duran, Patrick" }] } let(:xml) { Base64.strict_encode64(file_fixture("datacite.xml").read) } let(:valid_attributes) do { @@ -3188,7 +3211,7 @@ end context "update multiple affiliations" do - let(:creators) { [{ "name" => "Ollomi, Benjamin", "affiliation" => [{ "name" => "Cambridge University" }, { "name" => "EMBL-EBI" }] }] } + let(:creators) { [{ "name" => "Ollomi, Benjamin", "affiliation" => [{ "name" => "Cambridge University" }, { "name" => "EMBL-EBI" }], "nameIdentifiers" => [] }] } let(:update_attributes) do { "data" => {