diff --git a/app/services/csv/scheme_csv_service.rb b/app/services/csv/scheme_csv_service.rb index 22ead264b..fbb6947f8 100644 --- a/app/services/csv/scheme_csv_service.rb +++ b/app/services/csv/scheme_csv_service.rb @@ -66,7 +66,7 @@ module Csv def scheme_value(attribute, scheme) attribute = SCHEME_FIELD_FROM_ATTRIBUTE.fetch(attribute, attribute) if attribute == "scheme_active_dates" - scheme_availability(scheme).gsub("\n", ", ") + "#{scheme_availability(scheme).gsub("\n", ", ")}" elsif CUSTOM_CALL_CHAINS.key? attribute.to_sym call_chain = CUSTOM_CALL_CHAINS[attribute.to_sym] call_chain.reduce(scheme) { |object, next_call| object&.public_send(next_call) } @@ -80,7 +80,7 @@ module Csv def location_value(attribute, location) attribute = LOCATION_FIELD_FROM_ATTRIBUTE.fetch(attribute, attribute) if attribute == "location_active_dates" - location_availability(location).gsub("\n", ", ") + "#{location_availability(location).gsub("\n", ", ")}" else location.public_send(attribute) end diff --git a/spec/fixtures/files/locations_csv_export.csv b/spec/fixtures/files/locations_csv_export.csv index 3322e165d..51844b6c5 100644 --- a/spec/fixtures/files/locations_csv_export.csv +++ b/spec/fixtures/files/locations_csv_export.csv @@ -1,2 +1,2 @@ scheme_code,location_code,location_postcode,location_name,location_status,location_local_authority,location_units,location_type_of_unit,location_mobility_type,location_active_dates -,,SW1A 2AA,Downing Street,active,Westminster,20,Self-contained house,Fitted with equipment and adaptations,Active from 1 April 2022 +,,SW1A 2AA,Downing Street,deactivating_soon,Westminster,20,Self-contained house,Fitted with equipment and adaptations,"Active from 1 April 2022 to 25 December 2023, Deactivated on 26 December 2023" diff --git a/spec/fixtures/files/schemes_and_locations_csv_export.csv b/spec/fixtures/files/schemes_and_locations_csv_export.csv index 180cc35a9..9db484412 100644 --- a/spec/fixtures/files/schemes_and_locations_csv_export.csv +++ b/spec/fixtures/files/schemes_and_locations_csv_export.csv @@ -1,2 +1,2 @@ scheme_code,scheme_service_name,scheme_status,scheme_sensitive,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_support_services_provided_by,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,scheme_active_dates,location_code,location_postcode,location_name,location_status,location_local_authority,location_units,location_type_of_unit,location_mobility_type,location_active_dates -,Test name,active,Yes,Housing for older people,No,DLUHC,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,Active from 1 April 2020,,SW1A 2AA,Downing Street,active,Westminster,20,Self-contained house,Fitted with equipment and adaptations,Active from 1 April 2022 +,Test name,active,Yes,Housing for older people,No,DLUHC,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020 to 31 March 2022, Deactivated on 1 April 2022, Active from 1 April 2023",,SW1A 2AA,Downing Street,deactivating_soon,Westminster,20,Self-contained house,Fitted with equipment and adaptations,"Active from 1 April 2022 to 25 December 2023, Deactivated on 26 December 2023" diff --git a/spec/fixtures/files/schemes_csv_export.csv b/spec/fixtures/files/schemes_csv_export.csv index 4bdca4e3d..9fd9928c9 100644 --- a/spec/fixtures/files/schemes_csv_export.csv +++ b/spec/fixtures/files/schemes_csv_export.csv @@ -1,2 +1,2 @@ scheme_code,scheme_service_name,scheme_status,scheme_sensitive,scheme_type,scheme_registered_under_care_act,scheme_owning_organisation_name,scheme_support_services_provided_by,scheme_primary_client_group,scheme_has_other_client_group,scheme_secondary_client_group,scheme_support_type,scheme_intended_stay,scheme_created_at,scheme_active_dates -,Test name,active,Yes,Housing for older people,No,DLUHC,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,Active from 1 April 2020 +,Test name,active,Yes,Housing for older people,No,DLUHC,The same organisation that owns the housing stock,People with alcohol problems,Yes,Older people with support needs,High level,Medium stay,2021-04-01T00:00:00+01:00,"Active from 1 April 2020 to 31 March 2022, Deactivated on 1 April 2022, Active from 1 April 2023" diff --git a/spec/services/csv/scheme_csv_service_spec.rb b/spec/services/csv/scheme_csv_service_spec.rb index 7a8ef3e63..7551a2a4c 100644 --- a/spec/services/csv/scheme_csv_service_spec.rb +++ b/spec/services/csv/scheme_csv_service_spec.rb @@ -4,6 +4,7 @@ RSpec.describe Csv::SchemeCsvService do let(:organisation) { create(:organisation) } let(:fixed_time) { Time.zone.local(2023, 6, 26) } let(:scheme) { create(:scheme, :export, owning_organisation: organisation, service_name: "Test name") } + let(:location) { create(:location, :export, scheme:) } let(:service) { described_class.new(download_type:) } let(:download_type) { "combined" } let(:csv) { CSV.parse(service.prepare_csv(Scheme.where(id: schemes.map(&:id)))) } @@ -12,7 +13,8 @@ RSpec.describe Csv::SchemeCsvService do before do Timecop.freeze(fixed_time) - create(:location, :export, scheme:) + create(:scheme_deactivation_period, scheme:, deactivation_date: scheme.created_at + 1.year, reactivation_date: scheme.created_at + 2.years) + create(:location_deactivation_period, location:, deactivation_date: location.created_at + 6.months) end after do @@ -106,6 +108,9 @@ RSpec.describe Csv::SchemeCsvService do context "when download type is combined" do let(:combined_attributes) { %w[scheme_code scheme_service_name scheme_status scheme_sensitive scheme_type scheme_registered_under_care_act scheme_owning_organisation_name scheme_support_services_provided_by scheme_primary_client_group scheme_has_other_client_group scheme_secondary_client_group scheme_support_type scheme_intended_stay scheme_created_at scheme_active_dates location_code location_postcode location_name location_status location_local_authority location_units location_type_of_unit location_mobility_type location_active_dates] } + before do + scheme + end it "has the correct headers" do expect(headers).to eq(combined_attributes)