From 8607f9f3f9c56eed3589ff8365149404556a5ec5 Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 20 Mar 2024 11:28:08 +0000 Subject: [PATCH] Update nationality all csv labels --- .../form/lettings/questions/nationality_all.rb | 6 ++++++ app/models/form/sales/questions/nationality_all.rb | 6 ++++++ spec/services/csv/lettings_log_csv_service_spec.rb | 14 ++++++++++++++ spec/services/csv/sales_log_csv_service_spec.rb | 14 ++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/app/models/form/lettings/questions/nationality_all.rb b/app/models/form/lettings/questions/nationality_all.rb index 8d59a37fb..bf18e1c14 100644 --- a/app/models/form/lettings/questions/nationality_all.rb +++ b/app/models/form/lettings/questions/nationality_all.rb @@ -15,4 +15,10 @@ class Form::Lettings::Questions::NationalityAll < ::Form::Question end QUESTION_NUMBER_FROM_YEAR = { 2023 => 36, 2024 => 35 }.freeze + + def label_from_value(value) + return unless value + + answer_options[value.to_s]["name"] + end end diff --git a/app/models/form/sales/questions/nationality_all.rb b/app/models/form/sales/questions/nationality_all.rb index dd8377830..1cb5c74bd 100644 --- a/app/models/form/sales/questions/nationality_all.rb +++ b/app/models/form/sales/questions/nationality_all.rb @@ -21,4 +21,10 @@ class Form::Sales::Questions::NationalityAll < ::Form::Question @buyer_index == 1 ? 26 : 34 end end + + def label_from_value(value) + return unless value + + answer_options[value.to_s]["name"] + end end diff --git a/spec/services/csv/lettings_log_csv_service_spec.rb b/spec/services/csv/lettings_log_csv_service_spec.rb index c0232ef5d..0b091348d 100644 --- a/spec/services/csv/lettings_log_csv_service_spec.rb +++ b/spec/services/csv/lettings_log_csv_service_spec.rb @@ -171,6 +171,7 @@ RSpec.describe Csv::LettingsLogCsvService do context "when the current form is 2024" do let(:now) { Time.zone.local(2024, 4, 1) } + let(:fixed_time) { Time.zone.local(2024, 4, 1) } it "exports the CSV with 2024 ordering and all values correct" do expected_content = CSV.read("spec/fixtures/files/lettings_log_csv_export_labels_24.csv") @@ -181,6 +182,19 @@ RSpec.describe Csv::LettingsLogCsvService do end expect(csv).to eq expected_content end + + context "when the log has nationality_all" do + before do + log.update!(nationality_all: 36) + end + + it "exports the id for under the heading 'nationality_all'" do + expect(log.nationality_all).to eq 36 + nationality_all_column_index = csv.first.index("nationality_all") + nationality_all_value = csv.second[nationality_all_column_index] + expect(nationality_all_value).to eq "Australia" + end + end end context "when the current form is 2023" do diff --git a/spec/services/csv/sales_log_csv_service_spec.rb b/spec/services/csv/sales_log_csv_service_spec.rb index e34595942..f6bdd7bfd 100644 --- a/spec/services/csv/sales_log_csv_service_spec.rb +++ b/spec/services/csv/sales_log_csv_service_spec.rb @@ -166,6 +166,7 @@ RSpec.describe Csv::SalesLogCsvService do end context "when the current form is 2024" do + let(:fixed_time) { Time.zone.local(2024, 5, 1) } let(:now) { Time.zone.local(2024, 5, 1) } it "exports the CSV with the 2024 ordering and all values correct" do @@ -177,6 +178,19 @@ RSpec.describe Csv::SalesLogCsvService do end expect(csv).to eq expected_content end + + context "when the log has nationality_all" do + before do + log.update!(nationality_all: 36) + end + + it "exports the id for under the heading 'nationality_all'" do + expect(log.nationality_all).to eq 36 + nationality_all_column_index = csv.first.index("nationality_all") + nationality_all_value = csv.second[nationality_all_column_index] + expect(nationality_all_value).to eq "Australia" + end + end end context "when the current form is 2023" do