Browse Source

feat: update tests

pull/1739/head
natdeanlewissoftwire 3 years ago
parent
commit
65def73ff6
  1. 2
      app/models/form/lettings/questions/location_id.rb
  2. 15
      app/models/validations/shared_validations.rb
  3. 4
      spec/models/form/lettings/questions/location_id_spec.rb

2
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

15
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)

4
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

Loading…
Cancel
Save