From f0a1e88662757f64a60cb472760278e7c3e7686f Mon Sep 17 00:00:00 2001 From: kjgarza Date: Wed, 22 Jan 2020 23:47:31 +0100 Subject: [PATCH 1/2] uncomment test --- spec/requests/providers_spec.rb | 39 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/spec/requests/providers_spec.rb b/spec/requests/providers_spec.rb index 359504455..1d9c11186 100644 --- a/spec/requests/providers_spec.rb +++ b/spec/requests/providers_spec.rb @@ -96,29 +96,28 @@ end end - # describe 'GET /providers/totals' do - # let(:provider) { create(:provider) } - # let(:client) { create(:client, provider: provider) } - # let!(:prefixes) { create_list(:prefix, 10) } - # let!(:dois) { create_list(:doi, 3, client: client, aasm_state: "findable") } - - # before do - # Provider.import - # Client.import - # sleep 2 - # end + describe 'GET /providers/totals' do + let(:provider) { create(:provider) } + let(:client) { create(:client, provider: provider) } + let!(:prefixes) { create_list(:prefix, 10) } + let!(:dois) { create_list(:doi, 3, client: client, aasm_state: "findable") } - # it "returns providers" do - # get "/providers/totals", nil, headers + before do + Provider.import + Client.import + Doi.import + sleep 3 + end - # puts last_response.body + it "returns providers" do + get "/providers/totals", nil, headers - # expect(last_response.status).to eq(200) - # expect(json['data'].size).to eq(4) - # expect(json.dig('meta', 'total')).to eq(4) - # expect(json.dig('meta')).to eq(4) - # end - # end + expect(last_response.status).to eq(200) + # expect(json['data'].size).to eq(4) + expect(json.first.dig('count')).to eq(3) + expect(json.first.dig('temporal')).not_to be_nil + end + end describe 'POST /providers' do context 'request is valid' do From 22c6d3c1f4594f61d68c0356179cbbe9b39bf76b Mon Sep 17 00:00:00 2001 From: kjgarza Date: Wed, 22 Jan 2020 23:48:44 +0100 Subject: [PATCH 2/2] enable aggregations for prefixes, providers, repos addresses https://github.com/datacite/datacite/issues/935 --- app/models/doi.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/models/doi.rb b/app/models/doi.rb index ae50b9e66..7869d556e 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -583,6 +583,16 @@ def self.query(query, options={}) options[:page][:number] ||= 1 options[:page][:size] ||= 25 + if options[:totals_agg] == "provider" + aggregations = provider_aggregations + elsif options[:totals_agg] == "client" + aggregations = client_aggregations + elsif options[:totals_agg] == "prefix" + aggregations = prefix_aggregations + else + aggregations = get_aggregations_hash(options) + end + # Cursor nav use the search after, this should always be an array of values that match the sort. if options.dig(:page, :cursor) from = 0