Skip to content

Commit

Permalink
fix person specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 10, 2020
1 parent 567071e commit 3d84206
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
16 changes: 13 additions & 3 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -2052,7 +2052,7 @@ type Date {
"""
Date information for this resource
"""
date: ISO8601Date!
date: ISO8601DateTime!

"""
The type of date
Expand Down Expand Up @@ -3649,6 +3649,11 @@ An ISO 8601-encoded date
"""
scalar ISO8601Date

"""
An ISO 8601-encoded datetime
"""
scalar ISO8601DateTime

"""
Information about identifiers
"""
Expand Down Expand Up @@ -6510,6 +6515,11 @@ type Person {
"""
name: String

"""
Other names.
"""
otherNames: [String!]

"""
Authored publications
"""
Expand Down
1 change: 1 addition & 0 deletions app/graphql/types/person_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/graphql/types/person_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand Down Expand Up @@ -48,6 +49,10 @@
name
givenName
familyName
otherNames
affiliation {
name
}
citationCount
viewCount
downloadCount
Expand Down Expand Up @@ -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"}])
Expand All @@ -100,6 +109,7 @@
name
givenName
familyName
otherNames
affiliation {
name
}
Expand All @@ -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"},
Expand Down
2 changes: 2 additions & 0 deletions spec/models/person_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"}])
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3d84206

Please sign in to comment.