spec/doi_utils_spec.rb in briard-2.4.2 vs spec/doi_utils_spec.rb in briard-2.6.0

- old
+ new

@@ -1,314 +1,318 @@ # frozen_string_literal: true require 'spec_helper' describe Briard::Metadata, vcr: true do - let(:input) { "https://doi.org/10.1101/097196" } + subject { described_class.new(input: input, from: 'crossref') } - subject { Briard::Metadata.new(input: input, from: "crossref") } + let(:input) { 'https://doi.org/10.1101/097196' } - context "doi resolver" do - it "doi" do - doi = "10.5061/DRYAD.8515" + context 'doi resolver' do + it 'doi' do + doi = '10.5061/DRYAD.8515' response = subject.doi_resolver(doi) - expect(response).to eq("https://doi.org/") + expect(response).to eq('https://doi.org/') end - it "doi with protocol" do - doi = "doi:10.5061/DRYAD.8515" + it 'doi with protocol' do + doi = 'doi:10.5061/DRYAD.8515' response = subject.doi_resolver(doi) - expect(response).to eq("https://doi.org/") + expect(response).to eq('https://doi.org/') end - it "https url" do - doi = "https://doi.org/10.5061/dryad.8515" + it 'https url' do + doi = 'https://doi.org/10.5061/dryad.8515' response = subject.doi_resolver(doi) - expect(response).to eq("https://doi.org/") + expect(response).to eq('https://doi.org/') end - it "dx.doi.org url" do - doi = "http://dx.doi.org/10.5061/dryad.8515" + it 'dx.doi.org url' do + doi = 'http://dx.doi.org/10.5061/dryad.8515' response = subject.doi_resolver(doi) - expect(response).to eq("https://doi.org/") + expect(response).to eq('https://doi.org/') end - it "stage resolver" do - doi = "https://handle.stage.datacite.org/10.5061/dryad.8515" + it 'stage resolver' do + doi = 'https://handle.stage.datacite.org/10.5061/dryad.8515' response = subject.doi_resolver(doi) - expect(response).to eq("https://handle.stage.datacite.org/") + expect(response).to eq('https://handle.stage.datacite.org/') end - it "stage resolver http" do - doi = "http://handle.stage.datacite.org/10.5061/dryad.8515" + it 'stage resolver http' do + doi = 'http://handle.stage.datacite.org/10.5061/dryad.8515' response = subject.doi_resolver(doi) - expect(response).to eq("https://handle.stage.datacite.org/") + expect(response).to eq('https://handle.stage.datacite.org/') end - it "force stage resolver" do - doi = "https://doi.org/10.5061/dryad.8515" + it 'force stage resolver' do + doi = 'https://doi.org/10.5061/dryad.8515' response = subject.doi_resolver(doi, sandbox: true) - expect(response).to eq("https://handle.stage.datacite.org/") + expect(response).to eq('https://handle.stage.datacite.org/') end end - context "doi_api_url" do - it "doi" do - doi = "10.5061/DRYAD.8515" + context 'doi_api_url' do + it 'doi' do + doi = '10.5061/DRYAD.8515' response = subject.doi_api_url(doi) - expect(response).to eq("https://api.datacite.org/dois/10.5061/dryad.8515?include=media,client") + expect(response).to eq('https://api.datacite.org/dois/10.5061/dryad.8515?include=media,client') end - it "doi with protocol" do - doi = "doi:10.5061/DRYAD.8515" + it 'doi with protocol' do + doi = 'doi:10.5061/DRYAD.8515' response = subject.doi_api_url(doi) - expect(response).to eq("https://api.datacite.org/dois/10.5061/dryad.8515?include=media,client") + expect(response).to eq('https://api.datacite.org/dois/10.5061/dryad.8515?include=media,client') end - it "https url" do - doi = "https://doi.org/10.5061/dryad.8515" + it 'https url' do + doi = 'https://doi.org/10.5061/dryad.8515' response = subject.doi_api_url(doi) - expect(response).to eq("https://api.datacite.org/dois/10.5061/dryad.8515?include=media,client") + expect(response).to eq('https://api.datacite.org/dois/10.5061/dryad.8515?include=media,client') end - it "dx.doi.org url" do - doi = "http://dx.doi.org/10.5061/dryad.8515" + it 'dx.doi.org url' do + doi = 'http://dx.doi.org/10.5061/dryad.8515' response = subject.doi_api_url(doi) - expect(response).to eq("https://api.datacite.org/dois/10.5061/dryad.8515?include=media,client") + expect(response).to eq('https://api.datacite.org/dois/10.5061/dryad.8515?include=media,client') end - it "test resolver" do - doi = "https://handle.stage.datacite.org/10.5061/dryad.8515" + it 'test resolver' do + doi = 'https://handle.stage.datacite.org/10.5061/dryad.8515' response = subject.doi_api_url(doi) - expect(response).to eq("https://api.stage.datacite.org/dois/10.5061/dryad.8515?include=media,client") + expect(response).to eq('https://api.stage.datacite.org/dois/10.5061/dryad.8515?include=media,client') end - it "test resolver http" do - doi = "http://handle.stage.datacite.org/10.5061/dryad.8515" + it 'test resolver http' do + doi = 'http://handle.stage.datacite.org/10.5061/dryad.8515' response = subject.doi_api_url(doi) - expect(response).to eq("https://api.stage.datacite.org/dois/10.5061/dryad.8515?include=media,client") + expect(response).to eq('https://api.stage.datacite.org/dois/10.5061/dryad.8515?include=media,client') end - it "force test resolver" do - doi = "https://doi.org/10.5061/dryad.8515" + it 'force test resolver' do + doi = 'https://doi.org/10.5061/dryad.8515' response = subject.doi_api_url(doi, sandbox: true) - expect(response).to eq("https://api.stage.datacite.org/dois/10.5061/dryad.8515?include=media,client") + expect(response).to eq('https://api.stage.datacite.org/dois/10.5061/dryad.8515?include=media,client') end end - context "normalize doi" do - it "doi" do - doi = "10.5061/DRYAD.8515" + context 'normalize doi' do + it 'doi' do + doi = '10.5061/DRYAD.8515' response = subject.normalize_doi(doi) - expect(response).to eq("https://doi.org/10.5061/dryad.8515") + expect(response).to eq('https://doi.org/10.5061/dryad.8515') end - it "doi with protocol" do - doi = "doi:10.5061/DRYAD.8515" + it 'doi with protocol' do + doi = 'doi:10.5061/DRYAD.8515' response = subject.normalize_doi(doi) - expect(response).to eq("https://doi.org/10.5061/dryad.8515") + expect(response).to eq('https://doi.org/10.5061/dryad.8515') end - it "SICI doi" do - doi = "10.1890/0012-9658(2006)87[2832:tiopma]2.0.co;2" + it 'SICI doi' do + doi = '10.1890/0012-9658(2006)87[2832:tiopma]2.0.co;2' response = subject.normalize_doi(doi) - expect(response).to eq("https://doi.org/10.1890/0012-9658(2006)87%5B2832:tiopma%5D2.0.co;2") + expect(response).to eq('https://doi.org/10.1890/0012-9658(2006)87%5B2832:tiopma%5D2.0.co;2') end - it "https url" do - doi = "https://doi.org/10.5061/dryad.8515" + it 'https url' do + doi = 'https://doi.org/10.5061/dryad.8515' response = subject.normalize_doi(doi) - expect(response).to eq("https://doi.org/10.5061/dryad.8515") + expect(response).to eq('https://doi.org/10.5061/dryad.8515') end - it "dx.doi.org url" do - doi = "http://dx.doi.org/10.5061/dryad.8515" + it 'dx.doi.org url' do + doi = 'http://dx.doi.org/10.5061/dryad.8515' response = subject.normalize_doi(doi) - expect(response).to eq("https://doi.org/10.5061/dryad.8515") + expect(response).to eq('https://doi.org/10.5061/dryad.8515') end - it "not valid doi prefix" do - doi = "https://doi.org/20.5061/dryad.8515" + it 'not valid doi prefix' do + doi = 'https://doi.org/20.5061/dryad.8515' response = subject.normalize_doi(doi) - expect(response).to be_nil + expect(response.nil?).to be(true) end - it "doi prefix with string" do - doi = "https://doi.org/10.506X/dryad.8515" + it 'doi prefix with string' do + doi = 'https://doi.org/10.506X/dryad.8515' response = subject.normalize_doi(doi) - expect(response).to be_nil + expect(response.nil?).to be(true) end - it "doi prefix too long" do - doi = "https://doi.org/10.506123/dryad.8515" + it 'doi prefix too long' do + doi = 'https://doi.org/10.506123/dryad.8515' response = subject.normalize_doi(doi) - expect(response).to be_nil + expect(response.nil?).to be(true) end - it "doi from url without doi proxy" do - doi = "https://handle.net/10.5061/dryad.8515" + it 'doi from url without doi proxy' do + doi = 'https://handle.net/10.5061/dryad.8515' response = subject.normalize_doi(doi) - expect(response).to be_nil + expect(response.nil?).to be(true) end - it "url with one slash" do - doi = "https:/doi.org/10.5061/dryad.8515" + it 'url with one slash' do + doi = 'https:/doi.org/10.5061/dryad.8515' response = subject.normalize_doi(doi) - expect(response).to eq("https://doi.org/10.5061/dryad.8515") + expect(response).to eq('https://doi.org/10.5061/dryad.8515') end - it "doi from datacite sandbox" do - doi = "https://handle.stage.datacite.org/10.5438/55e5-t5c0" + it 'doi from datacite sandbox' do + doi = 'https://handle.stage.datacite.org/10.5438/55e5-t5c0' response = subject.normalize_doi(doi) - expect(response).to eq("https://handle.stage.datacite.org/10.5438/55e5-t5c0") + expect(response).to eq('https://handle.stage.datacite.org/10.5438/55e5-t5c0') end - it "doi force datacite sandbox" do - doi = "10.5438/55e5-t5c0" + it 'doi force datacite sandbox' do + doi = '10.5438/55e5-t5c0' response = subject.normalize_doi(doi, sandbox: true) - expect(response).to eq("https://handle.stage.datacite.org/10.5438/55e5-t5c0") + expect(response).to eq('https://handle.stage.datacite.org/10.5438/55e5-t5c0') end end - context "doi_from_url" do - it "url" do - doi = subject.doi_from_url("https://doi.org/10.5061/dryad.8515") - expect(doi).to eq("10.5061/dryad.8515") + context 'doi_from_url' do + it 'url' do + doi = subject.doi_from_url('https://doi.org/10.5061/dryad.8515') + expect(doi).to eq('10.5061/dryad.8515') end - it "doi" do - doi = subject.doi_from_url("10.5061/dryad.8515") - expect(doi).to eq("10.5061/dryad.8515") + it 'doi' do + doi = subject.doi_from_url('10.5061/dryad.8515') + expect(doi).to eq('10.5061/dryad.8515') end - it "doi with special characters" do - doi = subject.doi_from_url("10.5067/terra+aqua/ceres/cldtyphist_l3.004") - expect(doi).to eq("10.5067/terra+aqua/ceres/cldtyphist_l3.004") + it 'doi with special characters' do + doi = subject.doi_from_url('10.5067/terra+aqua/ceres/cldtyphist_l3.004') + expect(doi).to eq('10.5067/terra+aqua/ceres/cldtyphist_l3.004') end - it "not a doi" do - doi = subject.doi_from_url("https://doi.org/10.5061") - expect(doi).to be nil + it 'not a doi' do + doi = subject.doi_from_url('https://doi.org/10.5061') + expect(doi.nil?).to be(true) end - it "sandbox url" do - doi = subject.doi_from_url("https://handle.stage.datacite.org/10.5438/55e5-t5c0") - expect(doi).to eq("10.5438/55e5-t5c0") + it 'sandbox url' do + doi = subject.doi_from_url('https://handle.stage.datacite.org/10.5438/55e5-t5c0') + expect(doi).to eq('10.5438/55e5-t5c0') end end - context "doi registration agency" do - it "datacite" do - doi = "https://doi.org/10.5061/dryad.8515" + context 'doi registration agency' do + it 'datacite' do + doi = 'https://doi.org/10.5061/dryad.8515' response = subject.get_doi_ra(doi) - expect(response).to eq("DataCite") + expect(response).to eq('DataCite') end - it "crossref" do - doi = "10.1371/journal.pone.0000030" + it 'crossref' do + doi = '10.1371/journal.pone.0000030' response = subject.get_doi_ra(doi) - expect(response).to eq("Crossref") + expect(response).to eq('Crossref') end - it "medra" do - doi = "https://doi.org/10.1392/roma081203" + it 'medra' do + doi = 'https://doi.org/10.1392/roma081203' response = subject.get_doi_ra(doi) - expect(response).to eq("mEDRA") + expect(response).to eq('mEDRA') end - it "kisti" do - doi = "https://doi.org/10.5012/bkcs.2013.34.10.2889" + it 'kisti' do + doi = 'https://doi.org/10.5012/bkcs.2013.34.10.2889' response = subject.get_doi_ra(doi) - expect(response).to eq("KISTI") + expect(response).to eq('KISTI') end - it "jalc" do - doi = "https://doi.org/10.11367/grsj1979.12.283" + it 'jalc' do + doi = 'https://doi.org/10.11367/grsj1979.12.283' response = subject.get_doi_ra(doi) - expect(response).to eq("JaLC") + expect(response).to eq('JaLC') end - it "op" do - doi = "https://doi.org/10.2791/81962" + it 'op' do + doi = 'https://doi.org/10.2791/81962' response = subject.get_doi_ra(doi) - expect(response).to eq("OP") + expect(response).to eq('OP') end - it "not a valid prefix" do - doi = "https://doi.org/10.a/dryad.8515x" + it 'not a valid prefix' do + doi = 'https://doi.org/10.a/dryad.8515x' response = subject.get_doi_ra(doi) - expect(response).to be_nil + expect(response.nil?).to be(true) end - it "not found" do - doi = "https://doi.org/10.99999/dryad.8515x" + it 'not found' do + doi = 'https://doi.org/10.99999/dryad.8515x' response = subject.get_doi_ra(doi) - expect(response).to be_nil + expect(response.nil?).to be(true) end end - context "validate doi" do - it "doi" do - doi = "10.5061/dryad.8515" + context 'validate doi' do + it 'doi' do + doi = '10.5061/dryad.8515' response = subject.validate_doi(doi) - expect(response).to eq("10.5061/dryad.8515") + expect(response).to eq('10.5061/dryad.8515') end end - context "validate funder doi" do - it "funder doi" do - doi = "10.13039/501100001711" + context 'validate funder doi' do + it 'funder doi' do + doi = '10.13039/501100001711' response = subject.validate_funder_doi(doi) - expect(response).to eq("https://doi.org/10.13039/501100001711") + expect(response).to eq('https://doi.org/10.13039/501100001711') end - it "funder doi without prefix" do - doi = "501100001711" + it 'funder doi without prefix' do + doi = '501100001711' response = subject.validate_funder_doi(doi) - expect(response).to eq("https://doi.org/10.13039/501100001711") + expect(response).to eq('https://doi.org/10.13039/501100001711') end - it "non-funder doi" do - doi = "10.5061/dryad.8515" + it 'non-funder doi' do + doi = '10.5061/dryad.8515' response = subject.validate_funder_doi(doi) - expect(response).to be_nil + expect(response.nil?).to be(true) end - it { expect(subject.validate_funder_doi("10.13039/100000050")).to eq "https://doi.org/10.13039/100000050" } - it { expect(subject.validate_funder_doi("10.13039/100006492")).to eq "https://doi.org/10.13039/100006492" } - it { expect(subject.validate_funder_doi('http://handle.test.datacite.org/10.13039/100000080')).to eq "https://doi.org/10.13039/100000080" } - it { expect(subject.validate_funder_doi('https://doi.org/10.13039/100000001')).to eq "https://doi.org/10.13039/100000001" } - it { expect(subject.validate_funder_doi('http://doi.org/10.13039/501100001711')).to eq "https://doi.org/10.13039/501100001711" } - it { expect(subject.validate_funder_doi('https://dx.doi.org/10.13039/501100001711')).to eq "https://doi.org/10.13039/501100001711" } - it { expect(subject.validate_funder_doi('doi:10.13039/501100001711')).to eq "https://doi.org/10.13039/501100001711" } - it { expect(subject.validate_funder_doi('10.13039/501100001711')).to eq "https://doi.org/10.13039/501100001711" } - it { expect(subject.validate_funder_doi('501100001711')).to eq "https://doi.org/10.13039/501100001711" } - it { expect(subject.validate_funder_doi("https://doi.org/10.13039/5monkeymonkey")).to be_nil } - it { expect(subject.validate_funder_doi('10.13039/5monkeymonkey')).to be_nil } + it { expect(subject.validate_funder_doi('10.13039/100000050')).to eq 'https://doi.org/10.13039/100000050' } + it { expect(subject.validate_funder_doi('10.13039/100006492')).to eq 'https://doi.org/10.13039/100006492' } + + it { + expect(subject.validate_funder_doi('http://handle.test.datacite.org/10.13039/100000080')).to eq 'https://doi.org/10.13039/100000080' + } + + it { expect(subject.validate_funder_doi('https://doi.org/10.13039/100000001')).to eq 'https://doi.org/10.13039/100000001' } + it { expect(subject.validate_funder_doi('http://doi.org/10.13039/501100001711')).to eq 'https://doi.org/10.13039/501100001711' } + it { expect(subject.validate_funder_doi('https://dx.doi.org/10.13039/501100001711')).to eq 'https://doi.org/10.13039/501100001711' } + it { expect(subject.validate_funder_doi('doi:10.13039/501100001711')).to eq 'https://doi.org/10.13039/501100001711' } + it { expect(subject.validate_funder_doi('10.13039/501100001711')).to eq 'https://doi.org/10.13039/501100001711' } + it { expect(subject.validate_funder_doi('501100001711')).to eq 'https://doi.org/10.13039/501100001711' } + it { expect(subject.validate_funder_doi('https://doi.org/10.13039/5monkeymonkey').nil?).to be(true) } + it { expect(subject.validate_funder_doi('10.13039/5monkeymonkey').nil?).to be(true) } end - context "validate prefix" do - it "doi" do - doi = "10.5061/dryad.8515" + context 'validate prefix' do + it 'doi' do + doi = '10.5061/dryad.8515' response = subject.validate_prefix(doi) - expect(response).to eq("10.5061") + expect(response).to eq('10.5061') end - it "doi with protocol" do - doi = "doi:10.5061/dryad.8515" + it 'doi with protocol' do + doi = 'doi:10.5061/dryad.8515' response = subject.validate_prefix(doi) - expect(response).to eq("10.5061") + expect(response).to eq('10.5061') end - it "doi as url" do - doi = "https://doi.org/10.5061/dryad.8515" + it 'doi as url' do + doi = 'https://doi.org/10.5061/dryad.8515' response = subject.validate_prefix(doi) - expect(response).to eq("10.5061") + expect(response).to eq('10.5061') end - it "only prefix" do - doi = "10.5061" + it 'only prefix' do + doi = '10.5061' response = subject.validate_prefix(doi) - expect(response).to eq("10.5061") + expect(response).to eq('10.5061') end end end