File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ class ReindexByDoiJob < ApplicationJob
4+ queue_as :lupo_background
5+
6+ def perform ( doi_id , _options = { } )
7+ doi = Doi . find_by ( doi : doi_id )
8+ return unless doi . present?
9+
10+ if doi . agency == "datacite"
11+ DataciteDoiImportInBulkJob . perform_later ( [ doi . id ] , index : DataciteDoi . active_index )
12+ else
13+ OtherDoiImportInBulkJob . perform_later ( [ doi . id ] , index : OtherDoi . active_index )
14+ end
15+ end
16+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require "rails_helper"
4+
5+ describe ReindexByDoiJob , type : :job do
6+ let ( :datacite_doi ) { create ( :doi , agency : "datacite" ) }
7+ let ( :other_doi ) { create ( :doi , agency : "crossref" ) }
8+ subject ( :job ) { ReindexByDoiJob . perform_later ( datacite_doi . doi ) }
9+
10+ it "queues the job" do
11+ expect { job } . to have_enqueued_job ( ReindexByDoiJob ) . on_queue (
12+ "test_lupo_background" ,
13+ )
14+ end
15+
16+ it "queues DataciteDoiImportInBulkJob for agency 'datacite'" do
17+ ReindexByDoiJob . perform_now ( datacite_doi . doi )
18+
19+ enqueued_job = enqueued_jobs . find { |j | j [ :job ] == DataciteDoiImportInBulkJob }
20+ expect ( enqueued_job ) . to be_present
21+ expect ( enqueued_job [ :args ] . first ) . to eq ( [ datacite_doi . id ] )
22+ end
23+
24+ it "queues OtherDoiImportInBulkJob for agency 'crossref'" do
25+ ReindexByDoiJob . perform_now ( other_doi . doi )
26+
27+ enqueued_job = enqueued_jobs . find { |j | j [ :job ] == OtherDoiImportInBulkJob }
28+ expect ( enqueued_job ) . to be_present
29+ expect ( enqueued_job [ :args ] . first ) . to eq ( [ other_doi . id ] )
30+ end
31+
32+ after do
33+ clear_enqueued_jobs
34+ clear_performed_jobs
35+ end
36+ end
You can’t perform that action at this time.
0 commit comments