Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/datacite/lupo
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Feb 13, 2020
2 parents b09d687 + f6727cc commit 5f2be30
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ def index
dois_names = results.map { |result| result.dig(:_source, :doi) }.join(',')
metrics_array = get_metrics_array(dois_names)
results = mix_in_metrics_array(results, metrics_array)
end

if params[:user_stats]
person_metrics = get_person_metrics(params[:user_id])
citations = person_metrics[:citations]
views = person_metrics[:views]
Expand Down
1 change: 1 addition & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ def self.subj_id_check(options = {})

Rails.logger.warn "[DoubleCheck] DoubleCheck #{response.results.results.length} events starting with _id #{response.results.to_a.first[:_id]}."
cursor = response.results.to_a.last[:sort]
Rails.logger.warn "[DoubleCheck] Cursor: #{cursor} "

# dois = response.results.results.map(&:subj_id)
events = response.results.results
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/dois_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
let!(:doi) { create(:doi, client: client, aasm_state: "findable") }
let!(:events) { create_list(:event_for_datacite_related, 3, obj_id: doi.doi) }
let!(:views) { create_list(:event_for_datacite_usage, 2, obj_id: doi.doi, total: 25) }
let!(:orcid_event) { create(:event_for_datacite_orcid_auto_update, subj_id: doi.doi, obj_id:"https://orcid.org/0000-0003-1419-2405") }

before do
Event.import
Expand All @@ -151,6 +152,7 @@
expect(json['data'].size).to eq(1)
result = json.dig('data').select { |item| item["id"] == doi.doi.downcase }.first
expect(json.dig('meta', 'total')).to eq(1)
expect(json.dig('meta', 'views')).to be_a(Array)
expect(json.dig('data', 0, 'attributes', 'url')).to eq(doi.url)
expect(json.dig('data', 0, 'attributes', 'doi')).to eq(doi.doi.downcase)
expect(json.dig('data', 0, 'attributes', 'titles')).to eq(doi.titles)
Expand All @@ -160,6 +162,16 @@
expect(json.dig('data', 0, 'attributes', 'viewsOverTime')).to eq([{"total"=>25, "year_month"=>"2015-06"}, {"total"=>25, "year_month"=>"2015-06"}])
end

it 'includes events with query parameter' do
get "/dois?mix-in=metrics&user-stats=true&user-id=0000-0003-1419-2405", nil, headers

expect(last_response.status).to eq(200)
expect(json['data'].size).to eq(1)
result = json.dig('data').select { |item| item["id"] == doi.doi.downcase }.first
expect(json.dig('meta', 'total')).to eq(1)
expect(json.dig('meta', 'views')).to be > 0
end

it 'includes events without query parameter' do
get "/dois", nil, headers

Expand Down

0 comments on commit 5f2be30

Please sign in to comment.