diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index a3569b8dc..b21b9ceb7 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -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] diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index ebb68a0be..9e81c8ae5 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -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 @@ -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) @@ -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