Skip to content

Commit

Permalink
Issue #705 - Ensure nameIdentifiers element of creators in dois retur…
Browse files Browse the repository at this point in the history
…ned by api is an array
  • Loading branch information
[email protected] committed Jan 16, 2021
1 parent c4d4bd4 commit b38f276
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions spec/requests/datacite_dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
"nameType" => "Personal",
"name" => "John Doe",
"affiliation" => [],
"nameIdentifiers" => [],
})
end

Expand All @@ -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
Expand Down Expand Up @@ -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" => {
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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" => {
Expand Down

0 comments on commit b38f276

Please sign in to comment.