Browse Source

Cldc 1464 completion date validations PO review (#1259)

* feat: add 22/23 year validation

* feat: wip commit

* feat: update i18n

* feat: add one year gap exchange/completion validations

* tests: add tests for new validations

* test: add setup validations tests

* test: update factory to pass saledate validation

* feat: update seeds

* feat: update tests to reflect sales logs shouldn't exist in new service before 2022

* feat: merge with main, improve date behaviour

* refactor: cleanup

* feat: update tests

* feat: enforce saledate not after 22/23 collection year end

* feat: check date is valid

* feat: add hodate/saledate hard validation to saledate as well

* feat: add HandoverDate check to saledate question

* test: update

* db: update

* test: update

* feat: wip po updates

* feat: add soft_validation to setup

* feat: fix bug by making sale date soft validation optional

* feat: add tests

* test: update

* refactor: linting
pull/1225/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
f356ef38ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      app/models/form/sales/pages/handover_date_check.rb
  2. 19
      app/models/form/sales/pages/sale_date_check.rb
  3. 8
      app/models/form/sales/questions/handover_date_check.rb
  4. 29
      app/models/form/sales/questions/sale_date_check.rb
  5. 1
      app/models/form/sales/subsections/setup.rb
  6. 2
      app/models/form/sales/subsections/shared_ownership_scheme.rb
  7. 2
      app/models/sales_log.rb
  8. 9
      app/models/validations/date_validations.rb
  9. 5
      app/models/validations/sales/sale_information_validations.rb
  10. 4
      app/models/validations/sales/setup_validations.rb
  11. 2
      app/models/validations/sales/soft_validations.rb
  12. 9
      app/models/validations/shared_validations.rb
  13. 2
      app/services/filter_service.rb
  14. 9
      config/locales/en.yml
  15. 5
      db/migrate/20230203104238_add_saledate_check_to_sales_log.rb
  16. 7
      db/schema.rb
  17. 18
      spec/models/form/sales/pages/handover_date_check_spec.rb
  18. 47
      spec/models/form/sales/pages/sale_date_check_spec.rb
  19. 4
      spec/models/form/sales/questions/handover_date_check_spec.rb
  20. 48
      spec/models/form/sales/questions/sale_date_check_spec.rb
  21. 1
      spec/models/form/sales/subsections/setup_spec.rb
  22. 16
      spec/models/form_handler_spec.rb
  23. 4
      spec/models/form_spec.rb
  24. 2
      spec/models/sales_log_spec.rb
  25. 6
      spec/models/validations/sales/sale_information_validations_spec.rb

8
app/models/form/sales/pages/handover_date_check.rb

@ -1,8 +1,14 @@
class Form::Sales::Pages::HandoverDateCheck < ::Form::Page class Form::Sales::Pages::HandoverDateCheck < ::Form::Page
def initialize(id, hsh, subsection) def initialize(id, hsh, subsection)
super super
@depends_on = [{ "hodate_3_years_or_more_saledate?" => true }] @id = "handover_date_check"
@depends_on = [{ "saledate_check" => nil, "hodate_3_years_or_more_saledate?" => true },
{ "saledate_check" => 1, "hodate_3_years_or_more_saledate?" => true }]
@informative_text = {} @informative_text = {}
@title_text = {
"translation" => "validations.sale_information.hodate.must_be_less_than_3_years_from_saledate",
"arguments" => [],
}
end end
def questions def questions

19
app/models/form/sales/pages/sale_date_check.rb

@ -0,0 +1,19 @@
class Form::Sales::Pages::SaleDateCheck < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "completion_date_check"
@depends_on = [{ "hodate_check" => nil, "hodate_3_years_or_more_saledate?" => true },
{ "hodate_check" => 1, "hodate_3_years_or_more_saledate?" => true }]
@informative_text = {}
@title_text = {
"translation" => "validations.sale_information.saledate.must_be_less_than_3_years_from_hodate",
"arguments" => [],
}
end
def questions
@questions ||= [
Form::Sales::Questions::SaleDateCheck.new(nil, nil, self),
]
end
end

8
app/models/form/sales/questions/handover_date_check.rb

@ -3,7 +3,7 @@ class Form::Sales::Questions::HandoverDateCheck < ::Form::Question
super super
@id = "hodate_check" @id = "hodate_check"
@check_answer_label = "Practical completion or handover date check" @check_answer_label = "Practical completion or handover date check"
@header = "Are you sure practical completion or handover date is more than 3 years before exchange date?" @header = "Are you sure?"
@type = "interruption_screen" @type = "interruption_screen"
@answer_options = { @answer_options = {
"0" => { "value" => "Yes" }, "0" => { "value" => "Yes" },
@ -17,6 +17,12 @@ class Form::Sales::Questions::HandoverDateCheck < ::Form::Question
{ {
"hodate_check" => 1, "hodate_check" => 1,
}, },
{
"saledate_check" => 0,
},
{
"saledate_check" => 1,
},
], ],
} }
end end

