From 65def73ff6b4c0fe001cc93da30a5e92529e7218 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 30 Jun 2023 15:15:52 +0100 Subject: [PATCH] feat: update tests --- app/models/form/lettings/questions/location_id.rb | 2 +- app/models/validations/shared_validations.rb | 15 +++++++-------- .../form/lettings/questions/location_id_spec.rb | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/models/form/lettings/questions/location_id.rb b/app/models/form/lettings/questions/location_id.rb index 7e022b69c..6e5ed3dc0 100644 --- a/app/models/form/lettings/questions/location_id.rb +++ b/app/models/form/lettings/questions/location_id.rb @@ -28,7 +28,7 @@ class Form::Lettings::Questions::LocationId < ::Form::Question def displayed_answer_options(lettings_log, _user = nil) return {} unless lettings_log.scheme - scheme_location_ids = lettings_log.scheme.locations.pluck(:id) + scheme_location_ids = lettings_log.scheme.locations.confirmed.pluck(:id) answer_options.select { |k, _v| scheme_location_ids.include?(k.to_i) } end diff --git a/app/models/validations/shared_validations.rb b/app/models/validations/shared_validations.rb index d048a6c70..ea2c4b4f9 100644 --- a/app/models/validations/shared_validations.rb +++ b/app/models/validations/shared_validations.rb @@ -65,25 +65,23 @@ module Validations::SharedValidations end def location_during_startdate_validation(record, field) - location_inactive_status = inactive_status(record.startdate, record.location) + location_inactive_status = inactive_status(record.startdate, record.location, field) if location_inactive_status.present? date, scope, deactivation_date = location_inactive_status.values_at(:date, :scope, :deactivation_date) - page = scheme_location_validation_page(field) - record.errors.add field, :not_active, message: I18n.t("validations.setup.startdate.location.#{scope}.#{page}", postcode: record.location.postcode, date:, deactivation_date:) + record.errors.add field, :not_active, message: I18n.t("validations.setup.startdate.location.#{scope}", postcode: record.location.postcode, date:, deactivation_date:) end end def scheme_during_startdate_validation(record, field) - scheme_inactive_status = inactive_status(record.startdate, record.scheme) + scheme_inactive_status = inactive_status(record.startdate, record.scheme, field) if scheme_inactive_status.present? date, scope, deactivation_date = scheme_inactive_status.values_at(:date, :scope, :deactivation_date) - page = scheme_location_validation_page(field) - record.errors.add field, I18n.t("validations.setup.startdate.scheme.#{scope}.#{page}", name: record.scheme.service_name, date:, deactivation_date:) + record.errors.add field, I18n.t("validations.setup.startdate.scheme.#{scope}", name: record.scheme.service_name, date:, deactivation_date:) end end - def inactive_status(date, resource) + def inactive_status(date, resource, field) return if date.blank? || resource.blank? status = resource.status_at(date) @@ -98,7 +96,8 @@ module Validations::SharedValidations when :deactivated then open_deactivation.deactivation_date end - { scope: status, date: date&.to_formatted_s(:govuk_date), deactivation_date: closest_reactivation&.deactivation_date&.to_formatted_s(:govuk_date) } + scope = date == :activating_soon ? "#{status}.#{status(scheme_location_validation_page(field))}" : status + { scope:, date: date&.to_formatted_s(:govuk_date), deactivation_date: closest_reactivation&.deactivation_date&.to_formatted_s(:govuk_date) } end def shared_validate_partner_count(record, max_people) diff --git a/spec/models/form/lettings/questions/location_id_spec.rb b/spec/models/form/lettings/questions/location_id_spec.rb index fbe580970..dae6db3f1 100644 --- a/spec/models/form/lettings/questions/location_id_spec.rb +++ b/spec/models/form/lettings/questions/location_id_spec.rb @@ -68,9 +68,9 @@ RSpec.describe Form::Lettings::Questions::LocationId, type: :model do Timecop.unfreeze end - context "and all the locations have a future startdate" do + context "and all the locations have a startdate more than 2 weeks in the future" do before do - FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 5, 13)) + FactoryBot.create(:location, scheme:, startdate: Time.utc(2022, 6, 1)) FactoryBot.create(:location, scheme:, startdate: Time.utc(2023, 1, 1)) lettings_log.update!(scheme:) end