From b16a95e98683e1b5fc559e4af45f6b31389a7c8a Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 27 Nov 2020 11:57:00 +0100 Subject: [PATCH] move dois missing report to different api. #676 --- app/controllers/exports_controller.rb | 7 +++ app/controllers/repositories_controller.rb | 7 --- config/routes.rb | 2 +- spec/requests/exports_spec.rb | 28 ++++++++++++ spec/requests/repositories_spec.rb | 52 ---------------------- 5 files changed, 36 insertions(+), 60 deletions(-) diff --git a/app/controllers/exports_controller.rb b/app/controllers/exports_controller.rb index e45838e33..223338c80 100644 --- a/app/controllers/exports_controller.rb +++ b/app/controllers/exports_controller.rb @@ -488,6 +488,13 @@ def repositories status: :bad_request end + def check_indexed_dois + csv = Client.export_doi_counts + filename = "repositories-not-fully-indexed-#{Date.today}.csv" + + send_data csv, filename: filename + end + def export_date(date) DateTime.strptime(date, "%Y-%m-%dT%H:%M:%S").strftime( "%d/%m/%YT%H:%M:%S.%3NUTC%:z", diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index aaf27d314..6f538e7a3 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -307,13 +307,6 @@ def stats render json: meta, status: :ok end - def check_links - csv = Client.export_doi_counts - filename = "repositories-not-fully-indexed-#{Date.today}.csv" - - send_data csv, filename: filename - end - protected def set_include if params[:include].present? diff --git a/config/routes.rb b/config/routes.rb index e1273b0eb..1628297b0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -169,7 +169,7 @@ get "export/repositories", to: "exports#repositories", defaults: { format: :csv } get "export/contacts", to: "exports#contacts", defaults: { format: :csv } - get "repositories/check-links", to: "repositories#check_links" + get "export/check-indexed-dois", to: "exports#check_indexed_dois" resources :heartbeat, only: %i[index] diff --git a/spec/requests/exports_spec.rb b/spec/requests/exports_spec.rb index a4471e5d8..c57633d77 100644 --- a/spec/requests/exports_spec.rb +++ b/spec/requests/exports_spec.rb @@ -229,4 +229,32 @@ ) end end + + describe "GET /export/check-indexed-dois", elasticsearch: true do + let(:client) do + create( + :client, + provider: provider, + symbol: "UVA.LIBRARY", + name: "University of Virginia Library", + ) + end + let!(:dois) { create_list(:doi, 3, client: client, aasm_state: "findable") } + + before do + DataciteDoi.import + Client.import + sleep 2 + end + + it "returns repositories with dois not indexed", vcr: false do + get "/export/check-indexed-dois", + nil, admin_headers + puts last_response.body + expect(last_response.status).to eq(200) + csv = last_response.body.lines + expect(csv.length).to eq(1) + expect(csv[0].strip).to be_blank + end + end end diff --git a/spec/requests/repositories_spec.rb b/spec/requests/repositories_spec.rb index 48f557cdf..c90d98f54 100644 --- a/spec/requests/repositories_spec.rb +++ b/spec/requests/repositories_spec.rb @@ -625,56 +625,4 @@ # expect(Doi.query(nil, client_id: target.symbol.downcase).results.total).to eq(3) end end - - describe "GET /repositories/check-links", elasticsearch: true do - let(:admin_bearer) { User.generate_token } - let(:admin_headers) do - { - "HTTP_ACCEPT" => "text/csv", - "HTTP_AUTHORIZATION" => "Bearer " + admin_bearer, - } - end - let(:consortium) do - create( - :provider, - role_name: "ROLE_CONSORTIUM", - name: "Virtual Library of Virginia", - symbol: "VIVA", - ) - end - let!(:provider) do - create( - :provider, - role_name: "ROLE_CONSORTIUM_ORGANIZATION", - name: "University of Virginia", - symbol: "UVA", - consortium: consortium, - ) - end - let(:client) do - create( - :client, - provider: provider, - symbol: "UVA.LIBRARY", - name: "University of Virginia Library", - ) - end - let!(:dois) { create_list(:doi, 3, client: client, aasm_state: "findable") } - - before do - DataciteDoi.import - Client.import - sleep 2 - end - - it "returns repositories with dois not indexed", vcr: false do - get "/repositories/check-links", - nil, admin_headers - puts last_response.body - expect(last_response.status).to eq(200) - csv = last_response.body.lines - expect(csv.length).to eq(1) - expect(csv[0].strip).to be_blank - end - end end