29
app/models/form/sales/questions/sale_date_check.rb

@ -0,0 +1,29 @@
class Form::Sales::Questions::SaleDateCheck < ::Form::Question
def initialize(id, hsh, page)
super
@id = "saledate_check"
@check_answer_label = "Sale completion date check"
@header = "Are you sure?"
@type = "interruption_screen"
@answer_options = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}
@hidden_in_check_answers = {
"depends_on" => [
{
"hodate_check" => 0,
},
{
"hodate_check" => 1,
},
{
"saledate_check" => 0,
},
{
"saledate_check" => 1,
},
],
}
end
end

1
app/models/form/sales/subsections/setup.rb

@ -10,6 +10,7 @@ class Form::Sales::Subsections::Setup < ::Form::Subsection
Form::Common::Pages::Organisation.new(nil, nil, self), Form::Common::Pages::Organisation.new(nil, nil, self),
Form::Common::Pages::CreatedBy.new(nil, nil, self), Form::Common::Pages::CreatedBy.new(nil, nil, self),
Form::Sales::Pages::SaleDate.new(nil, nil, self), Form::Sales::Pages::SaleDate.new(nil, nil, self),
Form::Sales::Pages::SaleDateCheck.new(nil, nil, self),
Form::Sales::Pages::PurchaserCode.new(nil, nil, self), Form::Sales::Pages::PurchaserCode.new(nil, nil, self),
Form::Sales::Pages::OwnershipScheme.new(nil, nil, self), Form::Sales::Pages::OwnershipScheme.new(nil, nil, self),
Form::Sales::Pages::SharedOwnershipType.new(nil, nil, self), Form::Sales::Pages::SharedOwnershipType.new(nil, nil, self),

2
app/models/form/sales/subsections/shared_ownership_scheme.rb

@ -15,7 +15,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection
Form::Sales::Pages::Resale.new(nil, nil, self), Form::Sales::Pages::Resale.new(nil, nil, self),
Form::Sales::Pages::ExchangeDate.new(nil, nil, self), Form::Sales::Pages::ExchangeDate.new(nil, nil, self),
Form::Sales::Pages::HandoverDate.new(nil, nil, self), Form::Sales::Pages::HandoverDate.new(nil, nil, self),
Form::Sales::Pages::HandoverDateCheck.new("handover_date_check", nil, self), Form::Sales::Pages::HandoverDateCheck.new(nil, nil, self),
Form::Sales::Pages::LaNominations.new(nil, nil, self), Form::Sales::Pages::LaNominations.new(nil, nil, self),
Form::Sales::Pages::BuyerPrevious.new(nil, nil, self), Form::Sales::Pages::BuyerPrevious.new(nil, nil, self),
Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self), Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self),

2
app/models/sales_log.rb

