Skip to content

Commit

Permalink
properly support claims. #623
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Oct 4, 2020
1 parent 1cdcc6b commit 4a1c40b
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3553,7 +3553,7 @@ type Error {
"""
The error status.
"""
status: Int!
status: Int

"""
The error description.
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/error_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
class ErrorType < BaseObject
description "Information about errors"

field :status, Int, null: false, description: "The error status."
field :status, Int, null: true, description: "The error status."
field :title, String, null: false, description: "The error description."
end
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
ENV['SITE_TITLE'] ||= "DataCite REST API"
ENV['LOG_LEVEL'] ||= "info"
ENV['CONCURRENCY'] ||= "25"
ENV['API_URL'] ||= "https://api.test.datacite.org"
ENV['API_URL'] ||= "https://api.stage.datacite.org"
ENV['CDN_URL'] ||= "https://assets.datacite.org"
ENV['BRACCO_URL'] ||= "https://doi.datacite.org"
ENV['GITHUB_URL'] ||= "https://github.com/datacite/lupo"
Expand Down
8 changes: 8 additions & 0 deletions config/initializers/cors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
allow do
origins '*'

resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end

allow do
origins 'localhost:3000', /\Ahttps:\/\/*.datacite.org\z/

resource '*',
headers: :any,
expose: ["X-Credential-Username", "X-Anonymous-Consumer"],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 41 additions & 3 deletions spec/graphql/types/work_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
end

describe "find work with claims", elasticsearch: true, vcr: true do
let!(:work) { create(:doi, doi: "10.13140/RG.2.1.3847.9844", aasm_state: "findable") }
let!(:work) { create(:doi, doi: "10.17863/cam.536", aasm_state: "findable") }

before do
Doi.import
Expand All @@ -94,17 +94,55 @@
sourceId
state
claimed
errorMessages {
status
title
}
}
}
})
end

it "returns work" do
current_user = User.new(User.generate_token(uid: "0000-0001-5663-772X", aud: "stage"))
response = LupoSchema.execute(query, context: { current_user: current_user }).as_json

expect(response.dig("data", "work", "id")).to eq("https://handle.test.datacite.org/#{work.doi.downcase}")
expect(response.dig("data", "work", "claims")).to eq([{"claimed"=>"2017-10-16T11:15:01Z", "errorMessages"=>[], "sourceId"=>"orcid_update", "state"=>"done"}])
end
end

describe "find work with claims and errors", elasticsearch: true, vcr: true do
let!(:work) { create(:doi, doi: "10.70048/sc61-b496", aasm_state: "findable") }

before do
Doi.import
sleep 2
end

let(:query) do
%(query {
work(id: "https://doi.org/#{work.doi}") {
id
claims {
sourceId
state
claimed
errorMessages {
status
title
}
}
}
})
end

it "returns work" do
current_user = User.new(User.generate_token(uid: "0000-0003-0302-7658", aud: "stage"))
current_user = User.new(User.generate_token(uid: "0000-0002-7352-517X", aud: "stage"))
response = LupoSchema.execute(query, context: { current_user: current_user }).as_json

expect(response.dig("data", "work", "id")).to eq("https://handle.test.datacite.org/#{work.doi.downcase}")
expect(response.dig("data", "work", "claims")).to eq([{"claimed"=>"2016-04-14T22:20:24Z", "sourceId"=>"orcid_search", "state"=>"done"}])
expect(response.dig("data", "work", "claims")).to eq([{"claimed"=>nil, "errorMessages"=>[{"status"=>nil, "title"=>"Missing data"}], "sourceId"=>"orcid_update", "state"=>"failed"}])
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/models/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
it { is_expected.to be_able_to(:create, provider) }
it { is_expected.to be_able_to(:update, provider) }
it { is_expected.to be_able_to(:destroy, provider) }
it { is_expected.not_to be_able_to(:transfer, client) }
it { is_expected.to be_able_to(:transfer, client) }

it { is_expected.to be_able_to(:read, client) }
it { is_expected.to be_able_to(:create, client) }
Expand Down

0 comments on commit 4a1c40b

Please sign in to comment.