From bbfe8111f74c506d6c0c4fff2af92548ab96a505 Mon Sep 17 00:00:00 2001 From: Carolyn Date: Mon, 24 Feb 2025 16:58:18 +0000 Subject: [PATCH] add 2025 BU test file method --- app/controllers/test_data_controller.rb | 35 ++++++++++++++----------- spec/factories/sales_log.rb | 1 - 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/controllers/test_data_controller.rb b/app/controllers/test_data_controller.rb index 2b049f176..e74e6c407 100644 --- a/app/controllers/test_data_controller.rb +++ b/app/controllers/test_data_controller.rb @@ -47,22 +47,25 @@ class TestDataController < ApplicationController redirect_to sales_log_path(log) end - def create_2024_test_sales_bulk_upload - return render_not_found unless FeatureToggle.create_test_logs_enabled? - - file = Tempfile.new("test_sales_log.csv") + [2024, 2025].each do |year| + define_method("create_#{year}_test_sales_bulk_upload") do + return render_not_found unless FeatureToggle.create_test_logs_enabled? - log = FactoryBot.create(:sales_log, :completed, assigned_to: current_user, value: 180_000, deposit: 150_000) - 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) - file.rewind - send_file file.path, type: "text/csv", - filename: "test_sales_log.csv", - disposition: "attachment", - after_send: lambda { - file.close - file.unlink - } + file = Tempfile.new("#{year}_test_sales_log.csv") + # saledate { Time.zone.today } + 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_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) + file.rewind + send_file file.path, type: "text/csv", + filename: "#{year}_test_sales_log.csv", + disposition: "attachment", + after_send: lambda { + file.close + file.unlink + } + end end end + diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index caef3ea81..820c99fdc 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -118,7 +118,6 @@ FactoryBot.define do uprn_known { 0 } address_line1 { "Address line 1" } town_or_city { Faker::Address.city } - county { "Somerset" } la_known { 1 } la { "E09000003" } savingsnk { 1 }