@ -35,7 +35,7 @@ class SalesLog < Log
scope :search_by, ->(param) { filter_by_id(param) } scope :search_by, ->(param) { filter_by_id(param) }
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org) } scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org) }
OPTIONAL_FIELDS = %w[purchid monthly_charges_value_check old_persons_shared_ownership_value_check].freeze OPTIONAL_FIELDS = %w[saledate_check purchid monthly_charges_value_check old_persons_shared_ownership_value_check].freeze
RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze RETIREMENT_AGES = { "M" => 65, "F" => 60, "X" => 65 }.freeze
def startdate def startdate

9
app/models/validations/date_validations.rb

@ -84,15 +84,6 @@ private
@second_collection_end_date ||= FormHandler.instance.forms.map { |_name, form| form.end_date }.compact.max @second_collection_end_date ||= FormHandler.instance.forms.map { |_name, form| form.end_date }.compact.max
end end
def date_valid?(question, record)
if record[question].is_a?(ActiveSupport::TimeWithZone) && record[question].year.zero?
record.errors.add question, I18n.t("validations.date.invalid_date")
false
else
true
end
end
def is_rsnvac_first_let?(record) def is_rsnvac_first_let?(record)
[15, 16, 17].include?(record["rsnvac"]) [15, 16, 17].include?(record["rsnvac"])
end end

5
app/models/validations/sales/sale_information_validations.rb

@ -2,8 +2,9 @@ module Validations::Sales::SaleInformationValidations
def validate_practical_completion_date_before_saledate(record) def validate_practical_completion_date_before_saledate(record)
return if record.saledate.blank? || record.hodate.blank? return if record.saledate.blank? || record.hodate.blank?
unless record.saledate > record.hodate if record.hodate > record.saledate
record.errors.add :hodate, I18n.t("validations.sale_information.hodate.must_be_before_exdate") record.errors.add :hodate, I18n.t("validations.sale_information.hodate.must_be_before_saledate")
record.errors.add :saledate, I18n.t("validations.sale_information.saledate.must_be_after_hodate")
end end
end end

4
app/models/validations/sales/setup_validations.rb

@ -1,6 +1,8 @@
module Validations::Sales::SetupValidations module Validations::Sales::SetupValidations
include Validations::SharedValidations
def validate_saledate(record) def validate_saledate(record)
return unless record.saledate return unless record.saledate && date_valid?("saledate", record)
unless Time.zone.local(2022, 4, 1) <= record.saledate && record.saledate < Time.zone.local(2023, 4, 1) unless Time.zone.local(2022, 4, 1) <= record.saledate && record.saledate < Time.zone.local(2023, 4, 1)
record.errors.add :saledate, I18n.t("validations.setup.saledate.financial_year") record.errors.add :saledate, I18n.t("validations.setup.saledate.financial_year")

2
app/models/validations/sales/soft_validations.rb

@ -67,7 +67,7 @@ module Validations::Sales::SoftValidations
def hodate_3_years_or_more_saledate? def hodate_3_years_or_more_saledate?
return unless hodate && saledate return unless hodate && saledate
((saledate.to_date - hodate.to_date).to_i / 365) >= 3 saledate - hodate >= 3.years
end end
def grant_outside_common_range? def grant_outside_common_range?

9
app/models/validations/shared_validations.rb

@ -99,6 +99,15 @@ module Validations::SharedValidations
end end
end end
def date_valid?(question, record)
if record[question].is_a?(ActiveSupport::TimeWithZone) && record[question].year.zero?
record.errors.add question, I18n.t("validations.date.invalid_date")
false
else
true
end
end
private private
def person_is_partner?(relationship) def person_is_partner?(relationship)

2
app/services/filter_service.rb

@ -36,7 +36,7 @@ class FilterService
end end
def bulk_upload def bulk_upload
id = ((logs_filters["bulk_upload_id"] || []).reject(&:blank?))[0] id = (logs_filters["bulk_upload_id"] || []).reject(&:blank?)[0]
@bulk_upload ||= current_user.bulk_uploads.find_by(id:) @bulk_upload ||= current_user.bulk_uploads.find_by(id:)
end end

9
config/locales/en.yml

