From ac9c4fcb5e931d140484612631c02b082670f5bd Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Thu, 18 Oct 2018 22:43:05 +0200 Subject: [PATCH] support schema-org-id hash --- app/controllers/dois_controller.rb | 1 + spec/requests/dois_spec.rb | 66 ++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index caa78d078..fa45a4f04 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -343,6 +343,7 @@ def safe_params "download-latency", "has-schema-org", "schema-org-id", + { "schema-org-id" => ["@type", "value", "propertyID"] }, "dc-identifier", "citation-doi", "body-has-pid" diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index cf33feb83..d008c851d 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -1687,6 +1687,72 @@ expect(json.dig('data', 'attributes', 'state')).to eq("registered") end end + + context 'landing page schema-org-id hash' do + let(:url) { "https://blog.datacite.org/re3data-science-europe/" } + let(:xml) { "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48cmVzb3VyY2UgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeG1sbnM9Imh0dHA6Ly9kYXRhY2l0ZS5vcmcvc2NoZW1hL2tlcm5lbC00IiB4c2k6c2NoZW1hTG9jYXRpb249Imh0dHA6Ly9kYXRhY2l0ZS5vcmcvc2NoZW1hL2tlcm5lbC00IGh0dHA6Ly9zY2hlbWEuZGF0YWNpdGUub3JnL21ldGEva2VybmVsLTQvbWV0YWRhdGEueHNkIj48aWRlbnRpZmllciBpZGVudGlmaWVyVHlwZT0iRE9JIj4xMC4yNTQ5OS94dWRhMnB6cmFocm9lcXBlZnZucTV6dDZkYzwvaWRlbnRpZmllcj48Y3JlYXRvcnM+PGNyZWF0b3I+PGNyZWF0b3JOYW1lPklhbiBQYXJyeTwvY3JlYXRvck5hbWU+PG5hbWVJZGVudGlmaWVyIHNjaGVtZVVSST0iaHR0cDovL29yY2lkLm9yZy8iIG5hbWVJZGVudGlmaWVyU2NoZW1lPSJPUkNJRCI+MDAwMC0wMDAxLTYyMDItNTEzWDwvbmFtZUlkZW50aWZpZXI+PC9jcmVhdG9yPjwvY3JlYXRvcnM+PHRpdGxlcz48dGl0bGU+U3VibWl0dGVkIGNoZW1pY2FsIGRhdGEgZm9yIEluQ2hJS2V5PVlBUFFCWFFZTEpSWFNBLVVIRkZGQU9ZU0EtTjwvdGl0bGU+PC90aXRsZXM+PHB1Ymxpc2hlcj5Sb3lhbCBTb2NpZXR5IG9mIENoZW1pc3RyeTwvcHVibGlzaGVyPjxwdWJsaWNhdGlvblllYXI+MjAxNzwvcHVibGljYXRpb25ZZWFyPjxyZXNvdXJjZVR5cGUgcmVzb3VyY2VUeXBlR2VuZXJhbD0iRGF0YXNldCI+U3Vic3RhbmNlPC9yZXNvdXJjZVR5cGU+PHJpZ2h0c0xpc3Q+PHJpZ2h0cyByaWdodHNVUkk9Imh0dHBzOi8vY3JlYXRpdmVjb21tb25zLm9yZy9zaGFyZS15b3VyLXdvcmsvcHVibGljLWRvbWFpbi9jYzAvIj5ObyBSaWdodHMgUmVzZXJ2ZWQ8L3JpZ2h0cz48L3JpZ2h0c0xpc3Q+PC9yZXNvdXJjZT4=" } + let(:link_check_result) { { + "error" => nil, + "redirect-count" => 0, + "redirect-urls" => [], + "download-latency" => 200, + "has-schema-org" => true, + "schema-org-id" => [ + { + "@type" => "PropertyValue", + "value" => "http://dx.doi.org/10.4225/06/564AB348340D5", + "propertyID" => "URL" + } + ], + "dc-identifier" => nil, + "citation-doi" => nil, + "body-has-pid" => true + } } + let(:valid_attributes) do + { + "data" => { + "type" => "dois", + "attributes" => { + "doi" => "10.14454/10703", + "url" => url, + "xml" => xml, + "last-landing-page" => url, + "last-landing-page-status" => 200, + "last-landing-page-status-check" => Time.zone.now, + "last-landing-page-content-type" => "text/html", + "last-landing-page-status-result" => link_check_result, + "event" => "register" + }, + "relationships"=> { + "client"=> { + "data"=> { + "type"=> "clients", + "id"=> client.symbol.downcase + } + } + } + } + } + end + + before { post '/dois', params: valid_attributes.to_json, headers: headers } + + it 'creates a Doi' do + puts response.body + expect(json.dig('data', 'attributes', 'url')).to eq(url) + expect(json.dig('data', 'attributes', 'doi')).to eq("10.14454/10703") + expect(json.dig('data', 'attributes', 'landing-page', 'status')).to eq(200) + expect(json.dig('data', 'attributes', 'landing-page', 'result')).to eq(link_check_result) + end + + it 'returns status code 201' do + expect(response).to have_http_status(201) + end + + it 'sets state to registered' do + expect(json.dig('data', 'attributes', 'state')).to eq("registered") + end + end end describe 'DELETE /dois/:id' do