Skip to content

Commit

Permalink
unit test and updating path for last run path
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcam-src committed Sep 3, 2024
1 parent 9fdac48 commit 4d8069a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/tasks/dimensions_ingest.rake
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace :dimensions do

# Helper method to compute the last run file path
def self.dimensions_last_run_path
File.join(ENV['DATA_STORAGE'], 'last_dimensions_ingest_run.txt')
File.join(ENV['DATA_STORAGE'], 'hyrax', 'last_dimensions_ingest_run.txt')
end

def self.get_date_range(args)
Expand Down
29 changes: 27 additions & 2 deletions spec/services/tasks/download_stats_migration_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@
file_download_stats.flatten.each_with_index do |stat, index|
allow(ActiveFedora::SolrService).to receive(:get).with("file_set_ids_ssim:#{stat.file_id}", rows: 1).and_return('response' => { 'docs' => [mock_works[index]] })
end
service.list_work_stat_info(output_path, nil)
service.migrate_to_new_table(output_path)
end

after { HycDownloadStat.delete_all }

it 'creates new HycDownloadStat works from the CSV file' do
service.list_work_stat_info(output_path, nil)
service.migrate_to_new_table(output_path)
csv_to_hash_array(output_path).each_with_index do |csv_row, index|
work_data = WorkUtilsHelper.fetch_work_data_by_fileset_id(csv_row[:file_id])
csv_row_date = Date.parse(csv_row[:date]).beginning_of_month
Expand All @@ -130,6 +130,27 @@
end
end

it 'retains historic stats for a work even if the work cannot be found in solr' do
file_download_stats.flatten.each_with_index do |stat, index|
allow(ActiveFedora::SolrService).to receive(:get).with("file_set_ids_ssim:#{stat.file_id}", rows: 1).and_return('response' => { 'docs' => [] })
end
service.list_work_stat_info(output_path, nil)
service.migrate_to_new_table(output_path)
csv_to_hash_array(output_path).each_with_index do |csv_row, index|
work_data = WorkUtilsHelper.fetch_work_data_by_fileset_id(csv_row[:file_id])
csv_row_date = Date.parse(csv_row[:date]).beginning_of_month
hyc_download_stat = HycDownloadStat.find_by(fileset_id: csv_row[:file_id], date: csv_row_date)

expect(hyc_download_stat).to be_present
expect(hyc_download_stat.fileset_id).to eq(csv_row[:file_id])
expect(hyc_download_stat.work_id).to eq('Unknown')
expect(hyc_download_stat.admin_set_id).to eq('Unknown')
expect(hyc_download_stat.work_type).to eq('Unknown')
expect(hyc_download_stat.date).to eq(csv_row[:date].to_date)
expect(hyc_download_stat.download_count).to eq(expected_aggregated_download_count[[csv_row[:file_id], csv_row_date]])
end
end

it 'handles and logs errors' do
allow(CSV).to receive(:read).and_raise(StandardError, 'Simulated CSV read failure')
allow(Rails.logger).to receive(:error)
Expand All @@ -138,6 +159,10 @@
end

context 'if a failure occurs during a private function' do
before do
service.list_work_stat_info(output_path, nil)
end

it 'handles and logs errors from create_hyc_download_stat' do
allow(Rails.logger).to receive(:error)
# Simulate a failure during the creation of a HycDownloadStat object for a specific file_id
Expand Down

0 comments on commit 4d8069a

Please sign in to comment.