@ -427,13 +427,16 @@ en:
social_homebuy: "Social HomeBuy buyers should not have lived here before" social_homebuy: "Social HomeBuy buyers should not have lived here before"
rent_to_buy: "Rent to Buy buyers should not have lived here before" rent_to_buy: "Rent to Buy buyers should not have lived here before"
hodate: hodate:
must_be_before_exdate: "Practical completion or handover date must be before exchange date" must_be_before_saledate: "Practical completion or handover date must be before exchange date"
must_be_less_than_3_years_from_saledate: "You told us practical completion or handover date is more than 3 years before completion date"
exdate: exdate:
must_be_before_saledate: "Contract exchange date must be less than 1 year before completion date" must_be_before_saledate: "Contract exchange date must be before completion date"
must_be_less_than_1_year_from_saledate: "Contract exchange date must be less than 1 year before completion date" must_be_less_than_1_year_from_saledate: "Contract exchange date must be less than 1 year before completion date"
saledate: saledate:
must_be_after_exdate: "Completion date must be less than 1 year after contract exchange date" must_be_after_exdate: "Completion date must be after contract exchange date"
must_be_less_than_1_year_from_exdate: "Completion date must be less than 1 year after contract exchange date" must_be_less_than_1_year_from_exdate: "Completion date must be less than 1 year after contract exchange date"
must_be_less_than_3_years_from_hodate: "You told us completion date is more than 3 years after practical completion or handover date"
must_be_after_hodate: "Completion date must be after practical completion or handover date"
previous_property_beds: previous_property_beds:
property_type_bedsit: "Bedsit bedroom maximum 1" property_type_bedsit: "Bedsit bedroom maximum 1"
discounted_ownership_value: "Mortgage, deposit, and grant total must equal £%{value_with_discount}" discounted_ownership_value: "Mortgage, deposit, and grant total must equal £%{value_with_discount}"

5
db/migrate/20230203104238_add_saledate_check_to_sales_log.rb

@ -0,0 +1,5 @@
class AddSaledateCheckToSalesLog < ActiveRecord::Migration[7.0]
def change
add_column :sales_logs, :saledate_check, :integer
end
end

7
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_01_27_102334) do ActiveRecord::Schema[7.0].define(version: 2023_02_03_104238) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -504,12 +504,13 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_27_102334) do
t.integer "retirement_value_check" t.integer "retirement_value_check"
t.integer "hodate_check" t.integer "hodate_check"
t.integer "extrabor_value_check" t.integer "extrabor_value_check"
t.integer "grant_value_check"
t.integer "staircase_bought_value_check"
t.integer "deposit_and_mortgage_value_check" t.integer "deposit_and_mortgage_value_check"
t.integer "shared_ownership_deposit_value_check" t.integer "shared_ownership_deposit_value_check"
t.integer "grant_value_check"
t.integer "old_persons_shared_ownership_value_check" t.integer "old_persons_shared_ownership_value_check"
t.integer "staircase_bought_value_check"
t.integer "monthly_charges_value_check" t.integer "monthly_charges_value_check"
t.integer "saledate_check"
t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id" t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

18
spec/models/form/sales/pages/handover_date_check_spec.rb

@ -16,18 +16,28 @@ RSpec.describe Form::Sales::Pages::HandoverDateCheck, type: :model do
end end
it "has the correct id" do it "has the correct id" do
expect(page.id).to eq("") expect(page.id).to eq("handover_date_check")
end end
it "has the correct header" do it "has the correct header" do
expect(page.header).to be_nil expect(page.header).to be_nil
end end
it "has the correct title_text" do
expect(page.title_text).to eq({
"translation" => "validations.sale_information.hodate.must_be_less_than_3_years_from_saledate",
"arguments" => [],
})
end
it "has the correct informative_text" do
expect(page.informative_text).to eq({})
end
it "has correct depends_on" do it "has correct depends_on" do
expect(page.depends_on).to eq([ expect(page.depends_on).to eq([
{ { "hodate_3_years_or_more_saledate?" => true, "saledate_check" => nil },
"hodate_3_years_or_more_saledate?" => true, { "hodate_3_years_or_more_saledate?" => true, "saledate_check" => 1 },
},
]) ])
end end

