diff --git a/spec/helpers/hyrax/work_utils_helper_spec.rb b/spec/helpers/hyrax/work_utils_helper_spec.rb index 8774c9c23..f847af631 100644 --- a/spec/helpers/hyrax/work_utils_helper_spec.rb +++ b/spec/helpers/hyrax/work_utils_helper_spec.rb @@ -38,23 +38,22 @@ } } - 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 @@ -62,18 +61,10 @@ 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]) @@ -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}.")