From 9a544dafc0349853df7c184db66869bb74bc534c Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 23 Aug 2019 09:06:04 +0200 Subject: [PATCH] fix specs --- .../DOI/get-url/no_password/returns_url.yml | 32 +++++++++++++++ spec/requests/dois_spec.rb | 40 ++----------------- 2 files changed, 35 insertions(+), 37 deletions(-) create mode 100644 spec/fixtures/vcr_cassettes/dois/GET_/dois/DOI/get-url/no_password/returns_url.yml diff --git a/spec/fixtures/vcr_cassettes/dois/GET_/dois/DOI/get-url/no_password/returns_url.yml b/spec/fixtures/vcr_cassettes/dois/GET_/dois/DOI/get-url/no_password/returns_url.yml new file mode 100644 index 000000000..371a4fd0d --- /dev/null +++ b/spec/fixtures/vcr_cassettes/dois/GET_/dois/DOI/get-url/no_password/returns_url.yml @@ -0,0 +1,32 @@ +--- +http_interactions: +- request: + method: get + uri: https://handle.test.datacite.org/api/handles/10.14454/05MB-Q396?index=1 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Mozilla/5.0 (compatible; Maremma/4.2.6; mailto:info@datacite.org) + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: OK + headers: + Date: + - Fri, 23 Aug 2019 06:55:15 GMT + Content-Type: + - application/json;charset=UTF-8 + Connection: + - keep-alive + Vary: + - Accept-Encoding + body: + encoding: ASCII-8BIT + string: '{"responseCode":1,"handle":"10.14454/05MB-Q396","values":[{"index":1,"type":"URL","data":{"format":"string","value":"https://www.datacite.org/roadmap.html"},"ttl":86400,"timestamp":"2018-07-20T11:49:02Z"}]}' + http_version: + recorded_at: Fri, 23 Aug 2019 06:55:15 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index 7bd6ae9b9..4e42f1983 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -2854,45 +2854,11 @@ sleep 1 end - it 'returns error' do - get "/dois/#{doi.doi}/get-url", nil, { 'HTTP_ACCEPT'=>'application/vnd.api+json' } - - expect(last_response.status).to eq(401) - expect(json['errors']).to eq([{"status"=>"401", "title"=>"Bad credentials."}]) - end - end - - context 'wrong password' do - let!(:doi) { create(:doi, client: client, doi: "10.14454/05mb-q396", event: "publish") } - let(:credentials) { client.encode_auth_param(username: client.symbol.downcase, password: "12345") } - - before do - Doi.import - sleep 1 - end - - it 'returns error' do - get "/dois/#{doi.doi}/get-url", nil, { 'HTTP_ACCEPT'=>'application/vnd.api+json', 'HTTP_AUTHORIZATION' => 'Basic ' + credentials } - - expect(last_response.status).to eq(401) - expect(json['errors']).to eq([{"status"=>"401", "title"=>"Bad credentials."}]) - end - end - - context 'no permission' do - let(:other_client) { create(:client, provider: provider) } - let!(:doi) { create(:doi, client: other_client, doi: "10.14454/8syz-ym47", event: "publish") } - - before do - Doi.import - sleep 1 - end - - it 'returns error' do + it 'returns url' do get "/dois/#{doi.doi}/get-url", nil, headers - expect(last_response.status).to eq(403) - expect(json['errors']).to eq([{"status"=>"403", "title"=>"You are not authorized to access this resource."}]) + expect(json["url"]).to eq("https://www.datacite.org/roadmap.html") + expect(last_response.status).to eq(200) end end