47
spec/models/form/sales/pages/sale_date_check_spec.rb

@ -0,0 +1,47 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::SaleDateCheck, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { "" }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[saledate_check])
end
it "has the correct id" do
expect(page.id).to eq("completion_date_check")
end
it "has the correct header" do
expect(page.header).to be_nil
end
it "has the correct title_text" do
expect(page.title_text).to eq({
"translation" => "validations.sale_information.saledate.must_be_less_than_3_years_from_hodate",
"arguments" => [],
})
end
it "has the correct informative_text" do
expect(page.informative_text).to eq({})
end
it "has correct depends_on" do
expect(page.depends_on).to eq([
{ "hodate_3_years_or_more_saledate?" => true, "hodate_check" => nil },
{ "hodate_3_years_or_more_saledate?" => true, "hodate_check" => 1 },
])
end
it "is interruption screen page" do
expect(page.interruption_screen?).to eq(true)
end
end

4
spec/models/form/sales/questions/handover_date_check_spec.rb

@ -16,7 +16,7 @@ RSpec.describe Form::Sales::Questions::HandoverDateCheck, type: :model do
end end
it "has the correct header" do it "has the correct header" do
expect(question.header).to eq("Are you sure practical completion or handover date is more than 3 years before exchange date?") expect(question.header).to eq("Are you sure?")
end end
it "has the correct check_answer_label" do it "has the correct check_answer_label" do
@ -43,6 +43,6 @@ RSpec.describe Form::Sales::Questions::HandoverDateCheck, type: :model do
end end
it "has the correct hidden_in_check_answers" do it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq({ "depends_on" => [{ "hodate_check" => 0 }, { "hodate_check" => 1 }] }) expect(question.hidden_in_check_answers).to eq({ "depends_on" => [{ "hodate_check" => 0 }, { "hodate_check" => 1 }, { "saledate_check" => 0 }, { "saledate_check" => 1 }] })
end end
end end

48
spec/models/form/sales/questions/sale_date_check_spec.rb

@ -0,0 +1,48 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::SaleDateCheck, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("saledate_check")
end
it "has the correct header" do
expect(question.header).to eq("Are you sure?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Sale completion date check")
end
it "has the correct type" do
expect(question.type).to eq("interruption_screen")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
})
end
it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq({ "depends_on" => [{ "hodate_check" => 0 }, { "hodate_check" => 1 }, { "saledate_check" => 0 }, { "saledate_check" => 1 }] })
end
end

1
spec/models/form/sales/subsections/setup_spec.rb

@ -17,6 +17,7 @@ RSpec.describe Form::Sales::Subsections::Setup, type: :model do
organisation organisation
created_by created_by
completion_date completion_date
completion_date_check
purchaser_code purchaser_code
ownership_scheme ownership_scheme
shared_ownership_type shared_ownership_type

16
spec/models/form_handler_spec.rb

