diff --git a/app/controllers/test_data_controller.rb b/app/controllers/test_data_controller.rb index 8617ff3b5..962790524 100644 --- a/app/controllers/test_data_controller.rb +++ b/app/controllers/test_data_controller.rb @@ -1,4 +1,6 @@ class TestDataController < ApplicationController + include CollectionTimeHelper + rescue_from ActiveRecord::RecordNotFound, with: :render_not_found def create_test_lettings_log @@ -20,7 +22,7 @@ class TestDataController < ApplicationController return render_not_found unless FeatureToggle.create_test_logs_enabled? file = Tempfile.new("#{year}_test_lettings_log.csv") - log = FactoryBot.create(:lettings_log, :completed, assigned_to: current_user, ppostcode_full: "SW1A 1AA", startdate: Time.zone.local(year.to_i, rand(4..12), rand(1..28))) + log = FactoryBot.create(:lettings_log, :completed, assigned_to: current_user, ppostcode_full: "SW1A 1AA", startdate: generate_different_date_within_collection_year(Time.zone.now, end_date_override: Time.zone.now + 14.days)) log_to_csv = BulkUpload::LettingsLogToCsv.new(log:, line_ending: "\n", overrides: { organisation_id: "ORG#{log.owning_organisation_id}", managing_organisation_id: "ORG#{log.owning_organisation_id}" }) file.write(log_to_csv.default_field_numbers_row) file.write(log_to_csv.to_csv_row) @@ -56,7 +58,7 @@ class TestDataController < ApplicationController return render_not_found unless FeatureToggle.create_test_logs_enabled? file = Tempfile.new("#{year}_test_sales_log.csv") - log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user, value: 180_000, deposit: 150_000, county: "Somerset", saledate: Time.zone.local(year.to_i, rand(4..12), rand(1..28))) + log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user, value: 180_000, deposit: 150_000, county: "Somerset", saledate: generate_different_date_within_collection_year(Time.zone.now, end_date_override: Time.zone.now + 14.days)) log_to_csv = BulkUpload::SalesLogToCsv.new(log:, line_ending: "\n", overrides: { organisation_id: "ORG#{log.owning_organisation_id}", managing_organisation_id: "ORG#{log.owning_organisation_id}" }) file.write(log_to_csv.default_field_numbers_row) file.write(log_to_csv.to_csv_row)