Skip to content

Commit

Permalink
condition user stats
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Feb 12, 2020
1 parent 6d44214 commit f6727cc
Show file tree
Hide file tree
Showing 2 changed files with 14 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
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 f6727cc

Please sign in to comment.