@ -52,14 +52,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do it "is able to load a current sales form" do
form = form_handler.get_form("current_sales") form = form_handler.get_form("current_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(210) expect(form.pages.count).to eq(211)
expect(form.name).to eq("2022_2023_sales") expect(form.name).to eq("2022_2023_sales")
end end
it "is able to load a previous sales form" do it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales") form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(210) expect(form.pages.count).to eq(211)
expect(form.name).to eq("2021_2022_sales") expect(form.name).to eq("2021_2022_sales")
end end
end end
@ -76,6 +76,10 @@ RSpec.describe FormHandler do
context "when the date is after 1st of April" do context "when the date is after 1st of April" do
let(:now) { Time.utc(2022, 8, 3) } let(:now) { Time.utc(2022, 8, 3) }
it "returns the same year as the current start year" do
expect(form_handler.current_collection_start_year).to eq(2022)
end
it "returns the correct current lettings form name" do it "returns the correct current lettings form name" do
expect(form_handler.form_name_from_start_year(2022, "lettings")).to eq("current_lettings") expect(form_handler.form_name_from_start_year(2022, "lettings")).to eq("current_lettings")
end end
@ -99,11 +103,19 @@ RSpec.describe FormHandler do
it "returns the correct next sales form name" do it "returns the correct next sales form name" do
expect(form_handler.form_name_from_start_year(2023, "sales")).to eq("next_sales") expect(form_handler.form_name_from_start_year(2023, "sales")).to eq("next_sales")
end end
it "returns the correct current start date" do
expect(form_handler.current_collection_start_date).to eq(Time.zone.local(2022, 4, 1))
end
end end
context "with the date before 1st of April" do context "with the date before 1st of April" do
let(:now) { Time.utc(2022, 2, 3) } let(:now) { Time.utc(2022, 2, 3) }
it "returns the previous year as the current start year" do
expect(form_handler.current_collection_start_year).to eq(2021)
end
it "returns the correct current lettings form name" do it "returns the correct current lettings form name" do
expect(form_handler.form_name_from_start_year(2021, "lettings")).to eq("current_lettings") expect(form_handler.form_name_from_start_year(2021, "lettings")).to eq("current_lettings")
end end

4
spec/models/form_spec.rb

@ -218,9 +218,9 @@ RSpec.describe Form, type: :model do
expect(form.sections[0].class).to eq(Form::Sales::Sections::Setup) expect(form.sections[0].class).to eq(Form::Sales::Sections::Setup)
expect(form.subsections.count).to eq(1) expect(form.subsections.count).to eq(1)
expect(form.subsections.first.id).to eq("setup") expect(form.subsections.first.id).to eq("setup")
expect(form.pages.count).to eq(14) expect(form.pages.count).to eq(15)
expect(form.pages.first.id).to eq("organisation") expect(form.pages.first.id).to eq("organisation")
expect(form.questions.count).to eq(15) expect(form.questions.count).to eq(16)
expect(form.questions.first.id).to eq("owning_organisation_id") expect(form.questions.first.id).to eq("owning_organisation_id")
expect(form.start_date).to eq(Time.zone.parse("2022-04-01")) expect(form.start_date).to eq(Time.zone.parse("2022-04-01"))
expect(form.end_date).to eq(Time.zone.parse("2023-07-01")) expect(form.end_date).to eq(Time.zone.parse("2023-07-01"))

2
spec/models/sales_log_spec.rb

@ -47,7 +47,7 @@ RSpec.describe SalesLog, type: :model do
let(:sales_log) { build(:sales_log) } let(:sales_log) { build(:sales_log) }
it "returns optional fields" do it "returns optional fields" do
expect(sales_log.optional_fields).to eq(%w[purchid monthly_charges_value_check old_persons_shared_ownership_value_check]) expect(sales_log.optional_fields).to eq(%w[saledate_check purchid monthly_charges_value_check old_persons_shared_ownership_value_check])
end end
end end

6
spec/models/validations/sales/sale_information_validations_spec.rb

@ -62,7 +62,7 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
it "does not add an error" do it "does not add an error" do
sale_information_validator.validate_practical_completion_date_before_saledate(record) sale_information_validator.validate_practical_completion_date_before_saledate(record)
expect(record.errors[:hodate]).to be_present expect(record.errors[:hodate]).not_to be_present
end end
end end
end end
@ -130,10 +130,10 @@ RSpec.describe Validations::Sales::SaleInformationValidations do
sale_information_validator.validate_exchange_date(record) sale_information_validator.validate_exchange_date(record)
expect(record.errors[:exdate]).to eq( expect(record.errors[:exdate]).to eq(
["Contract exchange date must be less than 1 year before completion date"], ["Contract exchange date must be before completion date"],
) )
expect(record.errors[:saledate]).to eq( expect(record.errors[:saledate]).to eq(
["Completion date must be less than 1 year after contract exchange date"], ["Completion date must be after contract exchange date"],
) )
end end
end end

Loading…
Cancel
Save