Skip to content

Commit

Permalink
update test stubs, removing redundant test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcam-src committed Sep 24, 2024
1 parent f2a7428 commit 6642a7e
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions spec/helpers/hyrax/work_utils_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,33 @@
}
}

before do
allow(ActiveFedora::SolrService).to receive(:get).with("file_set_ids_ssim:#{fileset_ids[0]}", rows: 1).and_return('response' => { 'docs' => mock_records[0] })
allow(ActiveFedora::SolrService).to receive(:get).with("title_tesim:#{admin_set_name}", {'df'=>'title_tesim', :rows=>1}).and_return('response' => { 'docs' => mock_admin_set })
end

describe '#fetch_work_data_by_fileset_id' do
it 'fetches the work data correctly' do
allow(ActiveFedora::SolrService).to receive(:get).with("id:#{fileset_ids[0]}", rows: 1).and_return('response' => { 'docs' => mock_records[0] })
allow(ActiveFedora::SolrService).to receive(:get).with("file_set_ids_ssim:#{fileset_ids[0]}", rows: 1).and_return('response' => { 'docs' => mock_records[0] })
allow(ActiveFedora::SolrService).to receive(:get).with("title_tesim:#{admin_set_name}", {'df'=>'title_tesim', :rows=>1}).and_return('response' => { 'docs' => mock_admin_set })
result = WorkUtilsHelper.fetch_work_data_by_fileset_id(fileset_ids[0])
expect(result).to eq(expected_work_data)
end

it 'logs appropriate messages for missing values' do
# Mock the solr response to simulate a work with missing values, if it somehow makes it past the initial nil check
allow(ActiveFedora::SolrService).to receive(:get).with("id:#{fileset_ids[0]}", rows: 1).and_return('response' => { 'docs' => [] })
allow(ActiveFedora::SolrService).to receive(:get).with("file_set_ids_ssim:#{fileset_ids[0]}", rows: 1).and_return('response' => { 'docs' => [] })
allow(Rails.logger).to receive(:warn)
result = WorkUtilsHelper.fetch_work_data_by_fileset_id(fileset_ids[0])
expect(Rails.logger).to have_received(:warn).with("No work found for fileset id: #{fileset_ids[0]}")
expect(Rails.logger).to have_received(:warn).with("No fileset data found for fileset id: #{fileset_ids[0]}")
expect(Rails.logger).to have_received(:warn).with("Could not find an admin set, the work with fileset id: #{fileset_ids[0]} has no admin set name.")
expect(result[:work_id]).to be_nil
expect(result[:work_type]).to be_nil
expect(result[:title]).to be_nil
expect(result[:admin_set_id]).to be_nil
end

context 'when no work is found' do
it 'logs a warning if no work is found' do
allow(ActiveFedora::SolrService).to receive(:get).with("file_set_ids_ssim:#{fileset_ids[1]}", rows: 1).and_return('response' => { 'docs' => [] })
allow(Rails.logger).to receive(:warn)
WorkUtilsHelper.fetch_work_data_by_fileset_id(fileset_ids[1])
expect(Rails.logger).to have_received(:warn).with("No work found for fileset id: #{fileset_ids[1]}")
end
end

context 'when admin set is not found' do
it 'logs an appropriate message if the work doesnt have an admin set title' do
# Using the mock record without an admin set title
allow(ActiveFedora::SolrService).to receive(:get).with("id:#{fileset_ids[1]}", rows: 1).and_return('response' => { 'docs' => mock_records[1] })
allow(ActiveFedora::SolrService).to receive(:get).with("file_set_ids_ssim:#{fileset_ids[1]}", rows: 1).and_return('response' => { 'docs' => mock_records[1] })
allow(Rails.logger).to receive(:warn)
result = WorkUtilsHelper.fetch_work_data_by_fileset_id(fileset_ids[1])
Expand All @@ -83,8 +74,9 @@

it 'logs an appropriate message if the query for an admin set returns nothing' do
# Using the mock record with an admin set title
allow(ActiveFedora::SolrService).to receive(:get).with("id:#{fileset_ids[1]}", rows: 1).and_return('response' => { 'docs' => mock_records[0] })
allow(ActiveFedora::SolrService).to receive(:get).with("file_set_ids_ssim:#{fileset_ids[1]}", rows: 1).and_return('response' => { 'docs' => mock_records[0] })
allow(ActiveFedora::SolrService).to receive(:get).with("title_tesim:#{admin_set_name}", {'df'=>'title_tesim', :rows=>1}).and_return('response' => { 'docs' => [] })
allow(ActiveFedora::SolrService).to receive(:get).with("title_tesim:#{admin_set_name}", {'df'=>'title_tesim', :rows=>1}).and_return('response' => { 'docs' => [{}] })
allow(Rails.logger).to receive(:warn)
result = WorkUtilsHelper.fetch_work_data_by_fileset_id(fileset_ids[1])
expect(Rails.logger).to have_received(:warn).with("No admin set found with title_tesim: #{admin_set_name}.")
Expand Down

0 comments on commit 6642a7e

Please sign in to comment.