From 3d842061eacd2c4b8dfce6fef1e4597045e70f5c Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 10 Apr 2020 13:07:19 +0200 Subject: [PATCH] fix person specs --- app/graphql/schema.graphql | 16 +++++++++++++--- app/graphql/types/person_type.rb | 1 + app/models/person.rb | 4 ++-- spec/graphql/types/person_type_spec.rb | 13 +++++++++++++ spec/models/person_spec.rb | 2 ++ 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql index 225e3bfee..5083210b6 100644 --- a/app/graphql/schema.graphql +++ b/app/graphql/schema.graphql @@ -38,14 +38,14 @@ Information about affiliations """ type Affiliation { """ - Unique identifier for each affiliation + Affiliation ROR identifier """ id: ID """ Affiliation name """ - name: String + name: String! } type Audiovisual implements DoiItem { @@ -2052,7 +2052,7 @@ type Date { """ Date information for this resource """ - date: ISO8601Date! + date: ISO8601DateTime! """ The type of date @@ -3649,6 +3649,11 @@ An ISO 8601-encoded date """ scalar ISO8601Date +""" +An ISO 8601-encoded datetime +""" +scalar ISO8601DateTime + """ Information about identifiers """ @@ -6510,6 +6515,11 @@ type Person { """ name: String + """ + Other names. + """ + otherNames: [String!] + """ Authored publications """ diff --git a/app/graphql/types/person_type.rb b/app/graphql/types/person_type.rb index 8ec892d0a..e9e7f016f 100644 --- a/app/graphql/types/person_type.rb +++ b/app/graphql/types/person_type.rb @@ -8,6 +8,7 @@ class PersonType < BaseObject field :name, String, null: true, description: "The name of the person." field :given_name, String, null: true, description: "Given name. In the U.S., the first name of a Person." field :family_name, String, null: true, description: "Family name. In the U.S., the last name of an Person." + field :other_names, [String], null: true, description: "Other names." field :affiliation, [AffiliationType], null: true, description: "Affiliations(s) of the person." field :view_count, Integer, null: true, description: "The number of views according to the Counter Code of Practice." field :download_count, Integer, null: true, description: "The number of downloads according to the Counter Code of Practice." diff --git a/app/models/person.rb b/app/models/person.rb index e03149b5f..62da1c5c8 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -54,7 +54,7 @@ def self.parse_message(message: nil) orcid = message.fetch("orcid-id", nil) given_name = message.fetch("given-names", nil) family_name = message.fetch("family-names", nil) - other_name = message.fetch("other-name", nil) + other_names = Array.wrap(message.fetch("other-name", nil)) if message.fetch("credit-name", nil).present? name = message.fetch("credit-name") elsif given_name.present? || family_name.present? @@ -70,7 +70,7 @@ def self.parse_message(message: nil) orcid: orcid, given_name: given_name, family_name: family_name, - other_name: other_name, + other_names: other_names, name: name, affiliation: affiliation }.compact) end diff --git a/spec/graphql/types/person_type_spec.rb b/spec/graphql/types/person_type_spec.rb index 26dc6ba56..bcbf0a15b 100644 --- a/spec/graphql/types/person_type_spec.rb +++ b/spec/graphql/types/person_type_spec.rb @@ -9,6 +9,7 @@ it { is_expected.to have_field(:name).of_type("String") } it { is_expected.to have_field(:givenName).of_type("String") } it { is_expected.to have_field(:familyName).of_type("String") } + it { is_expected.to have_field(:otherNames).of_type("[String!]") } it { is_expected.to have_field(:citationCount).of_type("Int") } it { is_expected.to have_field(:viewCount).of_type("Int") } it { is_expected.to have_field(:downloadCount).of_type("Int") } @@ -48,6 +49,10 @@ name givenName familyName + otherNames + affiliation { + name + } citationCount viewCount downloadCount @@ -78,6 +83,10 @@ expect(response.dig("data", "person", "id")).to eq("https://orcid.org/0000-0003-3484-6875") expect(response.dig("data", "person", "name")).to eq("K. J. Garza") + expect(response.dig("data", "person", "givenName")).to eq("Kristian") + expect(response.dig("data", "person", "familyName")).to eq("Garza") + expect(response.dig("data", "person", "otherNames")).to eq([]) + expect(response.dig("data", "person", "affiliation")).to eq([]) expect(response.dig("data", "person", "citationCount")).to eq(0) expect(response.dig("data", "person", "works", "totalCount")).to eq(1) expect(response.dig("data", "person", "works", "years")).to eq([{"count"=>1, "title"=>"2011"}]) @@ -100,6 +109,7 @@ name givenName familyName + otherNames affiliation { name } @@ -123,6 +133,9 @@ person = response.dig("data", "people", "nodes", 0) expect(person.fetch("id")).to eq("https://orcid.org/0000-0002-6028-9323") expect(person.fetch("name")).to eq("Stephen A. Fenner") + expect(person.fetch("givenName")).to eq("Stephen") + expect(person.fetch("familyName")).to eq("Fenner") + expect(person.fetch("otherNames")).to eq([]) expect(person.fetch("affiliation")).to eq([{"name"=>"Harvard College"}, {"name"=>"University of Chicago"}, {"name"=>"University of South Carolina"}, diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 5010310dd..b56cb438e 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -43,6 +43,7 @@ expect(person.name).to eq("Letícia Rodrigues Bueno") expect(person.given_name).to eq("Letícia Rodrigues") expect(person.family_name).to eq("Bueno") + expect(person.other_names).to eq([]) expect(person.affiliation).to eq([{"name"=>"Universidade Estadual de Maringá"}, {"name"=>"Universidade Federal do ABC"}, {"name"=>"Universidade Federal do Rio de Janeiro"}]) @@ -74,6 +75,7 @@ expect(person.name).to eq("Patricia Cruse") expect(person.given_name).to eq("Patricia") expect(person.family_name).to eq("Cruse") + expect(person.other_names).to eq(["Trisha Cruse"]) expect(person.affiliation).to eq([{"name"=>"DataCite"}, {"name"=>"University of California Berkeley"}]) end end